tfl_api_client 0.1.0
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 +7 -0
- data/.gitignore +37 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +62 -0
- data/GETTING_STARTED.md +161 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +62 -0
- data/Rakefile +30 -0
- data/lib/tfl_api_client/bike_point.rb +105 -0
- data/lib/tfl_api_client/client.rb +235 -0
- data/lib/tfl_api_client/exceptions.rb +91 -0
- data/lib/tfl_api_client/version.rb +28 -0
- data/lib/tfl_api_client.rb +33 -0
- data/spec/cassettes/bike_point/authorised_client_location.yml +83 -0
- data/spec/cassettes/bike_point/authorised_client_locations.yml +8179 -0
- data/spec/cassettes/bike_point/authorised_client_locations_within_bounding_box.yml +402 -0
- data/spec/cassettes/bike_point/authorised_client_locations_within_locus.yml +106 -0
- data/spec/cassettes/bike_point/authorised_client_search.yml +80 -0
- data/spec/cassettes/bike_point/unauthorised_client_location.yml +50 -0
- data/spec/cassettes/bike_point/unauthorised_client_locations.yml +50 -0
- data/spec/cassettes/bike_point/unauthorised_client_locations_within_bounding_box.yml +50 -0
- data/spec/cassettes/bike_point/unauthorised_client_locations_within_locus.yml +50 -0
- data/spec/cassettes/bike_point/unauthorised_client_search.yml +50 -0
- data/spec/integration/bike_point_spec.rb +158 -0
- data/spec/spec_helper.rb +114 -0
- data/spec/support/coverage.rb +36 -0
- data/spec/support/helpers.rb +81 -0
- data/spec/support/vcr.rb +43 -0
- data/spec/unit/bike_point_spec.rb +87 -0
- data/spec/unit/client_spec.rb +199 -0
- data/tfl_api_client.gemspec +36 -0
- metadata +222 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 072de61d15adb1e4f79ec7e0ab0b3d85d1618fb7
|
4
|
+
data.tar.gz: b06257ef4ec2284db1eb978c5b2372fd7ad38fc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf7b44b929b47a007102911506a007ed293ca585361c6cd697871000e3632c8c8faef938e97e1e5003dde0184dd430a061a37567d9bdf5f3fef16f4dc7af5606
|
7
|
+
data.tar.gz: 72c58429cc1b558c74f77836063000e359c5ea0d50afe83b8dd68dbf04c9753e2d7105b56218cbec2e5cd2a703f3f5f0ae09d004ff0a819025214db8fecb67b0
|
data/.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Ruby files
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
# Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
# Environment normalisation:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
/.idea/
|
29
|
+
|
30
|
+
# for a library or gem, you might want to ignore these files since the code is
|
31
|
+
# intended to run in multiple environments; otherwise, check them in:
|
32
|
+
Gemfile.lock
|
33
|
+
.ruby-version
|
34
|
+
.ruby-gemset
|
35
|
+
|
36
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
37
|
+
.rvmrc
|
data/.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 2.2.0
|
7
|
+
- 2.1.0
|
8
|
+
- 2.0.0
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- gem uninstall bundler
|
12
|
+
- gem install bundler --version '~> 1.10'
|
13
|
+
|
14
|
+
script:
|
15
|
+
- bundle exec rake
|
16
|
+
|
17
|
+
env:
|
18
|
+
global:
|
19
|
+
# Application ID
|
20
|
+
- secure: mNYN26/OaEx535SefPMYfR3hYpYbm7GBJcWuSQ+emO22LDF90dFVHzIakmNAvwPG+sMkjKmKdxbQHOW7IVvfQ7wSc7uQ1lKpUVQcbimc+VXdQ/KIhlKVmIu/ZNV3KJW+d+/4PXMIY88tUynfd9CcuG3SyIrpmjQbSyQM0N/EbK0S4dMMfxSr6ryUnRh3X5Jcyl/hnGzeFqQ8ZVSFBVOPgW1Tkn69MemYNCQtkIyHHAUgCgRc96VJMVaKo0Fujs1WHtsjy9fHmhbduDZ/th3Enl7H2YuayYrYxzJwWIFpKNT0eTx8DoQIhtgRDiCyRaAH+lqfmgr/a3UIEG0q7PABDg97n/I9Ie0dtwTGJ1arrRKvQ7l8S4rv0pRSIaSOdUPce5BIqoMmmexIfiCnuQCPzxIjbHVLBXf85XuNhNzlTJDsXGqyekuQxWcV7iTy305jVokgEQETE5s0lX2x2HpFPCBYm/Ig8zF/wII2QRgN4t7eeUxYuGWkJKw6h7ssuB3Zv0KNKZsNeLvCo9l3Z+8TZ6u1uS3ab61eUYY165HBAGUq5PQ7xBuWD25ERcbU+mtPClLwrKdJmR0m5BmUC33ZXXqgje3qfzBhJdwLULPj/j7Hy+SUx4RgFDfIxB0eXa8XUHoMX8V1R4MlUt08LtQej3NCNHUogYf9Jo01lPtte08=
|
21
|
+
# Application Key
|
22
|
+
- secure: epXs5gDgdb/krwvS0gCYVlB2IusKfYHE3pbc90Pd+XqqEHsdqYQ5vpNYFiDjHpazh7xVtW8gL/5UIjSU4AFSjgNphhb83YBmdvWO5z/Zugs/F7llseYCt8QtLkpw8a7ERzsXjnq91zbxiJO4+Vz0DSZRw8nUNiN4wRGmKVIHWPHe/yi3J7GfJ4xZXe2N+yXbXR36DWaGWvjdJDh3S1wSHGe3+HAmZq6e1Xw2a27hwkpUUA4eviCnuV6CfzJl/KVjLEdneBPQ3lhHsLOgZ4ZpoC1uFICyJfRwbWdaaG+J9VQMbmpjaZfpJlV3ObZsIjis6rpVvDaqRnVGOvnlFy6gdCh3Onqm6N9I7s4lVaGKFldciIJwwC/WoMiXZJBMKO3IlmcRHQJVzc1B+lS8ehCUSvtCl6AZ9R2EOYMfiDXp5c4jjZRcVfeqpuGg56twBzFNNu2AN3JLtgwEhGgvWg6176ws2hpYjJxSDtjFZoErfsRP8vl/vzXtnNNx8p1R4Z/eOTO/IKGdW4YI3e1JwszPEegohNpeVWgAGW3SrNeuDmfXJ8j0+SuuTlHcqmBc0fzjz+pEG8/irG2dfCvpVoDKUQhk8NJtvxsXHsVllk5SifwplAWZhFmXom4ID5HDpMpl0sQ7ynIO+5f9/KJAFnhqGlvoXRgQIBmO8/yyOlVeLnY=
|
23
|
+
# Coveralls Repository Token
|
24
|
+
- secure: djKSoF3fahZ0s0SfwZHCGdBA/OU66aNdj0XBhjCz4LkDFn5f9I2TdymY5kMQWnFeyiyQ298cwb0o1FfTZ/jIziI/bU1evLuQk4PTjwiW1P8nKcxK8FBNEhn1CFNyCZHfD4O7DqXsDZwbCgcDg3gQPO1+RL3Te1Ez5ZOsSpXtT4MOXZJ83lBRcN+YSQlaJ/kL/O6R7ipO5iRH92hu6+iZJTL6KaL67maU/06e+Sup/LcdxEfL9l4uPx+KSR4uHgZrnWNS0NIouS9nhaml5wXmdeNQeAzRRthIni1CgKB7z1o/+65aLa+FPwnOk7pBz/xOrWQZMDq2KvCpXg1cdzMQw2ptxSM2YRwDGIoMCMUIoowSacvtNILjwjIZFR3OjYeWBcgw8cTdTqAxDOnUCgjrGGHhKL9Fz/48jbnAs0Lbrdf15YKS8Ro/qi9bOeKEJ51lXmKVd2dy2XmnYzqFModdRza7IpmhjmX2qeNh7u8EEUZJbArxPZZNAuNmWb/j3hHaCwqOxXmeFEtDZNkA/DVQYDbz0yXihq7GcStcUBB23H9PDDyTec05ISC0c6yb17JcHP751t9BIvWlG1F1k7MZAqHmjbhReuCocW6Usk5J6CW8WN/dz/xDgwEhEZn5ElzwUae3G0N1APVFRcxrCJRzSBF2DMpSvc7jotFVE3sg7Kg=
|
25
|
+
|
26
|
+
notifications:
|
27
|
+
email:
|
28
|
+
on_success: change
|
29
|
+
on_failure: always
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Contributing to TFL API Client
|
2
|
+
|
3
|
+
This project started in order to fill a gap in the current offers for gems
|
4
|
+
that provide a programmatic interface to TFL's API.
|
5
|
+
|
6
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to
|
7
|
+
help improve this project.
|
8
|
+
|
9
|
+
Here are some ways in which *you* can contribute:
|
10
|
+
|
11
|
+
* by using prerelease versions
|
12
|
+
* by reporting [bugs][issues]
|
13
|
+
* by suggesting [new features][issues]
|
14
|
+
* by writing or editing documentation
|
15
|
+
* by writing code ( **no patch is too small** : fix typos, add comments, clean up inconsistent whitespace )
|
16
|
+
* by refactoring code
|
17
|
+
* by reviewing code
|
18
|
+
|
19
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
20
|
+
[issues]: https://github.com/LukeHackett/tfl_api_client/issues
|
21
|
+
|
22
|
+
|
23
|
+
## Submitting an Issue
|
24
|
+
|
25
|
+
I utilise the [GitHub issue tracking][issues] to track bugs and features.
|
26
|
+
Before submitting a bug report or feature request, check to make sure it
|
27
|
+
hasn't already been submitted.
|
28
|
+
|
29
|
+
When submitting a bug report, please include a [Gist][] that includes a stack
|
30
|
+
trace and any details that may be necessary to reproduce the bug, including
|
31
|
+
your gem version, Ruby version, and operating system.
|
32
|
+
|
33
|
+
Ideally, a bug report should include a pull request with failing specs.
|
34
|
+
|
35
|
+
[gist]: https://gist.github.com/
|
36
|
+
|
37
|
+
|
38
|
+
## Submitting a Pull Request
|
39
|
+
|
40
|
+
1. [Fork][fork] the [repository][repo].
|
41
|
+
2. [Create a feature branch][branch] using the [gitflow][] naming convention e.g. `feature/my-new-feature`.
|
42
|
+
3. Implement your feature or bug fix.
|
43
|
+
4. Add, commit, and push your changes.
|
44
|
+
5. [Submit a pull request][pr].
|
45
|
+
|
46
|
+
[repo]: https://github.com/LukeHackett/tfl_api_client/tree/master
|
47
|
+
[fork]: https://help.github.com/articles/fork-a-repo/
|
48
|
+
[branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
|
49
|
+
[pr]: https://help.github.com/articles/using-pull-requests/
|
50
|
+
|
51
|
+
[gitflow]: http://danielkummer.github.io/git-flow-cheatsheet/#features
|
52
|
+
|
53
|
+
|
54
|
+
## Notes
|
55
|
+
|
56
|
+
* Please add tests if you changed code. Contributions without tests won't be accepted.
|
57
|
+
* Please don't update the Gem version.
|
58
|
+
|
59
|
+
Inspired by [Middleman-Heroku][middleman] and [Factory Girl][factory_girl].
|
60
|
+
|
61
|
+
[middleman]: https://github.com/middleman/middleman-heroku/blob/master/CONTRIBUTING.md
|
62
|
+
[factory_girl]: https://github.com/thoughtbot/factory_girl/blob/master/CONTRIBUTING.md
|
data/GETTING_STARTED.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Getting Started
|
2
|
+
|
3
|
+
TFL API Client has been designed to be as simple as possible to work with.
|
4
|
+
|
5
|
+
This Getting Started guide will cover basic usage of the gem, however for a
|
6
|
+
more in depth guide, checkout the [docs][docs].
|
7
|
+
|
8
|
+
[docs]: http://www.rubydoc.info/github/LukeHackett/tfl_api_client
|
9
|
+
|
10
|
+
|
11
|
+
## BikePoint
|
12
|
+
|
13
|
+
The bike point interface interacts with the /BikePoint end point upon the
|
14
|
+
TFL API. This end point will return information regarding the [Santander
|
15
|
+
Cycle hire][cycle_hire] docking stations, including 5 minute real-time bike
|
16
|
+
and docking station status information.
|
17
|
+
|
18
|
+
[cycle_hire]: https://tfl.gov.uk/modes/cycling/santander-cycles
|
19
|
+
|
20
|
+
|
21
|
+
### Obtain an individual BikePoint
|
22
|
+
|
23
|
+
Information upon an individual BikePoint can be obtained using the location
|
24
|
+
method, whilst also passing the ID of the BikePoint.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
client = TflApi::Client.new(app_id: YOUR_TFL_APP_ID, app_key: YOUR_TFL_APP_KEY)
|
28
|
+
client.bike_point.location
|
29
|
+
|
30
|
+
=> {
|
31
|
+
"id":"BikePoints_10",
|
32
|
+
"url": "https://api-prod5.tfl.gov.uk/Place/BikePoints_10",
|
33
|
+
"commonName": "Park Street, Bankside",
|
34
|
+
"placeType": "BikePoint",
|
35
|
+
"additionalProperties": [],
|
36
|
+
"children":[],
|
37
|
+
"childrenUrls": [],
|
38
|
+
"lat":51.505974,
|
39
|
+
"lon":-0.092754
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
### Obtain all BikePoint locations
|
44
|
+
|
45
|
+
In order to obtain all BikePoint locations and their details the `locations`
|
46
|
+
method can be used.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client = TflApi::Client.new(app_id: YOUR_TFL_APP_ID, app_key: YOUR_TFL_APP_KEY)
|
50
|
+
client.bike_point.locations
|
51
|
+
|
52
|
+
=> [
|
53
|
+
{
|
54
|
+
"id":"BikePoints_10",
|
55
|
+
"url": "https://api-prod5.tfl.gov.uk/Place/BikePoints_10",
|
56
|
+
"commonName": "Park Street, Bankside",
|
57
|
+
"placeType": "BikePoint",
|
58
|
+
"additionalProperties": [],
|
59
|
+
"children":[],
|
60
|
+
"childrenUrls": [],
|
61
|
+
"lat":51.505974,
|
62
|
+
"lon":-0.092754
|
63
|
+
},
|
64
|
+
...
|
65
|
+
// Additional Locations
|
66
|
+
...
|
67
|
+
]
|
68
|
+
```
|
69
|
+
|
70
|
+
|
71
|
+
### Obtain all BikePoint locations within a locus
|
72
|
+
|
73
|
+
In order to obtain all BikePoint locations within a given locus the
|
74
|
+
`locations_within_locus` method should be used. In this context, a locus is a
|
75
|
+
particular position given by the longitude and latitude values with an area
|
76
|
+
that is calculated in accordance to the given radius in metres.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
client = TflApi::Client.new(app_id: YOUR_TFL_APP_ID, app_key: YOUR_TFL_APP_KEY)
|
80
|
+
client.bike_point.locations_within_locus(51.5007292, -0.1246254, 500)
|
81
|
+
|
82
|
+
=> {
|
83
|
+
"centrePoint": [
|
84
|
+
51.5, -0.124
|
85
|
+
],
|
86
|
+
"places": [
|
87
|
+
{
|
88
|
+
"additionalProperties": [],
|
89
|
+
"children": [],
|
90
|
+
"commonName": "Abingdon Green, Westminster",
|
91
|
+
"distance": 298.0259124357908,
|
92
|
+
"id": "BikePoints_583",
|
93
|
+
"lat": 51.497622,
|
94
|
+
"lon": -0.125978,
|
95
|
+
"placeType": "BikePoint",
|
96
|
+
"url": "https://api-prod6.tfl.gov.uk/Place/BikePoints_583",
|
97
|
+
}
|
98
|
+
...
|
99
|
+
// Additional Locations
|
100
|
+
...
|
101
|
+
]
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
### Obtain all BikePoint locations within a bounding box
|
107
|
+
|
108
|
+
In order to obtain all BikePoint locations within a given square the
|
109
|
+
`locations_within_bounding_box` method should be used. Each of the coordinate
|
110
|
+
pairs are used to draw a bounding box, to which all BikePoint locations within
|
111
|
+
the box are returned.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
client = TflApi::Client.new(app_id: YOUR_TFL_APP_ID, app_key: YOUR_TFL_APP_KEY)
|
115
|
+
client.bike_point.locations_within_bounding_box(51.5138453, -0.0983506, 51.5007292, -0.1246254)
|
116
|
+
|
117
|
+
=> [
|
118
|
+
{
|
119
|
+
"additionalProperties": [],
|
120
|
+
"children": [],
|
121
|
+
"commonName": "Godliman Street, St. Paul's",
|
122
|
+
"id": "BikePoints_48",
|
123
|
+
"lat": 51.512484,
|
124
|
+
"lon": -0.099141,
|
125
|
+
"placeType": "BikePoint",
|
126
|
+
"url": "https://api-prod6.tfl.gov.uk/Place/BikePoints_48"
|
127
|
+
}
|
128
|
+
...
|
129
|
+
// Additional Locations
|
130
|
+
...
|
131
|
+
]
|
132
|
+
```
|
133
|
+
|
134
|
+
|
135
|
+
### Search for a given BikePoint location
|
136
|
+
|
137
|
+
The TFL API supports searching for BikePoint locations and will search within
|
138
|
+
the "commonName" field. To search for a given location the `search` method
|
139
|
+
accepts a query String.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
client = TflApi::Client.new(app_id: YOUR_TFL_APP_ID, app_key: YOUR_TFL_APP_KEY)
|
143
|
+
client.bike_point.search("St. James's")
|
144
|
+
|
145
|
+
=> [
|
146
|
+
{
|
147
|
+
"id": "BikePoints_160",
|
148
|
+
"url": "https: //api-prod6.tfl.gov.uk/Place/BikePoints_160",
|
149
|
+
"commonName": "Waterloo Place, St. James's",
|
150
|
+
"placeType": "BikePoint",
|
151
|
+
"additionalProperties": [],
|
152
|
+
"children": [],
|
153
|
+
"childrenUrls": [],
|
154
|
+
"lat": 51.506633,
|
155
|
+
"lon": -0.131773
|
156
|
+
}
|
157
|
+
...
|
158
|
+
// Additional Locations
|
159
|
+
...
|
160
|
+
]
|
161
|
+
```
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Luke Hackett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Transport for London API Client
|
2
|
+
|
3
|
+
This gem aims to provide a simple, programmatic ruby client that allows
|
4
|
+
native ruby applications to seamlessly interact with Transport for
|
5
|
+
London's live APIs.
|
6
|
+
|
7
|
+
[](https://travis-ci.org/LukeHackett/tfl_api_client)
|
8
|
+
[](https://gemnasium.com/LukeHackett/tfl_api_client)
|
9
|
+
[](https://codeclimate.com/github/LukeHackett/tfl_api_client)
|
10
|
+
[](https://coveralls.io/github/LukeHackett/tfl_api_client?branch=master)
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'tfl_api_client'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then install via bundler:
|
22
|
+
|
23
|
+
$ bundle install
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install tfl_api_client
|
28
|
+
|
29
|
+
|
30
|
+
### Supported Ruby Versions
|
31
|
+
|
32
|
+
The TFL API Client supports Ruby 2.0.0 or higher.
|
33
|
+
|
34
|
+
Ruby 1.9.3 is currently not supported, but will be supported in future
|
35
|
+
iterations of the gem.
|
36
|
+
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Checkout the [Getting Started][getting_started] guide.
|
41
|
+
|
42
|
+
[getting_started]: GETTING_STARTED.md
|
43
|
+
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Check out [CONTRIBUTING.md][contributing] for more information upon
|
48
|
+
contributing.
|
49
|
+
|
50
|
+
The TFL API Client gem was originally developed by
|
51
|
+
[Luke Hackett][luke_hackett], and is not an official TFL client.
|
52
|
+
|
53
|
+
[contributing]: CONTRIBUTING.md
|
54
|
+
[luke_hackett]: http://www.lukehackett.com
|
55
|
+
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
Transport for London API Client is released under the [MIT License][license].
|
60
|
+
|
61
|
+
[licence]: http://www.opensource.org/licenses/MIT
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yard'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
|
6
|
+
task default: %w(clean test)
|
7
|
+
|
8
|
+
desc "Removes all non-essential project files and folders"
|
9
|
+
task :clean do
|
10
|
+
FileUtils.rm_rf 'coverage'
|
11
|
+
FileUtils.rm_rf '.yardoc'
|
12
|
+
FileUtils.rm_rf 'doc'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Runs the project's entire test suite"
|
16
|
+
RSpec::Core::RakeTask.new(:test) do |spec|
|
17
|
+
spec.pattern = FileList['spec/*/*.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :test do
|
21
|
+
desc "Runs the project's unit tests"
|
22
|
+
RSpec::Core::RakeTask.new(:unit) do |spec|
|
23
|
+
spec.pattern = FileList['spec/unit/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Runs the project's integration tests"
|
27
|
+
RSpec::Core::RakeTask.new(:integration) do |spec|
|
28
|
+
spec.pattern = FileList['spec/integration/*_spec.rb']
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2015 Luke Hackett
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#
|
25
|
+
|
26
|
+
|
27
|
+
module TflApi
|
28
|
+
class Client
|
29
|
+
# This class communicates with the TFL "/BikePoint" API to obtain details
|
30
|
+
# about bike points locations based upon their IDs or by their latitude
|
31
|
+
# and longitude values.
|
32
|
+
#
|
33
|
+
class BikePoint
|
34
|
+
|
35
|
+
# Initialize the BikePoint object and store the reference to Client object
|
36
|
+
#
|
37
|
+
# @param client [Client] the client object
|
38
|
+
#
|
39
|
+
# @return [BikePoint] the BikePoint object
|
40
|
+
#
|
41
|
+
def initialize(client)
|
42
|
+
@client = client
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns all BikePoint locations known by the TFL service
|
46
|
+
#
|
47
|
+
# @return [Array] An array of hashes containing all BikePoints and their details
|
48
|
+
#
|
49
|
+
def locations
|
50
|
+
@client.get('/BikePoint')
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the all details known by the TFL service for the given
|
54
|
+
# BikePoint id.
|
55
|
+
#
|
56
|
+
# @param id [String] the TFL BikePoint id
|
57
|
+
#
|
58
|
+
# @return [hash] A hash containing the details of the given BikePoint
|
59
|
+
#
|
60
|
+
def location(id)
|
61
|
+
@client.get("/BikePoint/#{id}")
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns all BikePoint locations known by the TFL service within a
|
65
|
+
# particular position or place (a locus).
|
66
|
+
#
|
67
|
+
# @param latitude [String] the latitude value
|
68
|
+
# @param longitude [String] the longitude value
|
69
|
+
# @param radius [String] the radius of the area to cover
|
70
|
+
#
|
71
|
+
# @return [Array] An array of hashes containing all BikePoints and their details
|
72
|
+
#
|
73
|
+
def locations_within_locus(latitude, longitude, radius)
|
74
|
+
uri_params = { lat: latitude, lon: longitude, radius: radius }
|
75
|
+
@client.get('/BikePoint', uri_params)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns all BikePoint locations known by the TFL service within a the given
|
79
|
+
# box based upon it's defined corner locations.
|
80
|
+
#
|
81
|
+
# @param sw_latitude [String] the south-west latitude positional value of the bounding box
|
82
|
+
# @param sw_longitude [String] the south-west longitude positional value of the bounding box
|
83
|
+
# @param ne_latitude [String] the north-east latitude positional value of the bounding box
|
84
|
+
# @param ne_longitude [String] the north-east longitude positional value of the bounding box
|
85
|
+
#
|
86
|
+
# @return [Array] An array of hashes containing all BikePoints and their details
|
87
|
+
#
|
88
|
+
def locations_within_bounding_box(sw_latitude, sw_longitude, ne_latitude, ne_longitude)
|
89
|
+
uri_params = { swLat: sw_latitude, swLon: sw_longitude, neLat: ne_latitude, neLon: ne_longitude }
|
90
|
+
@client.get('/BikePoint', uri_params)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns all BikePoint locations known by the TFL service within based upon
|
94
|
+
# the given search query.
|
95
|
+
#
|
96
|
+
# @param query [String] the query term to search for
|
97
|
+
#
|
98
|
+
# @return [Array] An array of hashes containing all BikePoints and their details
|
99
|
+
#
|
100
|
+
def search(query)
|
101
|
+
@client.get('/BikePoint/Search', { query: query })
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|