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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9d8f3553cff2a26e8158534f0c9b8f0dfec95b1
4
- data.tar.gz: cdadd90cbddbf5dc632f6048dd4dac845e75e2bf
3
+ metadata.gz: ad0725cbc7907bfcb303396fb89ce0d9f93de48f
4
+ data.tar.gz: bceac7b4db47cc3051e3c01a1a3e583bd9f81380
5
5
  SHA512:
6
- metadata.gz: 29b118da409b2f32432672762889d293948e4be92a4d2a4b2d73cb54f372975720bc917ec06b95a2feccd0a31ad7076f44bc9afd5db30be28daebd291b1b7cc1
7
- data.tar.gz: ddc779599342762cb7e78c6405de4e1e233e74934ecda9d148b9bfffe5638435cec179974827bca2540b27b1460de10f7f9c53faa6a6ce55f580a1f176b359ae
6
+ metadata.gz: 45ab691d369f0a373a53e04b56872b0c9b677a133400d76c3e304294ac176e7a8bece40f10473801dca61674881323258a1af63f310a4b88ea04dfd0db811100
7
+ data.tar.gz: eaa3dba26f5add897b677cc2f002ec56bf217974b29a68abd0c43264a3e2e13b76f17fad8acd5a9c49796c9db2cabd44b966b3fa8e53cb5448700386a261adaa
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- caruby2go (0.0.4)
4
+ caruby2go (0.1.0)
5
5
  thor (~> 0.19.1)
6
6
 
7
7
  GEM
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
- ## Local usage
32
- The script requires you to set the `CONSUMER_KEY` environment variable to your car2go consumer key
31
+ ## Publishing
33
32
 
34
- $ set CONSUMER_KEY=<your_consumer_key>
35
- $ bin/caruby2go p kobenhavn
36
- or
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
- ## 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.
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
- ## 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.
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
 
@@ -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 = nil)
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
- "#{CAR2GO_URI}/#{endpoint}?oauth_consumer_key=#{@consumer_key}#{loc_part}&format=json"
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
@@ -1,3 +1,3 @@
1
1
  class Caruby2go
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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 'https://www.car2go.com/api/v2.1/endpt?oauth_consumer_key=testkey&loc=MPLS&format=json',
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 'https://www.car2go.com/api/v2.1/endpt?oauth_consumer_key=testkey&format=json',
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
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: 2015-11-21 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor