spbus 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58eec47fb8c6377374cede176ce2613b1639f928
4
- data.tar.gz: 60981bfd93bd384d157024f95f3b96e390f6e125
3
+ metadata.gz: 721321499ae1d4ad22f3f61f5802e2872ebd0f9b
4
+ data.tar.gz: 9b936314c670942e1e5a8a770725267c48897a37
5
5
  SHA512:
6
- metadata.gz: c573ccd0ecccec2804867de1440fba932d961c751297f1ee2c1c71ef4c9a90338cbf3d530d2da25b6411a9231667d5b4c1a65ad9bb36d8a90d211987e964dee9
7
- data.tar.gz: b73ba4b11c0e8eb8ce5a141a02f5929841eedb01eec3927dc1428a1500e3447af309cda6eef45cb86fa1091fe8d90cf0d7e0120f7cc59cc13293d50cea1ce330
6
+ metadata.gz: cd2770c6723a184ab1bfe7abe5be0552f749f99dbc1563d8e037eb0a8d669dca810f20ee36168d486b5f7b1f0dc27db055249200d52a6471b5e283aaad7e5e0b
7
+ data.tar.gz: fe6ca2c698b0ea89f7cc02ea5d49fb44f814adad7e795489f02d09ce040e829b8c85416e3ea33b11d3d8813c1c8e0a0b378a915387caea55dd63d4698ea5e434
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
+ pkg/
2
3
 
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ script: bundle exec rspec
8
+
data/README.md CHANGED
@@ -3,6 +3,11 @@
3
3
  A gem to easily retrieve information about São Paulo bus routes, numbers,
4
4
  location, etc using SPTrans web services.
5
5
 
6
+ [![Code Climate](https://codeclimate.com/github/lenon/spbus.png)](https://codeclimate.com/github/lenon/spbus)
7
+ [![Gem Version](https://badge.fury.io/rb/spbus.png)](http://badge.fury.io/rb/spbus)
8
+ [![Build Status](https://travis-ci.org/lenon/spbus.png)](https://travis-ci.org/lenon/spbus)
9
+
10
+
6
11
  ## Installation
7
12
 
8
13
  Add this line to your application's Gemfile:
data/lib/spbus/bus.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "ostruct"
2
+
3
+ module SpBus
4
+ class Bus < OpenStruct
5
+ end
6
+ end
7
+
@@ -0,0 +1,37 @@
1
+ module SpBus
2
+ class Locations
3
+ BUSES_LOCATIONS = "http://200.189.189.54/InternetServices/PosicaoLinha"
4
+
5
+ attr_reader :buses
6
+
7
+ def initialize(route)
8
+ @route = route
9
+ end
10
+
11
+ def fetch_locations
12
+ sptrans_request
13
+
14
+ raise InconsistentResponse unless valid_response?
15
+
16
+ @buses = @response[:vs].collect do |hash|
17
+ SpBus::Bus.new(lat: hash[:py], long: hash[:px])
18
+ end
19
+
20
+ true
21
+ end
22
+
23
+ private
24
+
25
+ def sptrans_request
26
+ @response = JSON.parse(
27
+ RestClient.get(BUSES_LOCATIONS, params: { codigoLinha: @route }),
28
+ symbolize_names: true
29
+ )[:PosicaoLinhaResult]
30
+ end
31
+
32
+ def valid_response?
33
+ !@response.nil? && !@response[:hr].nil? && !@response[:hr].empty?
34
+ end
35
+ end
36
+ end
37
+
data/lib/spbus/route.rb CHANGED
@@ -25,6 +25,16 @@ module SpBus
25
25
  true
26
26
  end
27
27
 
28
+ def to_h
29
+ {
30
+ number: number,
31
+ origin: origin,
32
+ destination: destination,
33
+ code_for_origin: code_for_origin,
34
+ code_for_destination: code_for_destination
35
+ }
36
+ end
37
+
28
38
  private
29
39
 
30
40
  def sptrans_request
data/lib/spbus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SpBus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/spbus.rb CHANGED
@@ -4,6 +4,8 @@ require "json"
4
4
  require "spbus/version"
5
5
  require "spbus/crawler"
6
6
  require "spbus/route"
7
+ require "spbus/bus"
8
+ require "spbus/locations"
7
9
 
8
10
  module SpBus
9
11
  class InconsistentResponse < StandardError ; end
@@ -0,0 +1,34 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://200.189.189.54/InternetServices/PosicaoLinha?codigoLinha=59
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '101'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Server:
26
+ - Microsoft-HTTPAPI/2.0
27
+ Date:
28
+ - Sun, 08 Sep 2013 02:41:33 GMT
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"PosicaoLinhaResult":{"hr":"23:41","vs":[{"a":true,"p":"72420","px":-46.735629,"py":-23.64352625}]}}'
32
+ http_version:
33
+ recorded_at: Sun, 08 Sep 2013 02:41:33 GMT
34
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://200.189.189.54/InternetServices/BuscaLinhasSIM?termosBusca=6450-10
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '361'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Server:
26
+ - Microsoft-HTTPAPI/2.0
27
+ Date:
28
+ - Sat, 07 Sep 2013 23:22:55 GMT
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"BuscaLinhasSIMResult":[{"Circular":false,"CodigoLinha":59,"DenominacaoTPTS":"TERM.
32
+ BANDEIRA","DenominacaoTSTP":"TERM. CAPELINHA","Informacoes":null,"Letreiro":"6450","Sentido":1,"Tipo":10},{"Circular":false,"CodigoLinha":32827,"DenominacaoTPTS":"TERM.
33
+ BANDEIRA","DenominacaoTSTP":"TERM. CAPELINHA","Informacoes":null,"Letreiro":"6450","Sentido":2,"Tipo":10}]}'
34
+ http_version:
35
+ recorded_at: Sat, 07 Sep 2013 23:22:54 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe SpBus::Locations do
4
+
5
+ describe "#fetch_locations", :vcr do
6
+
7
+ subject { described_class.new("59") }
8
+ before { subject.fetch_locations }
9
+
10
+ it "retrieves all buses locations" do
11
+ expect(subject.buses).to have(1).item
12
+ expect(subject.buses.first).to be_kind_of(SpBus::Bus)
13
+ expect(subject.buses.first.lat).to eql(-23.64352625)
14
+ expect(subject.buses.first.long).to eql(-46.735629)
15
+ end
16
+ end
17
+ end
18
+
data/spec/route_spec.rb CHANGED
@@ -28,5 +28,21 @@ describe SpBus::Route do
28
28
  expect(subject.destination).to eql("TERM. BANDEIRA")
29
29
  end
30
30
  end
31
+
32
+ describe "#to_h", :vcr do
33
+
34
+ subject { described_class.new("6450-10") }
35
+ before { subject.fetch_details }
36
+
37
+ it "returns a hash" do
38
+ expect(subject.to_h).to eql({
39
+ number: "6450-10",
40
+ origin: "TERM. CAPELINHA",
41
+ destination: "TERM. BANDEIRA",
42
+ code_for_origin: 59,
43
+ code_for_destination: 32827
44
+ })
45
+ end
46
+ end
31
47
  end
32
48
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lenon Marcel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,22 +117,28 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
119
  - .rspec
120
+ - .travis.yml
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
123
124
  - Rakefile
124
125
  - example.rb
125
126
  - lib/spbus.rb
127
+ - lib/spbus/bus.rb
126
128
  - lib/spbus/crawler.rb
129
+ - lib/spbus/locations.rb
127
130
  - lib/spbus/route.rb
128
131
  - lib/spbus/version.rb
129
132
  - spbus.gemspec
130
133
  - spec/cassettes/SpBus_Crawler/_fetch_routes/returns_all_bus_routes.yml
131
134
  - spec/cassettes/SpBus_Crawler/_fetch_routes/returns_creates_a_Route_object_for_every_found_route.yml
135
+ - spec/cassettes/SpBus_Locations/_fetch_locations/retrieves_all_buses_locations.yml
132
136
  - spec/cassettes/SpBus_Route/_fetch_details/sets_destination_attribute.yml
133
137
  - spec/cassettes/SpBus_Route/_fetch_details/sets_origin_attribute.yml
134
138
  - spec/cassettes/SpBus_Route/_fetch_details/sets_route_position_codes.yml
139
+ - spec/cassettes/SpBus_Route/_to_h/returns_a_hash.yml
135
140
  - spec/crawler_spec.rb
141
+ - spec/locations_spec.rb
136
142
  - spec/route_spec.rb
137
143
  - spec/spec_helper.rb
138
144
  homepage: http://github.com/lenon/spbus
@@ -163,9 +169,12 @@ summary: A gem to easily retrieve information about São Paulo bus routes, numbe
163
169
  test_files:
164
170
  - spec/cassettes/SpBus_Crawler/_fetch_routes/returns_all_bus_routes.yml
165
171
  - spec/cassettes/SpBus_Crawler/_fetch_routes/returns_creates_a_Route_object_for_every_found_route.yml
172
+ - spec/cassettes/SpBus_Locations/_fetch_locations/retrieves_all_buses_locations.yml
166
173
  - spec/cassettes/SpBus_Route/_fetch_details/sets_destination_attribute.yml
167
174
  - spec/cassettes/SpBus_Route/_fetch_details/sets_origin_attribute.yml
168
175
  - spec/cassettes/SpBus_Route/_fetch_details/sets_route_position_codes.yml
176
+ - spec/cassettes/SpBus_Route/_to_h/returns_a_hash.yml
169
177
  - spec/crawler_spec.rb
178
+ - spec/locations_spec.rb
170
179
  - spec/route_spec.rb
171
180
  - spec/spec_helper.rb