tankerkoenig 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 +13 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tankerkoenig.rb +30 -0
- data/lib/tankerkoenig/opening_time.rb +11 -0
- data/lib/tankerkoenig/price.rb +76 -0
- data/lib/tankerkoenig/response.rb +32 -0
- data/lib/tankerkoenig/station.rb +120 -0
- data/lib/tankerkoenig/version.rb +3 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/tankerkoenig_spec.rb +86 -0
- data/tankerkoenig.gemspec +28 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 66370d28f1df625f4d9bf689bbe1e2add4960453a15d1a2d5483f75e3349ff46
|
4
|
+
data.tar.gz: 73d064a94b5407d93521f0e0221fd8c021f4e0c41d0d3bdca8c05f5bf3d7a4fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b04a1fd0ebabc1cfcd77ec43e2f454edf27a03401238e7d362795bb9a812e0dfaae0bc96bdcf4a903d52f2147e20571c5abf22791a892f2fc81ce597094c87b
|
7
|
+
data.tar.gz: bc84511723177438f187156ab557339f40e839e57a1e9b9a5d39132d9b9507c79b5c828a79ab65a872e933ea724f0060005f5ce7901b7aff4edb9e8fa0258e1d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.5.0
|
5
|
+
before_install: gem install bundler -v 1.16.1
|
6
|
+
env:
|
7
|
+
global:
|
8
|
+
secure: A59RFXDob3tLwj4h0HH+Nj9EQRW8kRE0QyDCFWSdazr3uudLz000rCVpgzuzK1DbrT1R8lHCwxKcnzyQHOEWTyV0kCd2I0CEU2ri4TAgNlJyvCfHEaW7CcSKFUILEpM3FQKxFgGAE0j/a0UITKhrdxErH6yP/PGMSZLIQ9lMvWGhAGtj8vS/qtWjW1ckZ/jEYZS8MM1VUKw20ToNwsMW63OAHax1hbow/29x/G/1WE2be366CNI2r/eqnhazVfoJ0l2nOdbMNwOdy1aq0Qzqr82NpleRAM/E0hSjTOh1opDA4ZoMbSQP34Oyy9jaaeM3oazAX4QdfWziD9+6zuLFOEP5UEpSosxG6QQmk9KwAUIg9JFd45GqZ/dIOu0SSfTvcCTIS0FMthRkLLpg+p4/ZRu8vCvSSc/zxE2dMrBWjmrHGPk31TUolZ8RoeKBakvc1i2073l5qXcm0ISyShgMlMKSvLB7s5kpzxRf2UpfAbM+aFggY35SzYX4T5mNtw7B26Co1Onhn3Q/x32YgJyYusSSXC5ZkRLHYsSLQNCYNh4F3Ze87BL0Z/77GpFU4/hXPsYe+XfiPXmjKai/ggLoz+ysINu44Ue30cJCXQSObBLVHoQh1gcdehnmm3MXGnDTeLpxexdVovEATJ6FlK95yyB529jt+TaqQ2eGNSuHYzM=
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Marco Roth
|
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,118 @@
|
|
1
|
+
# Tankerkoenig
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
This is a Ruby Wrapper for the [Tankerkönig HTTP API](https://creativecommons.tankerkoenig.de).
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'tankerkoenig'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install tankerkoenig
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Set the API Token
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Tankerkoenig.api_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
30
|
+
```
|
31
|
+
|
32
|
+
Get the detail of a single station
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Tankerkoenig::Station.detail('24a381e3-0d72-416d-bfd8-b2f65f6e5802')
|
36
|
+
# => #<Tankerkoenig::Response @ok=true @result=#<Tankerkoenig::Station [...]> [...]>
|
37
|
+
```
|
38
|
+
|
39
|
+
Search stations in the radius of the given coordinates.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Tankerkoenig::Station.list(lat: 52.521, lng: 13.438, rad: 1.5, type: :all, sort: :dist)
|
43
|
+
# => #<Tankerkoenig::Response @ok=true @result=[#<Tankerkoenig::Station [...]>, #<Tankerkoenig::Station [...]>] [...]>
|
44
|
+
```
|
45
|
+
|
46
|
+
Get the prices of a list of stations
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Tankerkoenig::Price.get(['4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8', '446bdcf5-9f75-47fc-9cfa-2c3d6fda1c3b', '60c0eefa-d2a8-4f5c-82cc-b5244ecae955', '44444444-4444-4444-4444-444444444444'])
|
50
|
+
# or
|
51
|
+
Tankerkoenig::Price.get('4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8,446bdcf5-9f75-47fc-9cfa-2c3d6fda1c3b,60c0eefa-d2a8-4f5c-82cc-b5244ecae955,44444444-4444-4444-4444-444444444444')
|
52
|
+
|
53
|
+
# => #<Tankerkoenig::Response @ok=true @result=[#<Tankerkoenig::Price [...]>, #<Tankerkoenig::Price [...]>] [...]>
|
54
|
+
```
|
55
|
+
|
56
|
+
Interacting with the `Tankerkoenig::Station` class.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
stations = Tankerkoenig::Station.list(lat: 52.521, lng: 13.438, rad: 1.5, type: :all, sort: :dist).result
|
60
|
+
station = stations.first
|
61
|
+
|
62
|
+
station.brand
|
63
|
+
# => "TOTAL"
|
64
|
+
|
65
|
+
station.street
|
66
|
+
# => "MARGARETE-SOMMER-STR"
|
67
|
+
|
68
|
+
station.place
|
69
|
+
# => "BERLIN"
|
70
|
+
|
71
|
+
station.e5?
|
72
|
+
# => true
|
73
|
+
|
74
|
+
station.e5
|
75
|
+
# => 1.499
|
76
|
+
|
77
|
+
station.e10?
|
78
|
+
# => true
|
79
|
+
|
80
|
+
station.e10
|
81
|
+
# => 1.479
|
82
|
+
|
83
|
+
station.diesel?
|
84
|
+
# => true
|
85
|
+
|
86
|
+
station.diesel
|
87
|
+
# => 1.309
|
88
|
+
|
89
|
+
station.open?
|
90
|
+
# => true
|
91
|
+
|
92
|
+
station.whole_day?
|
93
|
+
# => false
|
94
|
+
```
|
95
|
+
|
96
|
+
## Development
|
97
|
+
|
98
|
+
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.
|
99
|
+
|
100
|
+
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).
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/tankerkoenig-ruby.
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
109
|
+
|
110
|
+
## More Information
|
111
|
+
|
112
|
+
[Tankerkoenig Website](https://tankerkoenig.de)
|
113
|
+
|
114
|
+
[Tankerkoenig HTTP API](https://creativecommons.tankerkoenig.de)
|
115
|
+
|
116
|
+
[RubyGems](https://rubygems.org/gems/tankerkoenig)
|
117
|
+
|
118
|
+
[Source Code](https://github.com/marcoroth/tankerkoenig-ruby)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tankerkoenig"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/tankerkoenig.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "tankerkoenig/version"
|
2
|
+
require "tankerkoenig/response"
|
3
|
+
require "tankerkoenig/station"
|
4
|
+
require "tankerkoenig/price"
|
5
|
+
require "tankerkoenig/opening_time"
|
6
|
+
|
7
|
+
module Tankerkoenig
|
8
|
+
@api_base = 'https://creativecommons.tankerkoenig.de/json'
|
9
|
+
@api_key = ENV['TANKERKOENIG_API_KEY'] || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :api_key, :api_base
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.conn
|
16
|
+
if defined?(@conn)
|
17
|
+
@conn
|
18
|
+
else
|
19
|
+
@conn = Faraday.new(@api_base) do |faraday|
|
20
|
+
faraday.params['apikey'] = @api_key
|
21
|
+
faraday.adapter Faraday.default_adapter
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.conn=(conn)
|
27
|
+
@conn = conn
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Tankerkoenig
|
5
|
+
class Price
|
6
|
+
attr_reader :station_id, :status, :e5, :e10, :diesel
|
7
|
+
|
8
|
+
def initialize(*attributes)
|
9
|
+
if attributes.count == 2
|
10
|
+
@station_id = attributes[0]
|
11
|
+
@status = attributes[1][:status]
|
12
|
+
@e5 = attributes[1][:e5]
|
13
|
+
@e10 = attributes[1][:e10]
|
14
|
+
@diesel = attributes[1][:diesel]
|
15
|
+
end
|
16
|
+
|
17
|
+
if attributes.count == 5
|
18
|
+
@station_id = attributes[0]
|
19
|
+
@e5 = attributes[1]
|
20
|
+
@e10 = attributes[2]
|
21
|
+
@diesel = attributes[3]
|
22
|
+
@status = attributes[4] ? 'open' : 'closed'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get(ids)
|
27
|
+
ids = ids.join(',') if ids.is_a?(Array)
|
28
|
+
return Response.new(message: 'ids must be an Array or a String') unless ids.is_a?(String)
|
29
|
+
|
30
|
+
response = conn.get('prices.php', ids: ids)
|
31
|
+
attributes = JSON.parse(response.body, symbolize_names: true)
|
32
|
+
response = Response.new(attributes)
|
33
|
+
response.result = []
|
34
|
+
|
35
|
+
if response.success?
|
36
|
+
attributes[:prices].to_a.each do |p|
|
37
|
+
response.result << new(p.first, p.last)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.conn
|
45
|
+
Tankerkoenig.conn
|
46
|
+
end
|
47
|
+
|
48
|
+
def station
|
49
|
+
Station.detail(@station_id).result
|
50
|
+
end
|
51
|
+
|
52
|
+
def open?
|
53
|
+
@status == 'open'
|
54
|
+
end
|
55
|
+
|
56
|
+
def closed?
|
57
|
+
@status == 'closed'
|
58
|
+
end
|
59
|
+
|
60
|
+
def prices?
|
61
|
+
@status != 'no prices' && !@e5.nil? && !@e10.nil? && !@diesel.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def e5?
|
65
|
+
@e5 != false
|
66
|
+
end
|
67
|
+
|
68
|
+
def e10?
|
69
|
+
@e10 != false
|
70
|
+
end
|
71
|
+
|
72
|
+
def diesel?
|
73
|
+
@diesel != false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Tankerkoenig
|
2
|
+
class Response
|
3
|
+
attr_reader :ok, :license, :data, :status, :message
|
4
|
+
attr_accessor :result
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@ok = !attributes[:ok].nil? ? attributes[:ok] : false
|
8
|
+
@license = attributes[:license] || ''
|
9
|
+
@data = attributes[:data] || ''
|
10
|
+
@status = attributes[:status] || ''
|
11
|
+
if @ok
|
12
|
+
@message = attributes[:message] || ''
|
13
|
+
else
|
14
|
+
@message = attributes[:message] || 'an error occured'
|
15
|
+
end
|
16
|
+
@result = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
@ok
|
21
|
+
end
|
22
|
+
|
23
|
+
def error?
|
24
|
+
!@ok
|
25
|
+
end
|
26
|
+
|
27
|
+
def any?
|
28
|
+
@result != [] && @result != nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Tankerkoenig
|
5
|
+
class Station
|
6
|
+
attr_reader :id, :name, :brand, :street, :house_number, :post_code, :place
|
7
|
+
attr_reader :price, :opening_times, :overrides, :whole_day, :is_open
|
8
|
+
attr_reader :lat, :lng, :state
|
9
|
+
|
10
|
+
def initialize(station)
|
11
|
+
return if station.nil?
|
12
|
+
|
13
|
+
@id = station[:id]
|
14
|
+
@name = station[:name]
|
15
|
+
@brand = station[:brand]
|
16
|
+
@street = station[:street]
|
17
|
+
@house_humber = station[:houseNumber]
|
18
|
+
@post_code = station[:postCode]
|
19
|
+
@place = station[:place]
|
20
|
+
@opening_times = []
|
21
|
+
@overrides = station[:overrides]
|
22
|
+
@whole_day = station[:wholeDay]
|
23
|
+
@is_open = station[:isOpen]
|
24
|
+
@lat = station[:lat]
|
25
|
+
@lng = station[:lng]
|
26
|
+
@state = station[:state]
|
27
|
+
@price = Price.new(@id, station[:e5], station[:e10], station[:diesel], @is_open)
|
28
|
+
|
29
|
+
open_times = station[:openingTimes] || []
|
30
|
+
|
31
|
+
open_times.each do |opening_time|
|
32
|
+
@opening_times << OpeningTime.new(opening_time)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.detail(id)
|
37
|
+
return Response.new(message: 'you have to submit a valid station id') if id.nil? || id.empty?
|
38
|
+
|
39
|
+
response = conn.get('detail.php', id: id)
|
40
|
+
attributes = JSON.parse(response.body, symbolize_names: true)
|
41
|
+
response = Response.new(attributes)
|
42
|
+
response.result = Station.new(attributes[:station])
|
43
|
+
response
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.list(lat: nil, lng: nil, rad: 1, type: nil, sort: nil)
|
47
|
+
type_options = %w[e5 e10 diesel all]
|
48
|
+
sort_options = %w[price dist]
|
49
|
+
|
50
|
+
return Response.new(message: 'you need to submit a valid lat coordinate') if lat.nil?
|
51
|
+
return Response.new(message: 'you need to submit a valid lng coordinate') if lng.nil?
|
52
|
+
return Response.new(message: 'you need to submit a valid radius between 1 and 25') if rad.nil? || rad.to_f >= 25 || rad.to_f < 1
|
53
|
+
|
54
|
+
if sort.nil? && type.nil?
|
55
|
+
type = :all
|
56
|
+
else
|
57
|
+
return Response.new(message: "wrong type parameter. The available options are #{type_options}") unless type_options.include?(type.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
return Response.new(message: "wrong sort parameter. The available options are #{sort_options}") unless sort_options.include?(sort.to_s)
|
61
|
+
|
62
|
+
response = conn.get('list.php', lat: lat, lng: lng, rad: rad, type: type, sort: sort)
|
63
|
+
attributes = JSON.parse(response.body, symbolize_names: true)
|
64
|
+
response = Response.new(attributes)
|
65
|
+
response.result = []
|
66
|
+
|
67
|
+
if response.success?
|
68
|
+
attributes[:stations].each do |station|
|
69
|
+
response.result << Station.new(station)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
response
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.conn
|
77
|
+
Tankerkoenig.conn
|
78
|
+
end
|
79
|
+
|
80
|
+
def detail
|
81
|
+
Station.detail(@id).result
|
82
|
+
end
|
83
|
+
|
84
|
+
def open?
|
85
|
+
@is_open
|
86
|
+
end
|
87
|
+
|
88
|
+
def closed?
|
89
|
+
!@is_open
|
90
|
+
end
|
91
|
+
|
92
|
+
def whole_day?
|
93
|
+
@whole_day
|
94
|
+
end
|
95
|
+
|
96
|
+
def e5
|
97
|
+
@price.e5
|
98
|
+
end
|
99
|
+
|
100
|
+
def e10
|
101
|
+
@price.e10
|
102
|
+
end
|
103
|
+
|
104
|
+
def diesel
|
105
|
+
@price.diesel
|
106
|
+
end
|
107
|
+
|
108
|
+
def e5?
|
109
|
+
!e5.nil? && e5.class == Float
|
110
|
+
end
|
111
|
+
|
112
|
+
def e10?
|
113
|
+
!e10.nil? && e10.class == Float
|
114
|
+
end
|
115
|
+
|
116
|
+
def diesel?
|
117
|
+
!diesel.nil? && diesel.class == Float
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "tankerkoenig"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
RSpec.describe Tankerkoenig do
|
2
|
+
|
3
|
+
it 'has a version number' do
|
4
|
+
expect(Tankerkoenig::VERSION).not_to be(nil)
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'has an api_base' do
|
8
|
+
expect(Tankerkoenig.api_base).not_to be(nil)
|
9
|
+
expect(Tankerkoenig.api_base).not_to be('')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has an api_key' do
|
13
|
+
expect(Tankerkoenig.api_key).not_to be(nil)
|
14
|
+
expect(Tankerkoenig.api_key).not_to be('')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns stations from Station#list' do
|
18
|
+
lat = 52.521
|
19
|
+
lng = 13.438
|
20
|
+
rad = 1.5
|
21
|
+
sort = :dist
|
22
|
+
response = Tankerkoenig::Station.list(lat: lat, lng: lng, rad: rad, sort: sort, type: :all)
|
23
|
+
expect(response.any?).to eq(true)
|
24
|
+
response = Tankerkoenig::Station.list(lat: lat, lng: lng, rad: rad, sort: sort, type: :e5)
|
25
|
+
expect(response.any?).to eq(true)
|
26
|
+
response = Tankerkoenig::Station.list(lat: lat, lng: lng, rad: rad, sort: sort, type: :e10)
|
27
|
+
expect(response.any?).to eq(true)
|
28
|
+
response = Tankerkoenig::Station.list(lat: lat, lng: lng, rad: rad, sort: sort, type: :diesel)
|
29
|
+
expect(response.any?).to eq(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a station detail from Station#detail' do
|
33
|
+
id = '24a381e3-0d72-416d-bfd8-b2f65f6e5802'
|
34
|
+
response = Tankerkoenig::Station.detail(id)
|
35
|
+
expect(response.success?).to eq(true)
|
36
|
+
expect(response.status).not_to be('error')
|
37
|
+
expect(response.message).to eq('')
|
38
|
+
expect(response.any?).to eq(true)
|
39
|
+
expect(response.result.id == id)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns a list of stations by ids from Price#get' do
|
43
|
+
ids = ['4429a7d9-fb2d-4c29-8cfe-2ca90323f9f8', '446bdcf5-9f75-47fc-9cfa-2c3d6fda1c3b', '60c0eefa-d2a8-4f5c-82cc-b5244ecae955', '44444444-4444-4444-4444-444444444444']
|
44
|
+
response = Tankerkoenig::Price.get(ids)
|
45
|
+
expect(response.success?).to eq(true)
|
46
|
+
expect(response.status).not_to be('error')
|
47
|
+
expect(response.message).to eq('')
|
48
|
+
expect(response.any?).to eq(true)
|
49
|
+
expect(response.result.first.station_id == ids.first)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns errors from Station#list' do
|
53
|
+
response = Tankerkoenig::Station.list(lat: nil, lng: nil, rad: nil, sort: nil, type: :all)
|
54
|
+
expect(response.any?).to eq(false)
|
55
|
+
expect(response.message).to eq('you need to submit a valid lat coordinate')
|
56
|
+
|
57
|
+
response = Tankerkoenig::Station.list(lat: 52.521, lng: nil, rad: nil, sort: nil, type: :all)
|
58
|
+
expect(response.any?).to eq(false)
|
59
|
+
expect(response.message).to eq('you need to submit a valid lng coordinate')
|
60
|
+
|
61
|
+
response = Tankerkoenig::Station.list(lat: 52.521, lng: 13.438, rad: nil, sort: nil, type: :all)
|
62
|
+
expect(response.any?).to eq(false)
|
63
|
+
expect(response.message).to eq('you need to submit a valid radius between 1 and 25')
|
64
|
+
|
65
|
+
response = Tankerkoenig::Station.list(lat: 52.521, lng: 13.438, rad: 1.5, sort: nil, type: :all)
|
66
|
+
expect(response.any?).to eq(false)
|
67
|
+
expect(response.message).to eq('wrong sort parameter. The available options are ["price", "dist"]')
|
68
|
+
|
69
|
+
response = Tankerkoenig::Station.list(lat: 52.521, lng: 13.438, rad: 1.5, sort: :dist, type: :abc)
|
70
|
+
expect(response.any?).to eq(false)
|
71
|
+
expect(response.message).to eq('wrong type parameter. The available options are ["e5", "e10", "diesel", "all"]')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns an error from Station#detail' do
|
75
|
+
response = Tankerkoenig::Station.detail(nil)
|
76
|
+
expect(response.any?).to eq(false)
|
77
|
+
expect(response.message).to eq('you have to submit a valid station id')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns an error from Price#get' do
|
81
|
+
response = Tankerkoenig::Price.get(nil)
|
82
|
+
expect(response.any?).to eq(false)
|
83
|
+
expect(response.message).to eq('ids must be an Array or a String')
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "tankerkoenig/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tankerkoenig"
|
8
|
+
spec.version = Tankerkoenig::VERSION
|
9
|
+
spec.authors = ["Marco Roth"]
|
10
|
+
spec.email = ["marco.roth@intergga.ch"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby Wrapper for the Tankerkoenig HTTP API"
|
13
|
+
spec.description = "Ruby Wrapper for the Tankerkoenig HTTP API"
|
14
|
+
spec.homepage = "https://github.com/marcoroth/tankerkoenig-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_dependency "faraday"
|
27
|
+
spec.add_dependency "json"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tankerkoenig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Roth
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-24 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby Wrapper for the Tankerkoenig HTTP API
|
84
|
+
email:
|
85
|
+
- marco.roth@intergga.ch
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/tankerkoenig.rb
|
100
|
+
- lib/tankerkoenig/opening_time.rb
|
101
|
+
- lib/tankerkoenig/price.rb
|
102
|
+
- lib/tankerkoenig/response.rb
|
103
|
+
- lib/tankerkoenig/station.rb
|
104
|
+
- lib/tankerkoenig/version.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/tankerkoenig_spec.rb
|
107
|
+
- tankerkoenig.gemspec
|
108
|
+
homepage: https://github.com/marcoroth/tankerkoenig-ruby
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.7.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Ruby Wrapper for the Tankerkoenig HTTP API
|
132
|
+
test_files: []
|