caruby2go 0.0.4 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -10
- data/lib/caruby2go.rb +7 -2
- data/lib/caruby2go/version.rb +1 -1
- data/test/test_caruby2go.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad0725cbc7907bfcb303396fb89ce0d9f93de48f
|
4
|
+
data.tar.gz: bceac7b4db47cc3051e3c01a1a3e583bd9f81380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ab691d369f0a373a53e04b56872b0c9b677a133400d76c3e304294ac176e7a8bece40f10473801dca61674881323258a1af63f310a4b88ea04dfd0db811100
|
7
|
+
data.tar.gz: eaa3dba26f5add897b677cc2f002ec56bf217974b29a68abd0c43264a3e2e13b76f17fad8acd5a9c49796c9db2cabd44b966b3fa8e53cb5448700386a261adaa
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,21 +28,39 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
Executing `build` (in this project's root) will build and install the gem locally.
|
30
30
|
|
31
|
-
##
|
32
|
-
The script requires you to set the `CONSUMER_KEY` environment variable to your car2go consumer key
|
31
|
+
## Publishing
|
33
32
|
|
34
|
-
$
|
35
|
-
|
36
|
-
|
33
|
+
$ gem push pkg/caruby2go-<version>.gem
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
caruby2go requires you to have a car2go consumer key
|
37
|
+
|
38
|
+
### In your project
|
39
|
+
|
40
|
+
caruby2go_client = Caruby2go.new(ENV['CAR2GO_CONSUMER_KEY'], 'twincities')
|
41
|
+
caruby2go_client.vehicles
|
42
|
+
|
43
|
+
By default [the Car2Go API URL](https://www.car2go.com/api/v2.1) is used, but you have the option to pass in an alternate URL.
|
44
|
+
I added this option so I could use Runscape to monitor API calls.
|
45
|
+
|
46
|
+
caruby2go_client = Caruby2go.new(ENV['CAR2GO_CONSUMER_KEY'], 'twincities', 'https://www-car2go-com-eeeeeeee.runscope.net/api/v2.1')
|
47
|
+
|
48
|
+
### Included script
|
49
|
+
#### Find car locations for a city
|
37
50
|
|
38
51
|
$ CONSUMER_KEY=<your_consumer_key> bin/caruby2go p kobenhavn
|
39
|
-
or set it for the application user via a profile file.
|
40
52
|
|
41
|
-
|
42
|
-
|
53
|
+
#### Finding a city name
|
54
|
+
Use the `locationName` value (spaces removed) from the following call
|
55
|
+
|
56
|
+
$ CONSUMER_KEY=<your_consumer_key> bin/caruby2go l
|
57
|
+
|
58
|
+
[Freerider](https://github.com/eebbesen/freerider) has a script that will return an alphabetized, formatted list of all valid locations, too.
|
59
|
+
|
60
|
+
## Reference implementations
|
61
|
+
* bin/caruby2go in this project
|
43
62
|
|
44
|
-
|
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.
|
63
|
+
* [Freerider](https://github.com/eebbesen/freerider) is a gem which uses caruby2go to access car2go's API to track Car2Go vehicle movement.
|
46
64
|
|
47
65
|
## Contributing
|
48
66
|
|
data/lib/caruby2go.rb
CHANGED
@@ -8,9 +8,10 @@ require 'json'
|
|
8
8
|
class Caruby2go
|
9
9
|
CAR2GO_URI = 'https://www.car2go.com/api/v2.1'
|
10
10
|
|
11
|
-
def initialize(consumer_key, location =
|
11
|
+
def initialize(consumer_key, location=nil, uri=CAR2GO_URI)
|
12
12
|
@consumer_key = consumer_key
|
13
13
|
@location = location
|
14
|
+
@uri = uri
|
14
15
|
end
|
15
16
|
|
16
17
|
def gasstations # placemarks
|
@@ -33,7 +34,7 @@ class Caruby2go
|
|
33
34
|
|
34
35
|
def build_uri(endpoint)
|
35
36
|
loc_part = @location ? "&loc=#{@location}" : nil
|
36
|
-
"#{
|
37
|
+
"#{@uri}/#{endpoint}?oauth_consumer_key=#{@consumer_key}#{loc_part}&format=json"
|
37
38
|
end
|
38
39
|
|
39
40
|
def issue_get(uri, json_header = 'placemarks')
|
@@ -43,4 +44,8 @@ class Caruby2go
|
|
43
44
|
raise InvalidLocationError.new(@location) if '400 Bad Request' == e.message
|
44
45
|
raise e
|
45
46
|
end
|
47
|
+
|
48
|
+
def uri
|
49
|
+
@uri
|
50
|
+
end
|
46
51
|
end
|
data/lib/caruby2go/version.rb
CHANGED
data/test/test_caruby2go.rb
CHANGED
@@ -5,7 +5,7 @@ require 'byebug'
|
|
5
5
|
|
6
6
|
class TestCaruby2go < Minitest::Test
|
7
7
|
def setup
|
8
|
-
@caruby2go = Caruby2go.new('testkey', 'MPLS')
|
8
|
+
@caruby2go = Caruby2go.new('testkey', 'MPLS', 'https://www.justabaseuri.com2go')
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_initialize
|
@@ -13,13 +13,13 @@ class TestCaruby2go < Minitest::Test
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_build_uri_with_location
|
16
|
-
assert_equal
|
16
|
+
assert_equal "#{@caruby2go.send(:uri)}/endpt?oauth_consumer_key=testkey&loc=MPLS&format=json",
|
17
17
|
@caruby2go.send(:build_uri, 'endpt')
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_build_uri_without_location
|
21
21
|
@caruby2go = Caruby2go.new('testkey')
|
22
|
-
assert_equal
|
22
|
+
assert_equal "#{@caruby2go.send(:uri)}/endpt?oauth_consumer_key=testkey&format=json",
|
23
23
|
@caruby2go.send(:build_uri, 'endpt')
|
24
24
|
end
|
25
25
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Ebbesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|