citibikenyc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +30 -0
- data/citibikenyc.gemspec +26 -0
- data/lib/citibikenyc.rb +26 -0
- data/lib/citibikenyc/api.rb +21 -0
- data/lib/citibikenyc/client.rb +10 -0
- data/lib/citibikenyc/client/branches.rb +24 -0
- data/lib/citibikenyc/client/helmets.rb +24 -0
- data/lib/citibikenyc/client/stations.rb +35 -0
- data/lib/citibikenyc/configuration.rb +78 -0
- data/lib/citibikenyc/connection.rb +27 -0
- data/lib/citibikenyc/error.rb +7 -0
- data/lib/citibikenyc/request.rb +45 -0
- data/lib/citibikenyc/version.rb +3 -0
- data/lib/faraday/raise_http_exception.rb +27 -0
- data/spec/citibikenyc/client/branches_spec.rb +29 -0
- data/spec/citibikenyc/client/helmets_spec.rb +29 -0
- data/spec/citibikenyc/client/stations_spec.rb +53 -0
- data/spec/citibikenyc_spec.rb +93 -0
- data/spec/fixtures/branches.json +253 -0
- data/spec/fixtures/helmets.json +185 -0
- data/spec/fixtures/stations.json +1 -0
- data/spec/fixtures/stations_update_only.json +1 -0
- data/spec/spec_helper.rb +51 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07aeb5ee83325ec495e5a2a452d7548e214fe98a
|
4
|
+
data.tar.gz: 9e8630dba61d0850a7634e105dbcf712daa8de63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff897cf93ba7d222f1ac742effdf2c16368c221df6c7c8c93a6f2b80049b4efd60450ad739dc902b87dd48346371a66ae99cf1debf319f304f9e50fc25210b7
|
7
|
+
data.tar.gz: cf669aa4c87de7a3d89d25f1ce1a8a9153acc2fd517c3ba15d3f80510135c95f67e839e449ea5dd2e9ae29f292a476e48b4e6eaaa3cf13399d4940f451631d4e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Edgar Gonzalez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Citibikenyc [![Build Status](https://travis-ci.org/edgar/citibikenyc.png?branch=master)](https://travis-ci.org/edgar/citibikenyc) [![Dependency Status](https://gemnasium.com/edgar/citibikenyc.png)](https://gemnasium.com/edgar/citibikenyc)
|
2
|
+
A gem for CitibikeNYC API - citibikenyc.com
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
gem 'citibikenyc'
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install citibikenyc
|
17
|
+
|
18
|
+
## API Usage Examples
|
19
|
+
|
20
|
+
require "rubygems"
|
21
|
+
require "citibikenyc"
|
22
|
+
|
23
|
+
# Get a list of all stations
|
24
|
+
puts Citibikenyc.stations
|
25
|
+
|
26
|
+
# Get only the current status for all stations
|
27
|
+
puts Citibikenyc.stations_status
|
28
|
+
|
29
|
+
# Get helmets info
|
30
|
+
puts Citibikenyc.helmets
|
31
|
+
|
32
|
+
# Get branches info
|
33
|
+
puts Citibikenyc.branches
|
34
|
+
|
35
|
+
For more information about the data returned by every method please check the specs folder
|
36
|
+
|
37
|
+
## Configuration
|
38
|
+
|
39
|
+
Because citibikenyc gem is based on [Faraday](https://github.com/lostisland/faraday), it supports the following adapters:
|
40
|
+
|
41
|
+
* Net::HTTP (default)
|
42
|
+
* [Excon][https://github.com/geemus/excon]
|
43
|
+
* [Typhoeus][https://github.com/typhoeus/typhoeus]
|
44
|
+
* [Patron][http://toland.github.com/patron/]
|
45
|
+
* [EventMachine][https://github.com/igrigorik/em-http-request]
|
46
|
+
|
47
|
+
Beside the adapter, you can change the following properties:
|
48
|
+
|
49
|
+
* endpoint
|
50
|
+
* format
|
51
|
+
* user_agent
|
52
|
+
* proxy
|
53
|
+
* debug
|
54
|
+
|
55
|
+
For instance:
|
56
|
+
|
57
|
+
require 'typhoeus/adapters/faraday' # You will need the typhoeus gem
|
58
|
+
|
59
|
+
client = Citibikenyc.client(adapter: :typhoeus, user_agent: "foobar v1", debug: true)
|
60
|
+
client.stations
|
61
|
+
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new
|
6
|
+
task :default => :spec
|
7
|
+
task :test => :spec
|
8
|
+
|
9
|
+
namespace :doc do
|
10
|
+
begin
|
11
|
+
require 'yard'
|
12
|
+
rescue LoadError
|
13
|
+
# ignore
|
14
|
+
else
|
15
|
+
YARD::Rake::YardocTask.new do |task|
|
16
|
+
task.files = ['lib/**/*.rb']
|
17
|
+
task.options = [
|
18
|
+
'--protected',
|
19
|
+
'--output-dir', 'doc/yard',
|
20
|
+
'--tag', 'format:Supported formats',
|
21
|
+
'--markup', 'markdown',
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Open an irb session preloaded with this library"
|
28
|
+
task :console do
|
29
|
+
sh "irb -rubygems -I lib -r citibikenyc.rb"
|
30
|
+
end
|
data/citibikenyc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/citibikenyc/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_development_dependency 'rake'
|
6
|
+
gem.add_development_dependency('rspec', '~> 2.13.0')
|
7
|
+
gem.add_development_dependency('webmock', '~> 1.12.3')
|
8
|
+
gem.add_development_dependency('yard', '~> 0.8.6.2')
|
9
|
+
gem.add_development_dependency('bluecloth', '~> 2.2.0')
|
10
|
+
gem.add_runtime_dependency('faraday', '~> 0.8.7')
|
11
|
+
gem.add_runtime_dependency('faraday_middleware', '~> 0.9.0')
|
12
|
+
gem.add_runtime_dependency('multi_json', '~> 1.7.7')
|
13
|
+
gem.add_runtime_dependency('hashie', '~> 2.0.5')
|
14
|
+
gem.authors = ["Edgar Gonzalez"]
|
15
|
+
gem.email = ["edgargonzalez@gmail.com"]
|
16
|
+
gem.description = %q{A ruby wrapper for Citibikenyc API}
|
17
|
+
gem.homepage = "http://github.com/edgar/citibikenyc"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($\)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.summary = %q{A ruby wrapper for Citibikenyc API}
|
23
|
+
gem.name = "citibikenyc"
|
24
|
+
gem.require_paths = ["lib"]
|
25
|
+
gem.version = Citibikenyc::VERSION.dup
|
26
|
+
end
|
data/lib/citibikenyc.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../citibikenyc/error', __FILE__)
|
2
|
+
require File.expand_path('../citibikenyc/configuration', __FILE__)
|
3
|
+
require File.expand_path('../citibikenyc/api', __FILE__)
|
4
|
+
require File.expand_path('../citibikenyc/client', __FILE__)
|
5
|
+
|
6
|
+
module Citibikenyc
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
# Alias for Citibikenyc::Client.new
|
10
|
+
#
|
11
|
+
# @return [Citibikenyc::Client]
|
12
|
+
def self.client(options={})
|
13
|
+
Citibikenyc::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to Citibikenyc::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
client.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to Citibikenyc::Client
|
23
|
+
def self.respond_to?(method)
|
24
|
+
return client.respond_to?(method) || super
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
|
4
|
+
module Citibikenyc
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options={})
|
12
|
+
options = Citibikenyc.options.merge(options)
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
include Connection
|
19
|
+
include Request
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Citibikenyc
|
2
|
+
class Client
|
3
|
+
# Defines methods related to branches
|
4
|
+
module Branches
|
5
|
+
|
6
|
+
# Returns all information about branches
|
7
|
+
#
|
8
|
+
# @param options [Hash] An optional options hash
|
9
|
+
# @return [Hashie::Mash]
|
10
|
+
# @example Return all information about the branches
|
11
|
+
# Citibikenyc.branches
|
12
|
+
# @format :json
|
13
|
+
def branches(options={})
|
14
|
+
get(branches_path, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def branches_path
|
20
|
+
'v1/branch/list'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Citibikenyc
|
2
|
+
class Client
|
3
|
+
# Defines methods related to helmets
|
4
|
+
module Helmets
|
5
|
+
|
6
|
+
# Returns all information about helmets
|
7
|
+
#
|
8
|
+
# @param options [Hash] An optional options hash
|
9
|
+
# @return [Hashie::Mash]
|
10
|
+
# @example Return all information about the helmets
|
11
|
+
# Citibikenyc.helmets
|
12
|
+
# @format :json
|
13
|
+
def helmets(options={})
|
14
|
+
get(helmets_path, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def helmets_path
|
20
|
+
'v1/helmet/list'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Citibikenyc
|
2
|
+
class Client
|
3
|
+
# Defines methods related to stations
|
4
|
+
module Stations
|
5
|
+
|
6
|
+
# Returns all information about stations
|
7
|
+
#
|
8
|
+
# @param options [Hash] An optional options hash
|
9
|
+
# @return [Hashie::Mash]
|
10
|
+
# @example Return all information about the stations
|
11
|
+
# Citibikenyc.stations
|
12
|
+
# @format :json
|
13
|
+
def stations(options={})
|
14
|
+
get(stations_path, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns only the stations status
|
18
|
+
#
|
19
|
+
# @param options [Hash] An optional options hash
|
20
|
+
# @return [Hashie::Mash]
|
21
|
+
# @example Returns only the stations status
|
22
|
+
# Citibikenyc.stations_status
|
23
|
+
# @format :json
|
24
|
+
def stations_status(options={})
|
25
|
+
get(stations_path, options.merge(:updateOnly => true))
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def stations_path
|
31
|
+
'data2/stations.php'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module Citibikenyc
|
5
|
+
# Defines constants and methods related to configuration
|
6
|
+
module Configuration
|
7
|
+
# An array of valid keys in the options hash when configuring a {Citibikenyc::API}
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:adapter,
|
10
|
+
:endpoint,
|
11
|
+
:format,
|
12
|
+
:user_agent,
|
13
|
+
:proxy,
|
14
|
+
:debug
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# An array of valid request/response formats
|
18
|
+
VALID_FORMATS = [
|
19
|
+
:json].freeze
|
20
|
+
|
21
|
+
# The adapter that will be used to connect if none is set
|
22
|
+
#
|
23
|
+
# @note The default faraday adapter is Net::HTTP.
|
24
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
25
|
+
|
26
|
+
# By default, don't set an application ID
|
27
|
+
DEFAULT_CLIENT_ID = nil
|
28
|
+
|
29
|
+
# The endpoint that will be used to connect if none is set
|
30
|
+
#
|
31
|
+
# @note There is no reason to use any other endpoint at this time
|
32
|
+
DEFAULT_ENDPOINT = 'http://appservices.citibikenyc.com/'.freeze
|
33
|
+
|
34
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
35
|
+
#
|
36
|
+
# @note JSON is the only available format at this time
|
37
|
+
DEFAULT_FORMAT = :json
|
38
|
+
|
39
|
+
# By default, don't use a proxy server
|
40
|
+
DEFAULT_PROXY = nil
|
41
|
+
|
42
|
+
# By default, dont' log the request/response
|
43
|
+
DEFAULT_DEBUG = false
|
44
|
+
|
45
|
+
# The user agent that will be sent to the API endpoint if none is set
|
46
|
+
DEFAULT_USER_AGENT = "Citibikenyc #{Citibikenyc::VERSION}".freeze
|
47
|
+
|
48
|
+
# @private
|
49
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
50
|
+
|
51
|
+
# When this module is extended, set all configuration options to their default values
|
52
|
+
def self.extended(base)
|
53
|
+
base.reset
|
54
|
+
end
|
55
|
+
|
56
|
+
# Convenience method to allow configuration options to be set in a block
|
57
|
+
def configure
|
58
|
+
yield self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create a hash of options and their values
|
62
|
+
def options
|
63
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
64
|
+
option.merge!(key => send(key))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Reset all configuration options to defaults
|
69
|
+
def reset
|
70
|
+
self.adapter = DEFAULT_ADAPTER
|
71
|
+
self.endpoint = DEFAULT_ENDPOINT
|
72
|
+
self.format = DEFAULT_FORMAT
|
73
|
+
self.user_agent = DEFAULT_USER_AGENT
|
74
|
+
self.proxy = DEFAULT_PROXY
|
75
|
+
self.debug = DEFAULT_DEBUG
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module Citibikenyc
|
5
|
+
# @private
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection(raw=false)
|
10
|
+
options = {
|
11
|
+
:headers => {'Accept' => "application/json; charset=utf-8", 'User-Agent' => user_agent},
|
12
|
+
:proxy => proxy,
|
13
|
+
:ssl => {:verify => false},
|
14
|
+
:url => endpoint,
|
15
|
+
}
|
16
|
+
|
17
|
+
Faraday::Connection.new(options) do |connection|
|
18
|
+
connection.use Faraday::Request::UrlEncoded
|
19
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
20
|
+
connection.use Faraday::Response::ParseJson unless raw
|
21
|
+
connection.use FaradayMiddleware::RaiseHttpException
|
22
|
+
connection.use Faraday::Response::Logger if debug
|
23
|
+
connection.adapter(adapter)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|