spbus 0.0.5 → 0.0.6
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 +4 -4
- data/lib/spbus/request.rb +1 -11
- data/lib/spbus/scrapers/locations.rb +2 -2
- data/lib/spbus/scrapers/route_details.rb +3 -3
- data/lib/spbus/scrapers/routes.rb +0 -2
- data/lib/spbus/version.rb +1 -1
- data/lib/spbus.rb +5 -1
- data/spec/cassettes/bus_routes.yml +25340 -25621
- data/spec/cassettes/buses_locations.yml +9 -251
- data/spec/cassettes/invalid_route_detail.yml +9 -251
- data/spec/cassettes/normal_route_detail.yml +11 -253
- data/spec/cassettes/one_way_route_detail.yml +11 -253
- data/spec/cassettes/{normal_request.yml → simple_request.yml} +6 -6
- data/spec/request_spec.rb +8 -27
- data/spec/scrapers/locations_scraper_spec.rb +3 -3
- data/spec/scrapers/routes_scraper_spec.rb +1 -1
- data/spec/spbus_spec.rb +6 -0
- metadata +4 -6
- data/spec/cassettes/auth_request.yml +0 -278
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f63128061498523a2de0d0f08f42d12a6b18a32
|
4
|
+
data.tar.gz: 833ec14a34cb6db858fe91c3db826dbb466796ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f5fc8f1465d8c73d6e9524cd1e43e8ae8f13f048451d9f35b2e2baa28002589a38b4cfa9e4b05b8cf37346a72b0441585287c77bc22ff7ee570a33df2b5a239
|
7
|
+
data.tar.gz: 539481e90fb7e8b23909dc6f3866f7f9ded8bba84940ec284225a6bde2f6bf0814c7a76b2707adf544428576c1abddf69d838d1eb37044ea99d3e7a62aeb44bd
|
data/lib/spbus/request.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
module SpBus
|
2
2
|
class Request
|
3
3
|
|
4
|
-
AUTH_URL = "http://olhovivo.sptrans.com.br/"
|
5
|
-
|
6
|
-
attr_writer :authenticated
|
7
|
-
|
8
4
|
def initialize(url)
|
9
5
|
@url = url
|
10
|
-
@authenticated = true
|
11
6
|
end
|
12
7
|
|
13
8
|
def get
|
14
9
|
tries ||= 3
|
15
|
-
get_cookies if @authenticated
|
16
10
|
open(@url, request_headers).read
|
17
11
|
rescue Errno::ETIMEDOUT => e
|
18
12
|
raise e if (tries -= 1) == 0
|
@@ -21,13 +15,9 @@ module SpBus
|
|
21
15
|
|
22
16
|
private
|
23
17
|
|
24
|
-
def get_cookies
|
25
|
-
@cookies = open(AUTH_URL).meta["set-cookie"]
|
26
|
-
end
|
27
|
-
|
28
18
|
def request_headers
|
29
19
|
headers = {}
|
30
|
-
headers["
|
20
|
+
headers["User-Agent"] = "SpBus/#{SpBus::VERSION}"
|
31
21
|
headers
|
32
22
|
end
|
33
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SpBus::Scrapers
|
2
2
|
class Locations
|
3
3
|
|
4
|
-
URL = "http://
|
4
|
+
URL = "http://200.189.189.54/InternetServices/PosicaoLinha"
|
5
5
|
|
6
6
|
attr_reader :buses
|
7
7
|
|
@@ -11,7 +11,7 @@ module SpBus::Scrapers
|
|
11
11
|
|
12
12
|
def fetch
|
13
13
|
doc = SpBus::Request.new(url_with_params).get
|
14
|
-
@json = JSON.parse(doc, symbolize_names: true)
|
14
|
+
@json = JSON.parse(doc, symbolize_names: true)[:PosicaoLinhaResult]
|
15
15
|
|
16
16
|
validate_response
|
17
17
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SpBus::Scrapers
|
2
2
|
class RouteDetails
|
3
3
|
|
4
|
-
URL = "http://
|
4
|
+
URL = "http://200.189.189.54/InternetServices/BuscaLinhasSIM"
|
5
5
|
|
6
6
|
def initialize(route)
|
7
7
|
@route = route
|
@@ -9,7 +9,7 @@ module SpBus::Scrapers
|
|
9
9
|
|
10
10
|
def fetch
|
11
11
|
doc = SpBus::Request.new(url_with_params).get
|
12
|
-
@json = JSON.parse(doc, symbolize_names: true)
|
12
|
+
@json = JSON.parse(doc, symbolize_names: true)[:BuscaLinhasSIMResult]
|
13
13
|
|
14
14
|
validate_response
|
15
15
|
build_route
|
@@ -35,7 +35,7 @@ module SpBus::Scrapers
|
|
35
35
|
@json.size != 2 ||
|
36
36
|
@json[0][:DenominacaoTSTP] != @json[1][:DenominacaoTSTP] ||
|
37
37
|
@json[0][:DenominacaoTPTS] != @json[1][:DenominacaoTPTS]
|
38
|
-
raise SpBus::
|
38
|
+
raise SpBus::InvalidRoute
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
data/lib/spbus/version.rb
CHANGED