tfgm 0.0.2 → 0.0.3
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 +8 -8
- data/README.markdown +131 -2
- data/lib/tfgm.rb +14 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWYzMDM3YWQxNDYzMDVmMjlkM2NlMWFjMTk5ZTBlYzBjOWViNzE0Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Mzk4NzlmNWE2NGNjZTc3MGRkMWY1ODJkODE2YzNhZDk1YmYyMDk2Yg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGI1NjhjNzJjZDJlZTdjYTY4NGY3YTAxOGVhZTU5ZWY4NGRlMGJmZDhmYmVj
|
10
|
+
ZjJkY2ViZmMxYmEzMjEwZmMwZjk1NWFkYTIwNWUwMDA4MThhNDdiYWVmYTAy
|
11
|
+
MWRhMmM3YmMwMTA5NTgzYjU2Zjg0NWE1MzdmOTQwNDBlZWMxMmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmU1ZjA0Zjg2NTUzNDVlNjM2MjlkODg5NTRhNThlMTU3M2I4YTAwMTZhYmE1
|
14
|
+
YjJhZWRlMTM5NmYwYTZiMTM3YWM2YTdjZTA4Yzg2MWE3MDZmNWJlYTdkMWU2
|
15
|
+
ZGI5Y2NmOWRmNmM5NDU1NTIyNWM2Y2RkOGU0YTY2NWFlYjQzODk=
|
data/README.markdown
CHANGED
@@ -1,2 +1,131 @@
|
|
1
|
-
|
2
|
-
|
1
|
+

|
2
|
+
# TFGM Unofficial Rubygem
|
3
|
+
This is a Rubygem which acts as a wrapper for the [Transport for Greater Manchester REST API](http://developer.tfgm.com). This provides the most accurate car parks, bus and metrolink information available to freely consume through the **opendata.tfgm.com** REST API.
|
4
|
+
|
5
|
+
We built this to use internally in our project, EventBrite, for the [Innovation Challenge in Manchester](http://futureeverything.org/summit/conference/workshops-fringe-events/innovation-challenge/) (which won Best Under 21). The TFGM REST API is **new and unstable** as of March 2013 so we would avoid using it in production.
|
6
|
+
|
7
|
+
## Getting Started
|
8
|
+
* **Sign up for an API Key** — It's easy to sign up at [developer.tfgm.com](http://developer.tfgm.com) and you'll need a developer & application key. An example of what both the keys should like are: `a1b23cd4-ef67-890g-h123-4567i8jk9lmn` and they must be 36 characters in length.
|
9
|
+
|
10
|
+
* **Install the gem**
|
11
|
+
```ruby
|
12
|
+
gem install tfgm
|
13
|
+
```
|
14
|
+
|
15
|
+
* **Include it in your Ruby** — Insert this at the top of your Ruby code where you'll using TFGM.
|
16
|
+
```ruby
|
17
|
+
require 'tfgm'
|
18
|
+
```
|
19
|
+
|
20
|
+
* **Create an instance of TFGM::API**
|
21
|
+
```ruby
|
22
|
+
instance = TFGM::API.new("Developer Key", "Application Key")
|
23
|
+
```
|
24
|
+
|
25
|
+
* **Make it do something** — if you're unsure of what it can do, scroll down to "Manual" on this page.
|
26
|
+
```ruby
|
27
|
+
instance.stops_on_route('X50')
|
28
|
+
```
|
29
|
+
|
30
|
+
* **Have fun.** — Everything is returned as a `Hash.new` in Ruby. Use `.inspect` to extract data you need.
|
31
|
+
|
32
|
+
-----------------
|
33
|
+
|
34
|
+
## TFGM::API Manual
|
35
|
+
There's very limited data available, but we've outlined what's currently available below. Parameters denoted with `*` are mandatory.
|
36
|
+
|
37
|
+
### Car Parks
|
38
|
+
|
39
|
+
* Find all car parks in Greater Manchester
|
40
|
+
```ruby
|
41
|
+
# Parameters:
|
42
|
+
# (int) *page = default: 0
|
43
|
+
# (int) *per_page = default: 10
|
44
|
+
instance.carparks(0, 5)
|
45
|
+
```
|
46
|
+
|
47
|
+
* Find a car park by ID
|
48
|
+
```ruby
|
49
|
+
# Parameters:
|
50
|
+
# (int) *id
|
51
|
+
instance.carpark(21915)
|
52
|
+
```
|
53
|
+
|
54
|
+
### Routes
|
55
|
+
|
56
|
+
* View all bus routes running in Greater Manchester
|
57
|
+
```ruby
|
58
|
+
# Parameters:
|
59
|
+
# None
|
60
|
+
instance.routes
|
61
|
+
```
|
62
|
+
|
63
|
+
* View bus route by ID
|
64
|
+
```ruby
|
65
|
+
# Parameters
|
66
|
+
# (string) *bus_code
|
67
|
+
instance.route('X50')
|
68
|
+
```
|
69
|
+
|
70
|
+
* Verify bus route exists
|
71
|
+
```ruby
|
72
|
+
# Parameters:
|
73
|
+
# (string) *bus_code
|
74
|
+
if instance.is_route('X50') then
|
75
|
+
# Route exists, yay!
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
* Bus stops on bus route
|
80
|
+
```ruby
|
81
|
+
# Parameters
|
82
|
+
# (string) *bus_code
|
83
|
+
instance.stops_on_route('X50')
|
84
|
+
```
|
85
|
+
|
86
|
+
### Bus stops
|
87
|
+
|
88
|
+
* Find bus stops near a geolocation
|
89
|
+
```ruby
|
90
|
+
# Parameters:
|
91
|
+
# (double) *latitude
|
92
|
+
# (double) *longitude
|
93
|
+
instance.bus_stops_near(52.91391221, -3.39414441)
|
94
|
+
```
|
95
|
+
|
96
|
+
* Find bus stop by ATCO Code
|
97
|
+
```ruby
|
98
|
+
# Parameters:
|
99
|
+
# (string) *atco_code
|
100
|
+
instance.bus_stop('1800SB04781')
|
101
|
+
```
|
102
|
+
|
103
|
+
* Find routes running from bus stop
|
104
|
+
```ruby
|
105
|
+
# Parameters:
|
106
|
+
# (string) *atco_code
|
107
|
+
instance.buses_on_stop('1800SB04781')
|
108
|
+
```
|
109
|
+
|
110
|
+
### Metrolink times
|
111
|
+
|
112
|
+
* View all journey times
|
113
|
+
```ruby
|
114
|
+
# Parameters:
|
115
|
+
# None
|
116
|
+
instance.journey_times
|
117
|
+
```
|
118
|
+
|
119
|
+
* View journey times for a single route
|
120
|
+
```ruby
|
121
|
+
# Parameters:
|
122
|
+
# (string) *journey_id
|
123
|
+
instance.journey_times('A56-Dunham_proxy')
|
124
|
+
```
|
125
|
+
|
126
|
+
-----------------
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
We all know the REST API for TFGM is **really buggy**, but it's a great start. I'm glad that it's available and can foster innovation in the city, so if you're interested in developing it with me, just play about with it.
|
130
|
+
|
131
|
+
Let me know via [@bilawalhameed on Twitter](http://twitter.com/bilawalhameed/) if you're interested before sending a pull request.
|
data/lib/tfgm.rb
CHANGED
@@ -28,7 +28,7 @@ module TFGM
|
|
28
28
|
TFGM_BASE_URL = "http://opendata.tfgm.com"
|
29
29
|
|
30
30
|
## The version
|
31
|
-
TFGM_VERSION = "0.0.
|
31
|
+
TFGM_VERSION = "0.0.3"
|
32
32
|
|
33
33
|
##
|
34
34
|
## When we call TFGM::API.new, we automatically call initialize. Interesting.
|
@@ -71,10 +71,8 @@ module TFGM
|
|
71
71
|
|
72
72
|
## Right, throw an error if we can't authorize.
|
73
73
|
throw TFGM_Error::DeveloperOrApplicationKeyNotAccepted if _result['Message'].eql?("Authorization has been denied for this request.")
|
74
|
-
rescue TypeError
|
74
|
+
rescue TypeError, JSON::ParserError
|
75
75
|
## Empty by design.
|
76
|
-
rescue JSON::ParserError
|
77
|
-
throw TFGM_Error::JSONParserError
|
78
76
|
end
|
79
77
|
|
80
78
|
_result
|
@@ -83,11 +81,11 @@ module TFGM
|
|
83
81
|
##
|
84
82
|
## Show all car parks
|
85
83
|
##
|
86
|
-
def carparks(page =
|
84
|
+
def carparks(page = 0, per_page = 10, options = {})
|
87
85
|
_options = { :pageIndex => page, :pageSize => per_page }
|
88
86
|
|
89
87
|
## This validates whether a car park state is valid.
|
90
|
-
if options.has_key?('state')
|
88
|
+
if options.has_key?('state') then
|
91
89
|
_enums = self._call('/api/enums')
|
92
90
|
throw TFGM_Error::CarParkStateTypeInvalid unless _enums.member?(options['state'])
|
93
91
|
end
|
@@ -120,6 +118,10 @@ module TFGM
|
|
120
118
|
self._call("/api/routes/#{bus_code.to_s}", options)
|
121
119
|
end
|
122
120
|
|
121
|
+
def is_route(bus_code, options = {})
|
122
|
+
self.route(bus_code, options).count > 0
|
123
|
+
end
|
124
|
+
|
123
125
|
def buses_on_route(bus_code, options = {})
|
124
126
|
self._call("/api/routes/#{bus_code.to_s}/buses", options)
|
125
127
|
end
|
@@ -144,12 +146,12 @@ module TFGM
|
|
144
146
|
##
|
145
147
|
## Journey times
|
146
148
|
##
|
147
|
-
def journey_times(options = {})
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
149
|
+
def journey_times(journey_id = 0, options = {})
|
150
|
+
if journey_id > 0 then
|
151
|
+
self._call("/api/journeytimes/#{journey_id.to_s}", options)
|
152
|
+
else
|
153
|
+
self._call("/api/journeytimes", options)
|
154
|
+
end
|
153
155
|
end
|
154
156
|
|
155
157
|
##
|