smtuc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smtuc/stop.rb +46 -2
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3f74e6aa6bce3d5fead5098632858fdb228f0e7
4
- data.tar.gz: d59dd323678ecbac1eab0cea1842b9f6b355e3bd
3
+ metadata.gz: 4995e9c0da962a05500b58776c256e0b138733f2
4
+ data.tar.gz: 2cb8bf27264f28963780a3425c9ca251589e9075
5
5
  SHA512:
6
- metadata.gz: 2be8cef59a550b0b8a0da9c39258b3bfcb2cda24bbd0e74cb0fe1b2e5291dff85a99a48e82effc8a7eac637f634c19d495290b31d7664189e51b4a9218f1601d
7
- data.tar.gz: 15804d0620eb639782811b38470b6a217955f7325e2800c477d3b3bff83c6c487c4eb82a2ba9af077791439c9d8b323421ed7236bb8c3f35eb89aeaea91db416
6
+ metadata.gz: 78437e6dea4b671a01d2bc4cf4f844e4a73ecf782688bbb6f74d32714c036274def01ebfeb0b3ad66e17d63dd2bce94acb6f19927c93ca1e71aeb0470ce98a61
7
+ data.tar.gz: 1a64cf37f113ad6727233609f51533be60ac8c4950cec208a2e87a4678776c814e599bed5303a115d7f5341b3932db0648112a8483d98df360027ebd7687b226
data/lib/smtuc/stop.rb CHANGED
@@ -14,11 +14,55 @@ class SMTUC
14
14
  @lon = attributes['CoordY']
15
15
  end
16
16
 
17
+ # Because there's no real way through the API to get details on a specific
18
+ # stop, istead we grab all of the stops and filter by id.
19
+ #
20
+ # TODO: maybe there is a chance we can simply cache results locally,
21
+ # as stops don't even change that often.
22
+ def self.find(id)
23
+ all.select { |s| s.id == id }.first
24
+ end
25
+
17
26
  # Returns a list of all known stops
18
27
  def self.all
19
28
  response = Faraday.get(API_URL + '/GetStops?oLat=40.20343598944182&oLon=-8.417298279776674&meters=99999999999')
20
- lines = JSON.parse(response.body)
21
- lines.map { |line| new(line) }
29
+ JSON.parse(response.body).map { |stop| new(stop) }
30
+ end
31
+
32
+ # Returns a list of stops around a specific latitude and longitude.
33
+ # A radius can be specified. If it is not, it falls back to a default of 200m.
34
+ def self.by_location(lat, lon, radius = 200)
35
+ response = Faraday.get(API_URL + "/GetStops?oLat=#{lat}&oLon=#{lon}&meters=#{radius}")
36
+ JSON.parse(response.body).map { |stop| new(stop) }
37
+ end
38
+
39
+ def arrivals
40
+ response = Faraday.get(BASE_API_URL + '/NextArrivals/GetScheds?providerName=SMTUC&stopCode=SMTUC_' + id)
41
+ arrivals = JSON.parse(response.body)
42
+
43
+ # Response is normally an array that looks like this:
44
+ #
45
+ # [
46
+ # {"Key"=>1, "Value"=>["36", "Pr. República", "19"]},
47
+ # {"Key"=>2, "Value"=>["25T", "Beira Rio", "24"]}
48
+ # ]
49
+ #
50
+ # We map that to something a little friendlier that looks like this:
51
+ #
52
+ # [
53
+ # {
54
+ # line: "36",
55
+ # description: "Pr. República",
56
+ # minutes: 19
57
+ # }, (...)
58
+ # ]
59
+ arrivals.map do |l|
60
+ {
61
+ line: l['Value'][0],
62
+ description: l['Value'][1],
63
+ minutes: l['Value'][2].to_i
64
+ }
65
+ end
22
66
  end
23
67
  end
24
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smtuc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Oliveira
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '10.0'
69
69
  description: A non-official gem on top of a non-fficial API to SMTUC
70
70
  email: fred@helloform.com
71
71
  executables: []
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.6.11
98
+ rubygems_version: 2.6.14
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: SMTUC, the gem!