bikes 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.txt +18 -6
- data/README.md +14 -1
- data/lib/bikes.rb +18 -4
- data/lib/cache.rb +26 -0
- data/test/helpers.rb +3 -0
- data/test/test_bikes.rb +14 -14
- metadata +67 -34
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -1
- data/.travis.yml +0 -5
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -59
- data/Rakefile +0 -9
- data/bikes.gemspec +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7038ea6b3359ed8d9f1fd66e82d2a2cca541918e0291bec8391b4447c82e84d
|
4
|
+
data.tar.gz: 7bad3cd622c5b118fed44bfa1a3265891620f725b70a683afe79ae33a3fc3683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b9fba647be12e42455cfe0299bf4dcc8a46e7f763878024fc1bedcb7feb65b61717b8a9c3db5c3d3de41b873d77ddd54e1b53c868a4b574d7df06f5d42e41e0
|
7
|
+
data.tar.gz: c5fa9a7116f8b82c9eee5bddfd5207b7202bcee5a4e2da54abb6ab25c20b9987a8fa1a3f8977ae7cae9b43227a683a5a062789c938fd6fe6a3f199d7bac33e8e
|
data/LICENSE.txt
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
-
Copyright (c) 2014, Oisin Hurley
|
2
|
-
All rights reserved.
|
1
|
+
Copyright (c) 2014, Oisin Hurley. All rights reserved.
|
3
2
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification,
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
4
|
+
are permitted provided that the following conditions are met:
|
5
5
|
|
6
|
-
Redistributions of source code must retain the above copyright notice, this list
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list
|
7
|
+
of conditions and the following disclaimer.
|
7
8
|
|
8
|
-
Redistributions in binary form must reproduce the above copyright notice, this
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer in the documentation and/or other
|
11
|
+
materials provided with the distribution.
|
9
12
|
|
10
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
18
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
19
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
20
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
21
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
22
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### v0.0.
|
1
|
+
### v0.0.3 - simple wrapper for HTTP invocations
|
2
2
|
|
3
3
|
Wraps the results from the web service at [JC Decaux](https://developer.jcdecaux.com/#/opendata/vls?page=getstarted) in `Hashie::Mash` objects for ease of access.
|
4
4
|
|
@@ -34,3 +34,16 @@ Get an array of all the 'contracts' that are deployed - each contract refers to
|
|
34
34
|
```
|
35
35
|
b.contracts
|
36
36
|
```
|
37
|
+
|
38
|
+
**Testing**
|
39
|
+
|
40
|
+
Local testing happens using Webmock. To run the tests
|
41
|
+
|
42
|
+
```
|
43
|
+
git clone https://github.com/oisin/bikes.git
|
44
|
+
cd bikes
|
45
|
+
bundle install
|
46
|
+
bundle exec rake
|
47
|
+
```
|
48
|
+
|
49
|
+
Coverage is supplied courtesy of SimpleCov, and can be found in the `coverage` directory after a successful test run.
|
data/lib/bikes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'hashie'
|
3
|
+
require_relative 'cache'
|
3
4
|
|
4
5
|
class BikesOffline < Exception; end
|
5
6
|
|
@@ -12,18 +13,31 @@ class Bikes
|
|
12
13
|
def initialize(apikey, scheme)
|
13
14
|
@api = apikey
|
14
15
|
@scheme = scheme
|
16
|
+
# Contracts refresh daily
|
17
|
+
@contracts_cache = Cache.new(self, :contracts_fetch)
|
18
|
+
|
19
|
+
# Full stations list refresh every 60 seconds
|
20
|
+
@stations_cache = Cache.new(self, :stations_fetch, 60)
|
15
21
|
end
|
16
22
|
|
17
|
-
def
|
18
|
-
invoke(STATIONS_URL, {
|
23
|
+
def station(num)
|
24
|
+
invoke(STATIONS_URL + '/' + num.to_s, {contract: @scheme})
|
19
25
|
end
|
20
26
|
|
21
27
|
def contracts
|
28
|
+
@contracts_cache.contents
|
29
|
+
end
|
30
|
+
|
31
|
+
def contracts_fetch
|
22
32
|
invoke(CONTRACTS_URL)
|
23
33
|
end
|
24
34
|
|
25
|
-
def
|
26
|
-
|
35
|
+
def stations
|
36
|
+
@stations_cache.contents
|
37
|
+
end
|
38
|
+
|
39
|
+
def stations_fetch
|
40
|
+
invoke(STATIONS_URL, { contract: @scheme })
|
27
41
|
end
|
28
42
|
|
29
43
|
private
|
data/lib/cache.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class Cache
|
2
|
+
|
3
|
+
def initialize(source, fetchm, exp=86400)
|
4
|
+
@expiry = exp
|
5
|
+
@timestamp = 0
|
6
|
+
@contents = []
|
7
|
+
@source = source
|
8
|
+
@fetch = fetchm
|
9
|
+
end
|
10
|
+
|
11
|
+
def contents
|
12
|
+
if expired?
|
13
|
+
put(@source.send(@fetch))
|
14
|
+
end
|
15
|
+
@contents
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(stuff)
|
19
|
+
@timestamp = Time.now.utc.to_i
|
20
|
+
@contents = stuff
|
21
|
+
end
|
22
|
+
|
23
|
+
def expired?
|
24
|
+
(Time.now.utc.to_i - @timestamp) > @expiry
|
25
|
+
end
|
26
|
+
end
|
data/test/helpers.rb
CHANGED
data/test/test_bikes.rb
CHANGED
@@ -18,25 +18,25 @@ class TestBikes < Minitest::Spec
|
|
18
18
|
|
19
19
|
b = @bikes.contracts
|
20
20
|
|
21
|
-
b.size.must_equal 4
|
21
|
+
_(b.size).must_equal 4
|
22
22
|
|
23
|
-
b[1].name.must_equal 'Dublin'
|
24
|
-
b[1].cities[0].must_equal 'Dublin'
|
25
|
-
b[1].country_code.must_equal 'IE'
|
26
|
-
b[1].commercial_name.must_equal 'dublinbikes'
|
23
|
+
_(b[1].name).must_equal 'Dublin'
|
24
|
+
_(b[1].cities[0]).must_equal 'Dublin'
|
25
|
+
_(b[1].country_code).must_equal 'IE'
|
26
|
+
_(b[1].commercial_name).must_equal 'dublinbikes'
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_stations
|
30
30
|
stub_request(:get, STATIONS_URL).with(query: { apiKey: API_KEY, contract: 'Dublin'}).to_return({body: @stations.read})
|
31
31
|
s = @bikes.stations
|
32
32
|
|
33
|
-
s.size.must_equal 3
|
34
|
-
s[2].number.must_equal 32
|
35
|
-
s[2].name.must_equal "PEARSE STREET"
|
36
|
-
s[2].address.must_equal "Pearse Street"
|
37
|
-
s[2].bike_stands.must_equal 30
|
38
|
-
s[2].available_bike_stands.must_equal 2
|
39
|
-
s[2].available_bikes.must_equal 27
|
33
|
+
_(s.size).must_equal 3
|
34
|
+
_(s[2].number).must_equal 32
|
35
|
+
_(s[2].name).must_equal "PEARSE STREET"
|
36
|
+
_(s[2].address).must_equal "Pearse Street"
|
37
|
+
_(s[2].bike_stands).must_equal 30
|
38
|
+
_(s[2].available_bike_stands).must_equal 2
|
39
|
+
_(s[2].available_bikes).must_equal 27
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_station
|
@@ -46,8 +46,8 @@ class TestBikes < Minitest::Spec
|
|
46
46
|
|
47
47
|
s = @bikes.station(snum)
|
48
48
|
|
49
|
-
s.wont_be_nil
|
50
|
-
s.number.must_equal snum
|
49
|
+
_(s).wont_be_nil
|
50
|
+
_(s.number).must_equal snum
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_bad_thing_happen
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bikes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oisin Hurley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.18'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.13.1
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
29
|
+
version: '0.18'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.13.1
|
@@ -36,106 +36,140 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '2.5'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 2.5.1
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '2.5'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 2.5.1
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: hashie
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '4.1'
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 4.1.0
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '4.1'
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
72
|
+
version: 4.1.0
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: webmock
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
79
|
+
version: '3.13'
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.13.0
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.13'
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
92
|
+
version: 3.13.0
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: minitest
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: '5.
|
99
|
+
version: '5.14'
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 5.
|
102
|
+
version: 5.14.4
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '5.
|
109
|
+
version: '5.14'
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 5.
|
112
|
+
version: 5.14.4
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: simplecov
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0.21'
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.21.2
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0.21'
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.21.2
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rake
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '13.0'
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 13.0.6
|
143
|
+
type: :development
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '13.0'
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 13.0.6
|
113
153
|
description: Ruby client for JCDecaux urban bike rental schemes
|
114
154
|
email: oisin@nis.io
|
115
155
|
executables: []
|
116
156
|
extensions: []
|
117
157
|
extra_rdoc_files: []
|
118
158
|
files:
|
119
|
-
- ".coveralls.yml"
|
120
|
-
- ".gitignore"
|
121
|
-
- ".travis.yml"
|
122
|
-
- Gemfile
|
123
|
-
- Gemfile.lock
|
124
159
|
- LICENSE.txt
|
125
160
|
- README.md
|
126
|
-
- Rakefile
|
127
|
-
- bikes.gemspec
|
128
161
|
- lib/bikes.rb
|
162
|
+
- lib/cache.rb
|
129
163
|
- test/data/contracts.json
|
130
164
|
- test/data/station32.json
|
131
165
|
- test/data/stations.json
|
132
166
|
- test/helpers.rb
|
133
167
|
- test/test_bikes.rb
|
134
|
-
homepage:
|
168
|
+
homepage: https://rubygems.org/gems/bikes
|
135
169
|
licenses:
|
136
|
-
- BSD
|
170
|
+
- BSD-2-Clause
|
137
171
|
metadata: {}
|
138
|
-
post_install_message:
|
172
|
+
post_install_message:
|
139
173
|
rdoc_options: []
|
140
174
|
require_paths:
|
141
175
|
- lib
|
@@ -150,9 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
184
|
- !ruby/object:Gem::Version
|
151
185
|
version: '0'
|
152
186
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
187
|
+
rubygems_version: 3.2.22
|
188
|
+
signing_key:
|
156
189
|
specification_version: 4
|
157
190
|
summary: JCDecaux Bikes Client
|
158
191
|
test_files: []
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
service: travis_ci
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
coverage
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bikes (0.0.1)
|
5
|
-
hashie (~> 2.1, >= 2.1.2)
|
6
|
-
httparty (~> 0.13, >= 0.13.1)
|
7
|
-
json (~> 1.8, >= 1.8.1)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
addressable (2.3.6)
|
13
|
-
coveralls (0.7.1)
|
14
|
-
multi_json (~> 1.3)
|
15
|
-
rest-client
|
16
|
-
simplecov (>= 0.7)
|
17
|
-
term-ansicolor
|
18
|
-
thor
|
19
|
-
crack (0.4.2)
|
20
|
-
safe_yaml (~> 1.0.0)
|
21
|
-
docile (1.1.5)
|
22
|
-
hashie (2.1.2)
|
23
|
-
httparty (0.13.1)
|
24
|
-
json (~> 1.8)
|
25
|
-
multi_xml (>= 0.5.2)
|
26
|
-
json (1.8.1)
|
27
|
-
mime-types (2.4.1)
|
28
|
-
minitest (5.3.5)
|
29
|
-
multi_json (1.10.1)
|
30
|
-
multi_xml (0.5.5)
|
31
|
-
netrc (0.7.7)
|
32
|
-
rake (10.3.2)
|
33
|
-
rest-client (1.7.2)
|
34
|
-
mime-types (>= 1.16, < 3.0)
|
35
|
-
netrc (~> 0.7)
|
36
|
-
safe_yaml (1.0.3)
|
37
|
-
simplecov (0.9.1)
|
38
|
-
docile (~> 1.1.0)
|
39
|
-
multi_json (~> 1.0)
|
40
|
-
simplecov-html (~> 0.8.0)
|
41
|
-
simplecov-html (0.8.0)
|
42
|
-
term-ansicolor (1.3.0)
|
43
|
-
tins (~> 1.0)
|
44
|
-
thor (0.19.1)
|
45
|
-
tins (1.3.3)
|
46
|
-
webmock (1.19.0)
|
47
|
-
addressable (>= 2.3.6)
|
48
|
-
crack (>= 0.3.2)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
ruby
|
52
|
-
|
53
|
-
DEPENDENCIES
|
54
|
-
bikes!
|
55
|
-
coveralls (~> 0.7, >= 0.7.1)
|
56
|
-
minitest (~> 5.3, >= 5.3.5)
|
57
|
-
rake
|
58
|
-
simplecov (~> 0.9, >= 0.9.1)
|
59
|
-
webmock (~> 1.19, >= 1.19.0)
|
data/Rakefile
DELETED
data/bikes.gemspec
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = 'bikes'
|
5
|
-
s.version = '0.0.2'
|
6
|
-
s.date = Date.today.to_s
|
7
|
-
s.license = 'BSD'
|
8
|
-
s.summary = "JCDecaux Bikes Client"
|
9
|
-
s.description = "Ruby client for JCDecaux urban bike rental schemes"
|
10
|
-
s.authors = ["Oisin Hurley"]
|
11
|
-
s.email = 'oisin@nis.io'
|
12
|
-
s.files = `git ls-files`.split("\n")
|
13
|
-
s.homepage = 'http://rubygems.org/gems/bikes'
|
14
|
-
s.add_runtime_dependency 'httparty', '~> 0.13', '>= 0.13.1'
|
15
|
-
s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.1'
|
16
|
-
s.add_runtime_dependency 'hashie', '~> 2.1', '>= 2.1.2'
|
17
|
-
s.add_development_dependency 'webmock', '~> 1.19', '>= 1.19.0'
|
18
|
-
s.add_development_dependency 'minitest', '~> 5.3', '>= 5.3.5'
|
19
|
-
end
|