emt_api 0.0.0.1 → 0.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/README.md +9 -6
- data/Rakefile +5 -0
- data/emt_api.gemspec +2 -0
- data/lib/emt_api.rb +2 -1
- data/lib/emt_api/api.rb +25 -0
- data/lib/emt_api/line.rb +35 -0
- data/lib/emt_api/parser.rb +23 -0
- data/lib/emt_api/response.rb +30 -0
- data/lib/emt_api/version.rb +1 -1
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4d84d55baeb1ed55ab71ed89b6d7d625f2946f5
|
4
|
+
data.tar.gz: a446a34347bfc06e500aae32f8771ddb39b75efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d7a01351085662f6b33f4fc3e30f8fd08a41a2958e99528ba12a780f0140d49698fe8ff3a1e29d445ee03ab98c3ef33d7fdf86808be2956dd935dfb84fbfbe3
|
7
|
+
data.tar.gz: 4fdfc2b6de4baf7b9bb5f2af6d502db3c4032e32df13e1345211953f536371fb3d217901ac26fd365b8f681e691dfe15baada2255a9b0a32af1b92db04ae4ed5
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# EmtApi
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/amiedes/emt_api.svg?branch=master)](https://travis-ci.org/amiedes/emt_api)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/amiedes/emt_api/badge.svg)](https://coveralls.io/github/amiedes/emt_api)
|
4
5
|
|
5
|
-
|
6
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/emt_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -14,11 +15,15 @@ gem 'emt_api'
|
|
14
15
|
|
15
16
|
And then execute:
|
16
17
|
|
17
|
-
|
18
|
+
```
|
19
|
+
$ bundle
|
20
|
+
```
|
18
21
|
|
19
22
|
Or install it yourself as:
|
20
23
|
|
21
|
-
|
24
|
+
```
|
25
|
+
$ gem install emt_api
|
26
|
+
```
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
@@ -34,8 +39,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
39
|
|
35
40
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/emt_api.
|
36
41
|
|
37
|
-
|
38
42
|
## License
|
39
43
|
|
40
44
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/Rakefile
CHANGED
data/emt_api.gemspec
CHANGED
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
spec.add_development_dependency "byebug", "~> 9.0.6"
|
30
|
+
spec.add_development_dependency "vcr"
|
31
|
+
spec.add_development_dependency "webmock"
|
30
32
|
end
|
data/lib/emt_api.rb
CHANGED
data/lib/emt_api/api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'http'
|
2
|
+
require_relative 'response'
|
3
|
+
|
4
|
+
module EmtApi
|
5
|
+
class Api
|
6
|
+
GET_LIST_LINES_URL = 'https://openbus.emtmadrid.es:9443/emt-proxy-server/last/bus/GetListLines.php'
|
7
|
+
EMT_CLIENT = ENV['EMT_CLIENT']
|
8
|
+
EMT_SECRET = ENV['EMT_SECRET']
|
9
|
+
|
10
|
+
def self.get_list_lines(line_ids = nil, date = Time.now)
|
11
|
+
|
12
|
+
http_response = HTTP.post(GET_LIST_LINES_URL, form: {
|
13
|
+
idClient: EMT_CLIENT,
|
14
|
+
passKey: EMT_SECRET,
|
15
|
+
SelectDate: date.strftime("%d/%m/%Y"),
|
16
|
+
Lines: line_ids
|
17
|
+
})
|
18
|
+
|
19
|
+
emt_response = EmtApi::Response.new(http_response)
|
20
|
+
|
21
|
+
emt_response.valid_data? ? emt_response.data : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/emt_api/line.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'parser'
|
2
|
+
require_relative 'api'
|
3
|
+
|
4
|
+
module EmtApi
|
5
|
+
class Line
|
6
|
+
attr_accessor :id, :label, :group_number, :date_first, :date_end, :origin, :destination
|
7
|
+
|
8
|
+
def initialize(line_data = {})
|
9
|
+
@id = line_data['line']
|
10
|
+
@label = line_data['label']
|
11
|
+
@group_number = line_data['groupNumber'].to_i
|
12
|
+
@date_first = EmtApi::Parser.parse_date line_data['dateFirst']
|
13
|
+
@date_end = EmtApi::Parser.parse_date line_data['dateEnd']
|
14
|
+
@origin = EmtApi::Parser.parse_sentence line_data['nameA']
|
15
|
+
@destination = EmtApi::Parser.parse_sentence line_data['nameB']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all
|
19
|
+
response_data = EmtApi::Api.get_list_lines
|
20
|
+
lines = []
|
21
|
+
|
22
|
+
unless response_data.nil?
|
23
|
+
response_data.each { |line| lines << EmtApi::Line.new(line) }
|
24
|
+
end
|
25
|
+
|
26
|
+
lines
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find(id)
|
30
|
+
response_data = EmtApi::Api.get_list_lines(id)
|
31
|
+
response_data.nil? ? nil : EmtApi::Line.new(response_data)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EmtApi
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
def self.parse_date(date_string)
|
5
|
+
date_string = remove_trailing_whitespaces(date_string)
|
6
|
+
Date.parse(date_string)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse_sentence(sentence)
|
10
|
+
sentence = remove_trailing_whitespaces(sentence)
|
11
|
+
capitalize_sentence(sentence)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.remove_trailing_whitespaces(sentence)
|
15
|
+
sentence.rstrip
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.capitalize_sentence(sentence)
|
19
|
+
sentence.split.map { |word| word.capitalize }.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module EmtApi
|
2
|
+
class Response
|
3
|
+
attr_accessor :code, :result_code, :result_description, :data
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@code = response.code
|
7
|
+
if successful?
|
8
|
+
json_response = JSON.parse(response.body)
|
9
|
+
@result_code = json_response['resultCode']
|
10
|
+
@result_description = json_response['resultDescription']
|
11
|
+
if valid_result?
|
12
|
+
@data = json_response['resultValues']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def successful?
|
18
|
+
code == 200
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_result?
|
22
|
+
result_code == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_data?
|
26
|
+
successful? && valid_result?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/emt_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emt_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Miedes Garcés
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 9.0.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Ruby wrapper for the EMT API
|
84
112
|
email:
|
85
113
|
- albertomg994@gmail.com
|
@@ -98,6 +126,10 @@ files:
|
|
98
126
|
- bin/setup
|
99
127
|
- emt_api.gemspec
|
100
128
|
- lib/emt_api.rb
|
129
|
+
- lib/emt_api/api.rb
|
130
|
+
- lib/emt_api/line.rb
|
131
|
+
- lib/emt_api/parser.rb
|
132
|
+
- lib/emt_api/response.rb
|
101
133
|
- lib/emt_api/version.rb
|
102
134
|
homepage: https://github.com/amiedes/emt_api
|
103
135
|
licenses:
|