inthegra 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 +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +113 -0
- data/Rakefile +6 -0
- data/bin/setup +8 -0
- data/inthegra.gemspec +29 -0
- data/lib/faraday/inthegra.rb +18 -0
- data/lib/inthegra.rb +27 -0
- data/lib/inthegra/client.rb +32 -0
- data/lib/inthegra/client/bus_stops.rb +49 -0
- data/lib/inthegra/client/lines.rb +35 -0
- data/lib/inthegra/client/vehicles.rb +35 -0
- data/lib/inthegra/configuration.rb +41 -0
- data/lib/inthegra/connection.rb +28 -0
- data/lib/inthegra/error.rb +12 -0
- data/lib/inthegra/model/auth_token.rb +17 -0
- data/lib/inthegra/model/base.rb +14 -0
- data/lib/inthegra/model/bus_stop.rb +29 -0
- data/lib/inthegra/model/line.rb +29 -0
- data/lib/inthegra/model/vehicle.rb +25 -0
- data/lib/inthegra/request.rb +36 -0
- data/lib/inthegra/serializer/base.rb +45 -0
- data/lib/inthegra/serializer/collection.rb +13 -0
- data/lib/inthegra/serializer/vehicles.rb +18 -0
- data/lib/inthegra/version.rb +3 -0
- metadata +172 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0cc840081c44df61d67d768d2442ca6144e65e4b
|
|
4
|
+
data.tar.gz: a4a76a8e281603f75c79867b3d23b231a70ce50e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0a127c98092a04f66022ca598e79d804349da0a8a6b788a1c067e929c019042ccce6ca5ef1028ce7f626deff8f58845294215c7ee31a90adef077503b6bb6a8c
|
|
7
|
+
data.tar.gz: 2bbc6fa9d831356127c1f07955df62a8cd8d76953d0b4542edc5c45c7c6ac21cac1fc3db25063aaf2258cc184f5cddd8da0edfefda2371b6d05b7ae19ed8f399
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Rafael Guimarães
|
|
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,113 @@
|
|
|
1
|
+
# Inthegra
|
|
2
|
+
|
|
3
|
+
Ruby wrapper for the STRANS-PI Inthegra API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'inthegra'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install inthegra
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Require the inthegra gem and add the basic configuration:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require 'inthegra'
|
|
27
|
+
|
|
28
|
+
Inthegra.configure do |config|
|
|
29
|
+
config.email = YOUR_INTHEGRA_EMAIL
|
|
30
|
+
config.password = YOUR_INTHEGRA_PASSWORD
|
|
31
|
+
config.api_key = YOUR_INTHEGRA_API_KEY
|
|
32
|
+
end
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Create a new client instance and authenticate with the API.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
client = Inthegra::Client.new
|
|
39
|
+
|
|
40
|
+
client.authenticate
|
|
41
|
+
```
|
|
42
|
+
Remeber: The inthegra API expires the auth_token after every 10 minutes.
|
|
43
|
+
|
|
44
|
+
Now you can retrieve the API data.
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
client.vehicles
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Get all lines
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
client.lines
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Search line by query string
|
|
57
|
+
|
|
58
|
+
Searching all line with 'ininga' keyword.
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
client.line_search('ininga')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Get all bus stops
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
client.bus_stops
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Search bus stops by query string
|
|
71
|
+
|
|
72
|
+
Searching all bus stops with 'ininga' keyword.
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
client.bus_stops_search('ininga')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Search bus stops by line
|
|
79
|
+
|
|
80
|
+
Searching all bus stops of the 402 line code.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
client.bus_stops_by_line('0402')
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Get vehicles
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
client.vehicles
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Search vehicles by line
|
|
93
|
+
|
|
94
|
+
Searching vehicles of the 402 line code.
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
client.vehicles_by_line('0402')
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
|
103
|
+
|
|
104
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/teresinahc/inthegra.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/inthegra.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'inthegra/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "inthegra"
|
|
8
|
+
spec.version = Inthegra::VERSION
|
|
9
|
+
spec.authors = ["Rafael Guimarães", "Renato Filho"]
|
|
10
|
+
spec.email = ["rafaelguimaraesweb@gmail.com", "renatosousafilho@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Inthegra"
|
|
13
|
+
spec.description = "Ruby wrapper for the STRANS-PI Inthegra API"
|
|
14
|
+
spec.homepage = "https://github.com/teresinahc/inthegra"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
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.12"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
25
|
+
spec.add_development_dependency "simplecov", "~> 0.11.2"
|
|
26
|
+
spec.add_development_dependency "webmock", "~> 2.0.2"
|
|
27
|
+
spec.add_runtime_dependency "faraday", "~> 0.9.2"
|
|
28
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.10.0"
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module FaradayMiddleware
|
|
2
|
+
class Inthegra < Faraday::Middleware
|
|
3
|
+
|
|
4
|
+
def call(env)
|
|
5
|
+
if @auth_token
|
|
6
|
+
env[:request_headers] = env[:request_headers].merge('X-Auth-Token' => @auth_token.token)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
@app.call env
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(app, auth_token = nil)
|
|
13
|
+
@app = app
|
|
14
|
+
@auth_token = auth_token
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/inthegra.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "time"
|
|
2
|
+
require "json/ext"
|
|
3
|
+
require "faraday"
|
|
4
|
+
|
|
5
|
+
require "inthegra/error"
|
|
6
|
+
|
|
7
|
+
require "faraday/inthegra"
|
|
8
|
+
|
|
9
|
+
require "inthegra/version"
|
|
10
|
+
require 'inthegra/configuration'
|
|
11
|
+
require 'inthegra/connection'
|
|
12
|
+
require 'inthegra/request'
|
|
13
|
+
require 'inthegra/client'
|
|
14
|
+
|
|
15
|
+
require 'inthegra/model/base'
|
|
16
|
+
require 'inthegra/model/auth_token'
|
|
17
|
+
require 'inthegra/model/line'
|
|
18
|
+
require 'inthegra/model/bus_stop'
|
|
19
|
+
require 'inthegra/model/vehicle'
|
|
20
|
+
|
|
21
|
+
require 'inthegra/serializer/base'
|
|
22
|
+
require 'inthegra/serializer/collection'
|
|
23
|
+
require 'inthegra/serializer/vehicles'
|
|
24
|
+
|
|
25
|
+
module Inthegra
|
|
26
|
+
extend Configuration
|
|
27
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module Inthegra
|
|
4
|
+
class Client
|
|
5
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
|
6
|
+
|
|
7
|
+
include Connection
|
|
8
|
+
include Request
|
|
9
|
+
|
|
10
|
+
include Lines
|
|
11
|
+
include BusStops
|
|
12
|
+
include Vehicles
|
|
13
|
+
|
|
14
|
+
attr_accessor *Configuration::VALID_OPTIONS
|
|
15
|
+
|
|
16
|
+
# Creates a new Client
|
|
17
|
+
def initialize(options={})
|
|
18
|
+
options = Inthegra.options.merge(options)
|
|
19
|
+
|
|
20
|
+
Configuration::VALID_OPTIONS.each do |key|
|
|
21
|
+
send("#{key}=", options[key])
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Authenticate the client and set the auth_token
|
|
26
|
+
# @return Authtoken
|
|
27
|
+
def authenticate
|
|
28
|
+
response = post('signin', { email: email, password: password })
|
|
29
|
+
self.auth_token = AuthToken.new(response)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class Client
|
|
3
|
+
# Define methods related to bus_stops
|
|
4
|
+
module BusStops
|
|
5
|
+
|
|
6
|
+
# Return a list of all bus_stops
|
|
7
|
+
#
|
|
8
|
+
# @return [Array::BusStop] All bus stops
|
|
9
|
+
# @example Return all bus stops
|
|
10
|
+
# Inthegra.bus_stops
|
|
11
|
+
# @authenticated true
|
|
12
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#paradas
|
|
13
|
+
def bus_stops
|
|
14
|
+
response = get('paradas')
|
|
15
|
+
|
|
16
|
+
CollectionSerializer.parse(response, BusStop)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Return a list of all searched bus stops
|
|
20
|
+
#
|
|
21
|
+
# @param query [String] An search query
|
|
22
|
+
# @return [Array::BusStop] All bus stops returned by search
|
|
23
|
+
# @example Return a list of all bus stops localized in 'ininga' neighborhood
|
|
24
|
+
# Inthegra.bus_stops_search('ininga')
|
|
25
|
+
# @authenticated true
|
|
26
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#paradas
|
|
27
|
+
def bus_stops_search(query)
|
|
28
|
+
response = get('paradas', { busca: URI::encode(query) })
|
|
29
|
+
|
|
30
|
+
CollectionSerializer.parse(response, BusStop)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Return all bus stops of the line code passed
|
|
34
|
+
#
|
|
35
|
+
# @param line_code [String] An line code
|
|
36
|
+
# @return [Array::BusStop] All bus stops in the line
|
|
37
|
+
# @example Return a list of all bus stops by the line code passed
|
|
38
|
+
# Inthegra.line_search('0401')
|
|
39
|
+
# @authenticated true
|
|
40
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#paradas
|
|
41
|
+
def bus_stops_by_line(line_code)
|
|
42
|
+
response = get('paradasLinha', { busca: URI::encode(line_code) })
|
|
43
|
+
|
|
44
|
+
CollectionSerializer.parse(response['Paradas'], BusStop)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class Client
|
|
3
|
+
# Define methods related to lines
|
|
4
|
+
module Lines
|
|
5
|
+
|
|
6
|
+
# Return a list of all lines
|
|
7
|
+
#
|
|
8
|
+
# @return [Array::Line] All lines
|
|
9
|
+
# @example Return all lines
|
|
10
|
+
# Inthegra.lines
|
|
11
|
+
# @authenticated true
|
|
12
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#linhas
|
|
13
|
+
def lines
|
|
14
|
+
response = get('linhas')
|
|
15
|
+
|
|
16
|
+
CollectionSerializer.parse(response, Line)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Return a list of all searched lines
|
|
20
|
+
#
|
|
21
|
+
# @param query [String] An search query
|
|
22
|
+
# @return [Array::Line] All lines
|
|
23
|
+
# @example Return a list of all lines localized in 'ininga' neighborhood
|
|
24
|
+
# Inthegra.line_search('ininga')
|
|
25
|
+
# @authenticated true
|
|
26
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#linhas
|
|
27
|
+
def line_search(query)
|
|
28
|
+
response = get('linhas', { busca: URI::encode(query) })
|
|
29
|
+
|
|
30
|
+
CollectionSerializer.parse(response, Line)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class Client
|
|
3
|
+
# Define methods related to vehicles
|
|
4
|
+
module Vehicles
|
|
5
|
+
|
|
6
|
+
# Return a list of all vehicles
|
|
7
|
+
#
|
|
8
|
+
# @return [Array::Vehicle] All vehicles
|
|
9
|
+
# @example Return all vehicles
|
|
10
|
+
# Inthegra.vehicles
|
|
11
|
+
# @authenticated true
|
|
12
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#veiculos
|
|
13
|
+
def vehicles
|
|
14
|
+
response = get('veiculos')
|
|
15
|
+
|
|
16
|
+
VehiclesSerializer.parse(response, Vehicle)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Return a list of all vehicles of from a line code
|
|
20
|
+
#
|
|
21
|
+
# @param query [String] An search query
|
|
22
|
+
# @return [Array::Vehicle] All lines
|
|
23
|
+
# @example Return a list of all vehicles of from a line code 401
|
|
24
|
+
# Inthegra.line_search('0401')
|
|
25
|
+
# @authenticated true
|
|
26
|
+
# @see https://inthegra.strans.teresina.pi.gov.br/docs#veiculos
|
|
27
|
+
def vehicles_by_line(line_code)
|
|
28
|
+
response = get('veiculosLinha', { busca: URI::encode(line_code) })
|
|
29
|
+
|
|
30
|
+
VehiclesSerializer.parse([response], Vehicle)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
module Configuration
|
|
3
|
+
|
|
4
|
+
# Default options of the configuration module
|
|
5
|
+
VALID_OPTIONS = [
|
|
6
|
+
:email,
|
|
7
|
+
:password,
|
|
8
|
+
:api_key,
|
|
9
|
+
:auth_token,
|
|
10
|
+
:proxy,
|
|
11
|
+
|
|
12
|
+
:user_agent,
|
|
13
|
+
:endpoint
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
attr_accessor *VALID_OPTIONS
|
|
17
|
+
|
|
18
|
+
DEFAULT_ENDPOINT = 'https://api.inthegra.strans.teresina.pi.gov.br/v1'
|
|
19
|
+
|
|
20
|
+
# Set default value when this methods is extented
|
|
21
|
+
def self.extended(base)
|
|
22
|
+
base.set_default_values
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def configure
|
|
26
|
+
yield self
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def set_default_values
|
|
30
|
+
self.endpoint = DEFAULT_ENDPOINT
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Return the array of options
|
|
34
|
+
def options
|
|
35
|
+
VALID_OPTIONS.inject({}) do |option, key|
|
|
36
|
+
option.merge!(key => send(key))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'faraday_middleware'
|
|
2
|
+
|
|
3
|
+
module Inthegra
|
|
4
|
+
# Wrapper for the faraday connection
|
|
5
|
+
module Connection
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def connection
|
|
9
|
+
options = {
|
|
10
|
+
:headers => {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
"Date": Time.now.strftime("%a, %d %b %Y %H:%M:%S GMT"),
|
|
13
|
+
"X-Api-Key": api_key,
|
|
14
|
+
"User-Agent" => user_agent
|
|
15
|
+
},
|
|
16
|
+
:url => endpoint
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Faraday.new(options) do |connection|
|
|
20
|
+
connection.use FaradayMiddleware::Inthegra, auth_token
|
|
21
|
+
connection.use Faraday::Response::ParseJson
|
|
22
|
+
|
|
23
|
+
connection.adapter :net_http
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class AuthToken < BaseModel
|
|
3
|
+
|
|
4
|
+
# @return [String] the auth token
|
|
5
|
+
attr_reader :token
|
|
6
|
+
|
|
7
|
+
# @return [Time] time when the token expire
|
|
8
|
+
attr_reader :expires_in
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
def fill(data)
|
|
12
|
+
@token = data['token']
|
|
13
|
+
@expires_in = Time.now + (data['token'].to_i * 60)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class BusStop < BaseModel
|
|
3
|
+
|
|
4
|
+
# @return [Integer] code of identification
|
|
5
|
+
attr_reader :code
|
|
6
|
+
|
|
7
|
+
# @return [String] where the bus stop is
|
|
8
|
+
attr_reader :name
|
|
9
|
+
|
|
10
|
+
# @return [String] full address of bus stop
|
|
11
|
+
attr_reader :address
|
|
12
|
+
|
|
13
|
+
# @return [String] latitude of the bus stop
|
|
14
|
+
attr_reader :lat
|
|
15
|
+
|
|
16
|
+
# @return [String] longitude of the bus stop
|
|
17
|
+
attr_reader :long
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def fill(data)
|
|
21
|
+
@code = data['CodigoParada']
|
|
22
|
+
@name = data['Denomicao']
|
|
23
|
+
@address = data['Endereco']
|
|
24
|
+
@lat = data['Lat']
|
|
25
|
+
@long = data['Long']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class Line < BaseModel
|
|
3
|
+
|
|
4
|
+
# @return [String] code of identification
|
|
5
|
+
attr_reader :code
|
|
6
|
+
|
|
7
|
+
# @return [String] line name
|
|
8
|
+
attr_reader :name
|
|
9
|
+
|
|
10
|
+
# @return [String] where the line starts
|
|
11
|
+
attr_reader :first_stop
|
|
12
|
+
|
|
13
|
+
# @return [String] where the line stops
|
|
14
|
+
attr_reader :last_stop
|
|
15
|
+
|
|
16
|
+
# @return [Boolean] if is a circular line
|
|
17
|
+
attr_reader :circular
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def fill(data)
|
|
21
|
+
@code = data["CodigoParada"]
|
|
22
|
+
@name = data["Denomicao"]
|
|
23
|
+
@origin = data["Origem"]
|
|
24
|
+
@return = data["Retorno"]
|
|
25
|
+
@circular = data["Circular"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class Vehicle < BaseModel
|
|
3
|
+
|
|
4
|
+
# @return [Integer] code of identification
|
|
5
|
+
attr_reader :code
|
|
6
|
+
|
|
7
|
+
# @return [String] current vehicle latitude
|
|
8
|
+
attr_reader :lat
|
|
9
|
+
|
|
10
|
+
# @return [String] current vehicle longitude
|
|
11
|
+
attr_reader :long
|
|
12
|
+
|
|
13
|
+
# @return [Time] last data update
|
|
14
|
+
attr_reader :hour
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def fill(data)
|
|
18
|
+
@code = data["CodigoVeiculo"]
|
|
19
|
+
@lat = data["Lat"]
|
|
20
|
+
@long = data["Long"]
|
|
21
|
+
@hour = Time.parse(data["Hora"])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
module Request
|
|
3
|
+
|
|
4
|
+
def get(path, options = {})
|
|
5
|
+
request(:get, path, options)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def post(path, options = {})
|
|
9
|
+
request(:post, path, options)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
def request(method, path, options)
|
|
14
|
+
if !auth_token and path != 'signin'
|
|
15
|
+
# Throws exception when the user request a diferente url
|
|
16
|
+
# that requires authentication and not have the auth_token.
|
|
17
|
+
raise Unauthenticated, 'You need autenticate to use this resource. Use the method Client#authentication.'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
response = connection.send(method) do |request|
|
|
21
|
+
path = URI.encode(path)
|
|
22
|
+
|
|
23
|
+
case method
|
|
24
|
+
when :get
|
|
25
|
+
request.url(path, options)
|
|
26
|
+
when :post
|
|
27
|
+
request.path = path
|
|
28
|
+
request.body = options.to_json
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
response.body
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
# Generic serialize class
|
|
3
|
+
class BaseSerializer
|
|
4
|
+
|
|
5
|
+
# @return [Array:Hash] the input data
|
|
6
|
+
attr_reader :input
|
|
7
|
+
|
|
8
|
+
# @return [Array:BaseModel] the output data
|
|
9
|
+
attr_reader :output
|
|
10
|
+
|
|
11
|
+
# @return [BaseModel] the model of collection
|
|
12
|
+
attr_reader :model
|
|
13
|
+
|
|
14
|
+
# Initialize the serializer passing a input data and a model
|
|
15
|
+
#
|
|
16
|
+
# @param input [String] The input data
|
|
17
|
+
# @param model [String] The resource model
|
|
18
|
+
def initialize(data, model)
|
|
19
|
+
data ||= []
|
|
20
|
+
|
|
21
|
+
unless data.is_a?(Array)
|
|
22
|
+
raise InvalidSerializerInput, "The data is a #{data.class} and not a Array type"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@model = model
|
|
26
|
+
@input = data
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Decorator method for the serializer
|
|
30
|
+
#
|
|
31
|
+
# @param input [String] The input data
|
|
32
|
+
# @param model [String] the model of collection
|
|
33
|
+
# @example Parse a line response
|
|
34
|
+
# Inthegra::CollectionSerializer(response, Inthegra::Line)
|
|
35
|
+
def self.parse(input, model)
|
|
36
|
+
@output = new(input, model).parse
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Implementation of the parser
|
|
40
|
+
def parse
|
|
41
|
+
raise NotImplementedError.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Inthegra
|
|
2
|
+
class VehiclesSerializer < BaseSerializer
|
|
3
|
+
|
|
4
|
+
# Parse a generic collection with your model type
|
|
5
|
+
# @return [Array] collection items
|
|
6
|
+
def parse
|
|
7
|
+
collection = []
|
|
8
|
+
input.each do |line|
|
|
9
|
+
line['Linha']['Veiculos'].each do |vehicles|
|
|
10
|
+
collection << vehicles
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
CollectionSerializer.parse(collection, model)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: inthegra
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rafael Guimarães
|
|
8
|
+
- Renato Filho
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: exe
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: bundler
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - "~>"
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '1.12'
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - "~>"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '1.12'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rake
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - "~>"
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '10.0'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - "~>"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '10.0'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: rspec
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '3.0'
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - "~>"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '3.0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: simplecov
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 0.11.2
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 0.11.2
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: webmock
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - "~>"
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 2.0.2
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - "~>"
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 2.0.2
|
|
84
|
+
- !ruby/object:Gem::Dependency
|
|
85
|
+
name: faraday
|
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - "~>"
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: 0.9.2
|
|
91
|
+
type: :runtime
|
|
92
|
+
prerelease: false
|
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - "~>"
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: 0.9.2
|
|
98
|
+
- !ruby/object:Gem::Dependency
|
|
99
|
+
name: faraday_middleware
|
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - "~>"
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: 0.10.0
|
|
105
|
+
type: :runtime
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - "~>"
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: 0.10.0
|
|
112
|
+
description: Ruby wrapper for the STRANS-PI Inthegra API
|
|
113
|
+
email:
|
|
114
|
+
- rafaelguimaraesweb@gmail.com
|
|
115
|
+
- renatosousafilho@gmail.com
|
|
116
|
+
executables: []
|
|
117
|
+
extensions: []
|
|
118
|
+
extra_rdoc_files: []
|
|
119
|
+
files:
|
|
120
|
+
- ".gitignore"
|
|
121
|
+
- ".rspec"
|
|
122
|
+
- ".travis.yml"
|
|
123
|
+
- Gemfile
|
|
124
|
+
- LICENSE.txt
|
|
125
|
+
- README.md
|
|
126
|
+
- Rakefile
|
|
127
|
+
- bin/setup
|
|
128
|
+
- inthegra.gemspec
|
|
129
|
+
- lib/faraday/inthegra.rb
|
|
130
|
+
- lib/inthegra.rb
|
|
131
|
+
- lib/inthegra/client.rb
|
|
132
|
+
- lib/inthegra/client/bus_stops.rb
|
|
133
|
+
- lib/inthegra/client/lines.rb
|
|
134
|
+
- lib/inthegra/client/vehicles.rb
|
|
135
|
+
- lib/inthegra/configuration.rb
|
|
136
|
+
- lib/inthegra/connection.rb
|
|
137
|
+
- lib/inthegra/error.rb
|
|
138
|
+
- lib/inthegra/model/auth_token.rb
|
|
139
|
+
- lib/inthegra/model/base.rb
|
|
140
|
+
- lib/inthegra/model/bus_stop.rb
|
|
141
|
+
- lib/inthegra/model/line.rb
|
|
142
|
+
- lib/inthegra/model/vehicle.rb
|
|
143
|
+
- lib/inthegra/request.rb
|
|
144
|
+
- lib/inthegra/serializer/base.rb
|
|
145
|
+
- lib/inthegra/serializer/collection.rb
|
|
146
|
+
- lib/inthegra/serializer/vehicles.rb
|
|
147
|
+
- lib/inthegra/version.rb
|
|
148
|
+
homepage: https://github.com/teresinahc/inthegra
|
|
149
|
+
licenses:
|
|
150
|
+
- MIT
|
|
151
|
+
metadata: {}
|
|
152
|
+
post_install_message:
|
|
153
|
+
rdoc_options: []
|
|
154
|
+
require_paths:
|
|
155
|
+
- lib
|
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
|
+
requirements:
|
|
158
|
+
- - ">="
|
|
159
|
+
- !ruby/object:Gem::Version
|
|
160
|
+
version: '0'
|
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
requirements: []
|
|
167
|
+
rubyforge_project:
|
|
168
|
+
rubygems_version: 2.4.8
|
|
169
|
+
signing_key:
|
|
170
|
+
specification_version: 4
|
|
171
|
+
summary: Inthegra
|
|
172
|
+
test_files: []
|