velov 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/velov/api.rb +12 -0
- data/lib/velov/station.rb +40 -0
- data/lib/velov/station_list.rb +36 -0
- data/lib/velov/version.rb +3 -0
- data/lib/velov.rb +23 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/station_list_spec.rb +13 -0
- data/spec/station_spec.rb +38 -0
- data/spec/vcr_cassettes/fetch_valid_station_list.yml +1463 -0
- data/spec/vcr_cassettes/find_invalid_station_by_number.yml +44 -0
- data/spec/vcr_cassettes/find_valid_station_by_number.yml +48 -0
- data/velov.gemspec +30 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c6bc25fdb5e560786d2f9897ae3d0b4f2797b5f
|
4
|
+
data.tar.gz: a21d8265d840598cc3fbc751d2a1d22991ffa32b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b025bbda3f01363f26e3d6c50929857c05fcedd2865a86a2fc6102cc888a27598cc67d9e1d674bb283d2aee4a5621825738f3b6d6a0ff9027a294ce8fabd6c0
|
7
|
+
data.tar.gz: 956418df4e0ed3e2766f77b1c1e0ec1fd37087bafc39013acfba2bb93cc211f03e5c773efacf174e86f8f8987c0ad8296202eca6291e7404bc47c1de6fc20f21
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pierre-Baptiste Béchu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Velov
|
2
|
+
|
3
|
+
Velov is a ruby wrapper for [Velov API](https://download.data.grandlyon.com/ws/smartdata/jcd_jcdecaux.jcdvelov.json) (Public Bike Sharing System of Lyon, France). This Wrapper allows you to play with objects like bike's stations ! It's possible to add more features in the future, like "nearest station around me".
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'velov'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install velov
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/pbechu/velov/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/velov/api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Velov
|
2
|
+
class API
|
3
|
+
# DRY API Calls
|
4
|
+
def self.get(params = {})
|
5
|
+
connection ||= Faraday.new 'https://download.data.grandlyon.com' do |conn|
|
6
|
+
conn.response :json, :content_type => /\bjson$/
|
7
|
+
conn.adapter Faraday.default_adapter
|
8
|
+
end
|
9
|
+
connection.get "/ws/smartdata/jcd_jcdecaux.jcdvelov/all.json", params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Velov
|
2
|
+
class Station
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :number, Integer
|
6
|
+
attribute :name, String
|
7
|
+
attribute :address, String
|
8
|
+
attribute :address_complement, String
|
9
|
+
attribute :city, String
|
10
|
+
attribute :district_number, Integer
|
11
|
+
attribute :lat, Float
|
12
|
+
attribute :lng, Float
|
13
|
+
attribute :bike_stands, Integer
|
14
|
+
attribute :status, String
|
15
|
+
attribute :available_bike_stands, Integer
|
16
|
+
attribute :available_bikes, Integer
|
17
|
+
attribute :last_update, DateTime
|
18
|
+
|
19
|
+
def initialize(params)
|
20
|
+
@number = params[Velov::NUMBER].to_i
|
21
|
+
@name = params[Velov::NAME]
|
22
|
+
@address = params[Velov::ADDRESS]
|
23
|
+
@address_complement = params[Velov::ADDRESS_COMPLEMENT]
|
24
|
+
@city = params[Velov::CITY]
|
25
|
+
@district_number = params[Velov::DISTRICT_NUMBER].to_i
|
26
|
+
@lat = params[Velov::LATITUDE].to_f
|
27
|
+
@lng = params[Velov::LONGITUDE].to_f
|
28
|
+
@bike_stands = params[Velov::BIKE_STANDS].to_i
|
29
|
+
@status = params[Velov::STATUS]
|
30
|
+
@available_bike_stands = params[Velov::AVAILABLE_BIKE_STANDS].to_i
|
31
|
+
@available_bikes = params[Velov::AVAILABLE_BIKES].to_i
|
32
|
+
@last_update = DateTime.parse(params[Velov::LAST_UPDATE])
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_by_number(number)
|
36
|
+
# nil if not found
|
37
|
+
StationList.fetch({ "field" => "number", "value" => number}).to_a.first
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Velov
|
2
|
+
class StationList
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :size, Integer
|
6
|
+
attribute :list, Array[Station]
|
7
|
+
|
8
|
+
def initialize(size)
|
9
|
+
@size = size
|
10
|
+
@list = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_station(params)
|
14
|
+
@list << Station.new(params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
@list
|
19
|
+
end
|
20
|
+
|
21
|
+
# Fetch data of all stations
|
22
|
+
def self.fetch(params = {})
|
23
|
+
|
24
|
+
response = API.get(params)
|
25
|
+
|
26
|
+
station_list = StationList.new(response.body["nb_results"])
|
27
|
+
|
28
|
+
response.body["values"].each do |station_params|
|
29
|
+
station_list.add_station(station_params)
|
30
|
+
end
|
31
|
+
|
32
|
+
station_list
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/velov.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require "velov/version"
|
5
|
+
require "velov/api"
|
6
|
+
require "velov/station"
|
7
|
+
require "velov/station_list"
|
8
|
+
module Velov
|
9
|
+
# Define API Constants
|
10
|
+
NUMBER = 0
|
11
|
+
NAME = 1
|
12
|
+
ADDRESS = 2
|
13
|
+
ADDRESS_COMPLEMENT = 3
|
14
|
+
CITY = 4
|
15
|
+
DISTRICT_NUMBER = 5
|
16
|
+
LATITUDE = 8
|
17
|
+
LONGITUDE = 9
|
18
|
+
BIKE_STANDS = 10
|
19
|
+
STATUS = 11
|
20
|
+
AVAILABLE_BIKE_STANDS = 12
|
21
|
+
AVAILABLE_BIKES = 13
|
22
|
+
LAST_UPDATE = 18
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Velov::StationList do
|
4
|
+
describe ":fetch" do
|
5
|
+
before(:each) do
|
6
|
+
VCR.use_cassette "fetch_valid_station_list" do
|
7
|
+
@station_list = Velov::StationList.fetch
|
8
|
+
end
|
9
|
+
end
|
10
|
+
it { expect(@station_list.size).to eq 349 }
|
11
|
+
it { expect(@station_list.to_a.length).to eq 349}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Velov::Station do
|
4
|
+
describe ":find_by_number" do
|
5
|
+
context 'valid number' do
|
6
|
+
before(:each) do
|
7
|
+
VCR.use_cassette "find_valid_station_by_number" do
|
8
|
+
@station = Velov::Station.find_by_number(10117)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it { expect(@station.number).to eq 10117}
|
13
|
+
it { expect(@station.name).to eq "La Pérralière"}
|
14
|
+
it { expect(@station.address).to eq "171 rue Léon Blum"}
|
15
|
+
it { expect(@station.address_complement).to eq "None"}
|
16
|
+
it { expect(@station.city).to eq "VILLEURBANNE"}
|
17
|
+
it { expect(@station.district_number).to eq 117}
|
18
|
+
it { expect(@station.lat).to eq 45.7645636665294000}
|
19
|
+
it { expect(@station.lng).to eq 4.8923336071821100}
|
20
|
+
it { expect(@station.bike_stands).to eq 22}
|
21
|
+
it { expect(@station.status).to eq "OPEN"}
|
22
|
+
it { expect(@station.available_bike_stands).to eq 12}
|
23
|
+
it { expect(@station.available_bikes).to eq 10}
|
24
|
+
it { expect(@station.last_update).to eq DateTime.new(2014,8,21,14,50,31) }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'invalid number' do
|
29
|
+
before(:each) do
|
30
|
+
VCR.use_cassette "find_invalid_station_by_number" do
|
31
|
+
@station = Velov::Station.find_by_number(101173456)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it { expect(@station).to be nil}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|