caruby2go 0.0.2 → 0.0.4
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 +4 -4
- data/Gemfile.lock +16 -14
- data/README.md +11 -2
- data/bin/caruby2go +15 -9
- data/caruby2go.gemspec +4 -1
- data/circle.yml +4 -0
- data/lib/caruby2go.rb +7 -3
- data/lib/caruby2go/version.rb +1 -1
- data/lib/invalid_location_error.rb +5 -0
- data/test/test_caruby2go.rb +33 -2
- data/test/test_invalid_location_error.rb +9 -0
- metadata +28 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9d8f3553cff2a26e8158534f0c9b8f0dfec95b1
|
4
|
+
data.tar.gz: cdadd90cbddbf5dc632f6048dd4dac845e75e2bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b118da409b2f32432672762889d293948e4be92a4d2a4b2d73cb54f372975720bc917ec06b95a2feccd0a31ad7076f44bc9afd5db30be28daebd291b1b7cc1
|
7
|
+
data.tar.gz: ddc779599342762cb7e78c6405de4e1e233e74934ecda9d148b9bfffe5638435cec179974827bca2540b27b1460de10f7f9c53faa6a6ce55f580a1f176b359ae
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
caruby2go (0.0.
|
4
|
+
caruby2go (0.0.4)
|
5
|
+
thor (~> 0.19.1)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
byebug (6.0.2)
|
9
11
|
celluloid (0.16.0)
|
10
12
|
timers (~> 4.0.0)
|
11
13
|
coderay (1.1.0)
|
@@ -33,6 +35,7 @@ GEM
|
|
33
35
|
rb-inotify (>= 0.9)
|
34
36
|
lumberjack (1.0.9)
|
35
37
|
method_source (0.8.2)
|
38
|
+
minitest (5.4.3)
|
36
39
|
nenv (0.2.0)
|
37
40
|
notiffany (0.0.6)
|
38
41
|
nenv (~> 0.1)
|
@@ -62,14 +65,10 @@ GEM
|
|
62
65
|
rspec-mocks (3.2.1)
|
63
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
67
|
rspec-support (~> 3.2.0)
|
65
|
-
rspec-nc (0.2.0)
|
66
|
-
rspec (>= 2.9)
|
67
|
-
terminal-notifier (>= 1.4)
|
68
68
|
rspec-support (3.2.2)
|
69
69
|
shellany (0.0.1)
|
70
70
|
slop (3.6.0)
|
71
71
|
spy (0.4.1)
|
72
|
-
terminal-notifier (1.6.2)
|
73
72
|
thor (0.19.1)
|
74
73
|
timers (4.0.1)
|
75
74
|
hitimes
|
@@ -79,14 +78,17 @@ PLATFORMS
|
|
79
78
|
|
80
79
|
DEPENDENCIES
|
81
80
|
bundler (~> 1.7)
|
81
|
+
byebug
|
82
82
|
caruby2go!
|
83
|
-
guard
|
84
|
-
guard-rspec
|
85
|
-
|
86
|
-
pry
|
87
|
-
pry-
|
83
|
+
guard (~> 2.12)
|
84
|
+
guard-rspec (~> 4.5)
|
85
|
+
minitest
|
86
|
+
pry (~> 0.10)
|
87
|
+
pry-nav (~> 0.2)
|
88
|
+
pry-remote (~> 0.1)
|
88
89
|
rake (~> 10.0)
|
89
|
-
rspec
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
rspec (~> 3.2)
|
91
|
+
spy (~> 0.4)
|
92
|
+
|
93
|
+
BUNDLED WITH
|
94
|
+
1.10.6
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://circleci.com/gh/eebbesen/caruby2go)
|
2
|
+
|
1
3
|
# caruby2go
|
2
4
|
|
3
5
|
caruby2go is a gem that exposes [the car2go api](https://code.google.com/p/car2go/wiki/index_v2_1).
|
@@ -24,16 +26,23 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
$ rake build
|
26
28
|
|
27
|
-
build (in this project's root) will build and install the gem locally.
|
29
|
+
Executing `build` (in this project's root) will build and install the gem locally.
|
28
30
|
|
29
31
|
## Local usage
|
30
|
-
The script requires you to set the CONSUMER_KEY environment variable to your
|
32
|
+
The script requires you to set the `CONSUMER_KEY` environment variable to your car2go consumer key
|
31
33
|
|
32
34
|
$ set CONSUMER_KEY=<your_consumer_key>
|
33
35
|
$ bin/caruby2go p kobenhavn
|
34
36
|
or
|
35
37
|
|
36
38
|
$ CONSUMER_KEY=<your_consumer_key> bin/caruby2go p kobenhavn
|
39
|
+
or set it for the application user via a profile file.
|
40
|
+
|
41
|
+
## Finding a city name
|
42
|
+
You will see `400 Bad Request (OpenURI::HTTPError)` if you enter an invalid city. I was unable to locate a list of valid cities (the car2go locations endpoint does not provied that information) but have compiled a list of my own which you can view at doc/cities.txt.
|
43
|
+
|
44
|
+
## Reference implementation
|
45
|
+
[Freerider](https://github.com/eebbesen/freerider) is a gem which uses caruby2go to access car2go's API to identify cars you can refuel for free minutes.
|
37
46
|
|
38
47
|
## Contributing
|
39
48
|
|
data/bin/caruby2go
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'thor'
|
4
4
|
require_relative '../lib/caruby2go.rb'
|
5
|
-
require 'pry'
|
6
5
|
|
7
6
|
##
|
8
7
|
# Script for running the gem from the command line
|
9
8
|
class Caruby2goScript < Thor
|
10
9
|
RECORD_SEPARATOR = '========================================================='
|
10
|
+
|
11
|
+
class_option :raw, :type => :boolean, :desc => "Print the raw JSON from Car2Go"
|
12
|
+
|
11
13
|
desc 'vehicles CITY', 'get vehicles for CITY'
|
12
14
|
def vehicles(city)
|
13
15
|
call_api(city)
|
@@ -35,7 +37,7 @@ class Caruby2goScript < Thor
|
|
35
37
|
return if ENV['CONSUMER_KEY']
|
36
38
|
puts 'Set environment variable CONSUMER_KEY to your Car2Go consumer key.'
|
37
39
|
puts 'For example:'
|
38
|
-
puts ' $ CONSUMER_KEY=
|
40
|
+
puts ' $ CONSUMER_KEY=yourkey bin/caruby2go v twincities'
|
39
41
|
false
|
40
42
|
end
|
41
43
|
|
@@ -43,17 +45,21 @@ class Caruby2goScript < Thor
|
|
43
45
|
require_key
|
44
46
|
caruby2go = Caruby2go.new(ENV['CONSUMER_KEY'], city)
|
45
47
|
results = caruby2go.send("#{caller_locations(1, 1)[0].label}".to_sym)
|
46
|
-
|
48
|
+
print results
|
47
49
|
end
|
48
50
|
|
49
|
-
def
|
50
|
-
|
51
|
-
puts
|
52
|
-
|
53
|
-
|
51
|
+
def print(records)
|
52
|
+
if options[:raw]
|
53
|
+
puts records
|
54
|
+
else
|
55
|
+
records.each do |record|
|
56
|
+
puts RECORD_SEPARATOR
|
57
|
+
record.each do |k, v|
|
58
|
+
puts "#{k}:: #{v}"
|
59
|
+
end
|
54
60
|
end
|
61
|
+
puts RECORD_SEPARATOR
|
55
62
|
end
|
56
|
-
puts RECORD_SEPARATOR
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
data/caruby2go.gemspec
CHANGED
@@ -18,18 +18,21 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
|
+
|
21
23
|
spec.add_dependency 'thor', '~> 0.19.1'
|
22
24
|
|
23
25
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
27
|
|
26
28
|
# test
|
29
|
+
spec.add_development_dependency 'minitest'
|
27
30
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
28
|
-
spec.add_development_dependency 'rspec-nc', '~> 3.2'
|
29
31
|
spec.add_development_dependency 'guard', '~> 2.12'
|
30
32
|
spec.add_development_dependency 'guard-rspec', '~> 4.5'
|
31
33
|
spec.add_development_dependency 'pry', '~>0.10'
|
32
34
|
spec.add_development_dependency 'pry-remote', '~> 0.1'
|
33
35
|
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
34
36
|
spec.add_development_dependency 'spy', '~> 0.4'
|
37
|
+
spec.add_development_dependency 'byebug'
|
35
38
|
end
|
data/circle.yml
ADDED
data/lib/caruby2go.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'caruby2go/version'
|
2
|
+
require 'invalid_location_error'
|
2
3
|
require 'open-uri'
|
3
4
|
require 'json'
|
4
5
|
|
5
6
|
##
|
6
|
-
# Wraps the Car2Go public API
|
7
|
+
# Wraps the Car2Go public API
|
7
8
|
class Caruby2go
|
8
9
|
CAR2GO_URI = 'https://www.car2go.com/api/v2.1'
|
9
10
|
|
@@ -31,12 +32,15 @@ class Caruby2go
|
|
31
32
|
private
|
32
33
|
|
33
34
|
def build_uri(endpoint)
|
34
|
-
loc_part = @location ? "loc=#{@location}" : nil
|
35
|
-
"#{CAR2GO_URI}/#{endpoint}
|
35
|
+
loc_part = @location ? "&loc=#{@location}" : nil
|
36
|
+
"#{CAR2GO_URI}/#{endpoint}?oauth_consumer_key=#{@consumer_key}#{loc_part}&format=json"
|
36
37
|
end
|
37
38
|
|
38
39
|
def issue_get(uri, json_header = 'placemarks')
|
39
40
|
data = open(uri).read
|
40
41
|
JSON.parse(data)[json_header]
|
42
|
+
rescue OpenURI::HTTPError => e
|
43
|
+
raise InvalidLocationError.new(@location) if '400 Bad Request' == e.message
|
44
|
+
raise e
|
41
45
|
end
|
42
46
|
end
|
data/lib/caruby2go/version.rb
CHANGED
data/test/test_caruby2go.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require './lib/caruby2go'
|
3
3
|
require 'spy/integration'
|
4
|
+
require 'byebug'
|
4
5
|
|
5
6
|
class TestCaruby2go < Minitest::Test
|
6
7
|
def setup
|
@@ -12,13 +13,13 @@ class TestCaruby2go < Minitest::Test
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_build_uri_with_location
|
15
|
-
assert_equal 'https://www.car2go.com/api/v2.1/endpt?loc=MPLS&
|
16
|
+
assert_equal 'https://www.car2go.com/api/v2.1/endpt?oauth_consumer_key=testkey&loc=MPLS&format=json',
|
16
17
|
@caruby2go.send(:build_uri, 'endpt')
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_build_uri_without_location
|
20
21
|
@caruby2go = Caruby2go.new('testkey')
|
21
|
-
assert_equal 'https://www.car2go.com/api/v2.1/endpt
|
22
|
+
assert_equal 'https://www.car2go.com/api/v2.1/endpt?oauth_consumer_key=testkey&format=json',
|
22
23
|
@caruby2go.send(:build_uri, 'endpt')
|
23
24
|
end
|
24
25
|
|
@@ -70,6 +71,36 @@ class TestCaruby2go < Minitest::Test
|
|
70
71
|
run_mock(gasstations_json, :gasstations)
|
71
72
|
end
|
72
73
|
|
74
|
+
def test_issue_get_400
|
75
|
+
mock_open_uri = Minitest::Mock.new
|
76
|
+
mock_open_uri.expect(:read, nil) do
|
77
|
+
raise OpenURI::HTTPError.new('400 Bad Request', nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
error = assert_raises InvalidLocationError do
|
81
|
+
OpenURI.stub :open_uri, mock_open_uri do
|
82
|
+
@caruby2go.send(:issue_get, 'http://example.com')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
assert_equal "Car2Go probably doesn't like the city you entered: MPLS", error.message
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_issue_get_other_than_400
|
89
|
+
mock_open_uri = Minitest::Mock.new
|
90
|
+
mock_open_uri.expect(:read, nil) do
|
91
|
+
raise OpenURI::HTTPError.new('401 Unauthorized', nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
error = assert_raises OpenURI::HTTPError do
|
95
|
+
OpenURI.stub :open_uri, mock_open_uri do
|
96
|
+
@caruby2go.send(:issue_get, 'http://example.com')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
assert_equal '401 Unauthorized', error.message
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
73
104
|
def run_mock(json, method)
|
74
105
|
mock_open_uri = Minitest::Mock.new
|
75
106
|
mock_open_uri.expect(:read, json)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require './lib/invalid_location_error'
|
3
|
+
|
4
|
+
class TestInvalidLocationError < Minitest::Test
|
5
|
+
def test_initialize
|
6
|
+
ile = InvalidLocationError.new('nowheresville')
|
7
|
+
assert_equal "Car2Go probably doesn't like the city you entered: nowheresville", ile.message
|
8
|
+
end
|
9
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caruby2go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Ebbesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -53,21 +53,21 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.4'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: byebug
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Ruby gem that wraps the car2go API -- only supports the public API at
|
168
182
|
present
|
169
183
|
email:
|
@@ -183,10 +197,13 @@ files:
|
|
183
197
|
- bin/caruby2go
|
184
198
|
- build
|
185
199
|
- caruby2go.gemspec
|
200
|
+
- circle.yml
|
186
201
|
- lib/caruby2go.rb
|
187
202
|
- lib/caruby2go/version.rb
|
203
|
+
- lib/invalid_location_error.rb
|
188
204
|
- test/test_caruby2go.rb
|
189
205
|
- test/test_caruby2go_integration.rb
|
206
|
+
- test/test_invalid_location_error.rb
|
190
207
|
homepage: https://github.com/eebbesen/caruby2go
|
191
208
|
licenses:
|
192
209
|
- MIT
|
@@ -199,7 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
216
|
requirements:
|
200
217
|
- - ">="
|
201
218
|
- !ruby/object:Gem::Version
|
202
|
-
version: '0'
|
219
|
+
version: '2.0'
|
203
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
221
|
requirements:
|
205
222
|
- - ">="
|
@@ -207,10 +224,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
224
|
version: '0'
|
208
225
|
requirements: []
|
209
226
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.4.
|
227
|
+
rubygems_version: 2.4.6
|
211
228
|
signing_key:
|
212
229
|
specification_version: 4
|
213
230
|
summary: Ruby gem that wraps the car2go API
|
214
231
|
test_files:
|
215
232
|
- test/test_caruby2go.rb
|
216
233
|
- test/test_caruby2go_integration.rb
|
234
|
+
- test/test_invalid_location_error.rb
|