Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ruby_ptv

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ruby_ptv

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RubyPtv

A ruby wrapper for the Public Transport Victoria API V3.

Installation

Add this line to your application's Gemfile:

gem 'ruby_ptv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby_ptv

Getting started

You must have a valid PTV developer API key. If you don't have one, you can find out how to register for one here.

Usage

Setup:

client = RubyPtv::Client.new(dev_id: "ID", secret_key: "SECRET")

Optional global configuration:

client = RubyPtv.configure(
  dev_id: "ID",
  secret_key: "SECRET"
)

You can get the global configuration with:

RubyPtv.configuration # => { dev_id: "YOUR_ID", secret_key "YOUR_SECRET }

In case you need to reset the configuration:

RubyPtv.reset_configuration

Examples

Departures

You can search departures for all routes or for a single route. You can add any optional paramaters, as a hash, that are specified in the PTV api documentation (NOTE: the parameter keys MUST match the exact names specified by PTV).

client.departures(0, 1023, direction_id: 1)
client.departures_for_route(0, 1127, 14)

Searching departures will return a number of nested hashes due to the number of optional params available. You can loop through the results easily:

response = client.departures(0, 1023)

response["departures"].each do |departure|
  departure["stop_id"]          # => stop id
  departure["platform_number"]  # => platform number
end

Routes

You can search all routes or search for a route with a specified route id. There are no optional paramters available for the routes methods.

client.routes
client.route(2)

Searching routes will return a single array of hashes:

response = client.routes

routes.each do |route|
  route["route_type"]   # => route type
  route["route_name"]   # => route name
end

The search method allows you to query any stops, routes and myki ticket outlets with a specified search term. Just like departures, you can add any optional paramters that are specified by the PTV documentation.

client.search("Glen Waverley", route_types: 0)

Further information

The source code is fully commented with any required parameters and basic information you may need to use this wrapper. If you are unsure of any specifics of the API, such as any optional parameters available, check the official PTV documentation.

Testing

To run the test suite:

bundle exec rake test

Contributing

Bug reports and pull requests are welcome. Just create a new branch for your feature, add the appropriate tests and open a pull request.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 13 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc