citywrapper 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/citywrapper.gemspec +33 -0
- data/lib/citywrapper.rb +27 -0
- data/lib/citywrapper/api_base.rb +73 -0
- data/lib/citywrapper/configuration.rb +5 -0
- data/lib/citywrapper/resources/coverage.rb +17 -0
- data/lib/citywrapper/resources/single_point_coverage.rb +16 -0
- data/lib/citywrapper/resources/travel_time.rb +19 -0
- data/lib/citywrapper/version.rb +3 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48ace1ed0874f727cd99677a7cdc8dfa0d91b233
|
4
|
+
data.tar.gz: eff3079f4b193a51378adcd4dd9502f24db95a31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64cbbfa1829be778d21822e3098c505683f6846d2584e40c61a6a51378be2c169d777e3b1f4757f6215fc14041b95de3acaa27b45fdc20b528797435b7be78d0
|
7
|
+
data.tar.gz: b8c31b46301af22fb61203cafae42fd4043e169bf96af5de2e465c852d07bd8ef0af5a7e638ea1e21e4accd9ef837a295df34ab9785a6d715931800740d9816c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Joseph Southan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Citywrapper
|
2
|
+
[](https://travis-ci.org/JoeSouthan/citywrapper)
|
3
|
+
[](https://codeclimate.com/github/JoeSouthan/citywrapper)
|
4
|
+
#### WIP
|
5
|
+
|
6
|
+
TODO:
|
7
|
+
- Better documentation
|
8
|
+
|
9
|
+
A very light wrapper around the [Citymapper API](https://citymapper.3scale.net/).
|
10
|
+
|
11
|
+
This is in very early development, the Ruby API may change drastically.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'citywrapper'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install citywrapper
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Set your API key
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Citywrapper.configure do |c|
|
35
|
+
c.api_key = 'API_KEY'
|
36
|
+
end
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
Try making a request:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
t = Citywrapper::TravelTime.between(
|
44
|
+
start_coordinates: [51.525246, 0.084672],
|
45
|
+
end_coordinates: [51.559098, 0.074503],
|
46
|
+
time: Time.new(2016, 9, 7, 21, 00),
|
47
|
+
time_type: :arrival,
|
48
|
+
)
|
49
|
+
|
50
|
+
t.travel_time_minutes # 43
|
51
|
+
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/joesouthan/citywrapper.
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
69
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "citywrapper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/citywrapper.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'citywrapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'citywrapper'
|
8
|
+
spec.version = Citywrapper::VERSION
|
9
|
+
spec.authors = ['Joseph Southan']
|
10
|
+
spec.email = ['joe+github@sthn.io']
|
11
|
+
|
12
|
+
spec.summary = 'Wraps the Citymapper API'
|
13
|
+
spec.description = 'Simple wrapper around the Citymapper API'
|
14
|
+
spec.homepage = 'https://www.github.com/joesouthan/citywrapper'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = '>= 2.0'
|
17
|
+
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'vcr', '~> 3'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
30
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
31
|
+
spec.add_development_dependency 'fuubar', '~> 2.2'
|
32
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
|
33
|
+
end
|
data/lib/citywrapper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'json'
|
4
|
+
require 'citywrapper/version'
|
5
|
+
require 'citywrapper/api_base'
|
6
|
+
require 'citywrapper/configuration'
|
7
|
+
require 'citywrapper/resources/travel_time'
|
8
|
+
require 'citywrapper/resources/coverage'
|
9
|
+
require 'citywrapper/resources/single_point_coverage'
|
10
|
+
|
11
|
+
module Citywrapper
|
12
|
+
BASE_URL = 'https://developer.citymapper.com/api'.freeze
|
13
|
+
API_VERSION = '1'.freeze
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :api_key
|
17
|
+
attr_writer :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
yield(configuration)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Citywrapper
|
2
|
+
class ApiBase
|
3
|
+
attr_accessor :config, :response
|
4
|
+
|
5
|
+
JSON_HEADERS = {
|
6
|
+
'Content-Type' => 'application/json',
|
7
|
+
'Accept' => 'application/json'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@config = Citywrapper.configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def request(params: {}, method: :get)
|
15
|
+
raise 'Please set your API key' unless config.api_key
|
16
|
+
|
17
|
+
@method = method
|
18
|
+
@params = params
|
19
|
+
@query_uri = build_query
|
20
|
+
|
21
|
+
run_request
|
22
|
+
process_response
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_query
|
28
|
+
base_api_uri.tap do |uri|
|
29
|
+
uri.query = [parameters_for_query, uri.query].compact.join('&')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parameters_for_query
|
34
|
+
URI.encode_www_form(@params) unless @method == :post
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_response
|
38
|
+
case @response
|
39
|
+
when Net::HTTPNotFound
|
40
|
+
raise "Please check the resource type - #{@resource}"
|
41
|
+
when Net::HTTPForbidden
|
42
|
+
raise 'Please check your API key'
|
43
|
+
end
|
44
|
+
|
45
|
+
JSON.parse(@response.body, object_class: OpenStruct)
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_request
|
49
|
+
case @method
|
50
|
+
when :get
|
51
|
+
@response = Net::HTTP.get_response(@query_uri)
|
52
|
+
when :post
|
53
|
+
request = Net::HTTP.new(@query_uri.host, @query_uri.port)
|
54
|
+
request.use_ssl = true
|
55
|
+
@response = request.post(("#{@query_uri.path}?#{@query_uri.query}"), @params.to_json, JSON_HEADERS)
|
56
|
+
else
|
57
|
+
raise 'Only GET or POST'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def base_api_uri
|
62
|
+
URI(base_api_url)
|
63
|
+
end
|
64
|
+
|
65
|
+
def base_api_url
|
66
|
+
if @resource
|
67
|
+
"#{BASE_URL}/#{API_VERSION}/#{@resource}/?key=#{config.api_key}"
|
68
|
+
else
|
69
|
+
"#{BASE_URL}/#{API_VERSION}/?key=#{config.api_key}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Citywrapper
|
2
|
+
class TravelTime < ApiBase
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
@resource = 'traveltime'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.between(start_coordinates: [], end_coordinates: [], time: nil, time_type: nil)
|
9
|
+
new.request(
|
10
|
+
params: {
|
11
|
+
startcoord: start_coordinates.join(','),
|
12
|
+
endcoord: end_coordinates.join(','),
|
13
|
+
time: time ? time.to_i : nil,
|
14
|
+
time_type: time_type
|
15
|
+
}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: citywrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joseph Southan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fuubar
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codeclimate-test-reporter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.6'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.6'
|
125
|
+
description: Simple wrapper around the Citymapper API
|
126
|
+
email:
|
127
|
+
- joe+github@sthn.io
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".ruby-version"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- citywrapper.gemspec
|
143
|
+
- lib/citywrapper.rb
|
144
|
+
- lib/citywrapper/api_base.rb
|
145
|
+
- lib/citywrapper/configuration.rb
|
146
|
+
- lib/citywrapper/resources/coverage.rb
|
147
|
+
- lib/citywrapper/resources/single_point_coverage.rb
|
148
|
+
- lib/citywrapper/resources/travel_time.rb
|
149
|
+
- lib/citywrapper/version.rb
|
150
|
+
homepage: https://www.github.com/joesouthan/citywrapper
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata:
|
154
|
+
allowed_push_host: https://rubygems.org
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '2.0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.5.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Wraps the Citymapper API
|
175
|
+
test_files: []
|