frizzle 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/README.md +10 -7
- data/lib/frizzle.rb +28 -18
- data/lib/frizzle/agencies.rb +24 -22
- data/lib/frizzle/arrival_estimates.rb +30 -29
- data/lib/frizzle/base.rb +43 -38
- data/lib/frizzle/routes.rb +17 -15
- data/lib/frizzle/segments.rb +24 -22
- data/lib/frizzle/stops.rb +17 -15
- data/lib/frizzle/vehicles.rb +30 -28
- data/lib/frizzle/version.rb +1 -1
- data/spec/lib/frizzle/version_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f2dc3dc4aa57ce91c3701aa899733408a44c8c
|
4
|
+
data.tar.gz: 94904f848e313f2c57ab7505618fee2493d17dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea42bff16df76c9664a574d7143cbc755b24f55010b8c020789569be8496a68fec0ee1bc196391c9531dd896bab2cf73944ef997a927efa6bdf13de6815c88ac
|
7
|
+
data.tar.gz: 8d71b7e6459de9a8c9e00d098a2371b1d206651bb450764a620620e8da4208aa8c2555ce979289d8bd4eea8605be85812b1ed9887423465e86711632e107a3bf
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -43,11 +43,14 @@ The TransLoc API does not require an API key.
|
|
43
43
|
For methods that allow limiting the results with a geographical area filter, there are two form options: *rectangle form* and *point and radius form*.
|
44
44
|
|
45
45
|
To limit with *rectangle form*, pass two arrays ([lat, lng]) for the two geo area arguments. It would look like:
|
46
|
+
|
46
47
|
```ruby
|
47
48
|
Frizzle.agencies.find_by_geo_area([35.80176,-78.64347], [35.78061,-78.68218])
|
48
49
|
```
|
49
50
|
|
50
|
-
To limit with *point and radius*, pass an array ([lat, lng]) to the first argument.
|
51
|
+
To limit with *point and radius*, pass an array ([lat, lng]) to the first argument.
|
52
|
+
|
53
|
+
The second argument is optional and can be used to pass a radius in meters of a circle around the point. If this is not filled out, it will default to 100. If you wish to change the default radius, it can be changed through `Frizzle.default_geo_radius` or set individually by class.
|
51
54
|
|
52
55
|
```ruby
|
53
56
|
Frizzle.agencies.find_by_geo_area([35.80176,-78.64347])
|
@@ -58,7 +61,7 @@ Frizzle.agencies.find_by_geo_area([35.80176,-78.64347], 70)
|
|
58
61
|
|
59
62
|
Agencies can be accessed through `Frizzle.agencies` or `Frizzle::Agencies`. This API call can be requested every 10 seconds from the same IP address.
|
60
63
|
|
61
|
-
|
64
|
+
#### Examples:
|
62
65
|
|
63
66
|
```ruby
|
64
67
|
Frizzle::Agencies.all
|
@@ -76,7 +79,7 @@ Frizzle.agencies.find({:agencies => "12", :geo_area => "35.80176,-78.64347|100"}
|
|
76
79
|
|
77
80
|
Segments can be accessed through `Frizzle.segments` or `Frizzle::Segments`. This API call can be requested every 10 seconds from the same IP address.
|
78
81
|
|
79
|
-
|
82
|
+
#### Examples:
|
80
83
|
|
81
84
|
```ruby
|
82
85
|
Frizzle::Segments.find_by_agencies(24)
|
@@ -93,7 +96,7 @@ Frizzle.segments.find({:agencies => "24"}
|
|
93
96
|
|
94
97
|
Routes can be accessed through `Frizzle.routes` or `Frizzle::Routes`. This API call can be requested every 10 seconds from the same IP address.
|
95
98
|
|
96
|
-
|
99
|
+
#### Examples:
|
97
100
|
|
98
101
|
```ruby
|
99
102
|
Frizzle::Routes.find_by_agencies("24")
|
@@ -107,7 +110,7 @@ Frizzle::Routes.find({:agencies => "24"})
|
|
107
110
|
|
108
111
|
Stops can be accessed through `Frizzle.stops` or `Frizzle::Stops`. This API call can be requested every 10 seconds from the same IP address.
|
109
112
|
|
110
|
-
|
113
|
+
#### Examples:
|
111
114
|
|
112
115
|
```ruby
|
113
116
|
Frizzle::Stops.find_by_agencies(24)
|
@@ -120,7 +123,7 @@ Frizzle::Stops.find({:agencies => "24"})
|
|
120
123
|
|
121
124
|
Vehicles can be accessed through `Frizzle.vehicles` or `Frizzle::Vehicles`. This API call can be requested every 1 second from the same IP address.
|
122
125
|
|
123
|
-
|
126
|
+
#### Examples:
|
124
127
|
|
125
128
|
```ruby
|
126
129
|
Frizzle::Vehicles.find_by_agencies("24")
|
@@ -134,7 +137,7 @@ Frizzle::Vehicles.find({:agencies => "24"})
|
|
134
137
|
|
135
138
|
Arrival estimates can be accessed through `Frizzle.arrival_estimates` or `Frizzle::ArrivalEstimates`. This API call can be requested every 1 second from the same IP address.
|
136
139
|
|
137
|
-
|
140
|
+
#### Examples:
|
138
141
|
|
139
142
|
```ruby
|
140
143
|
Frizzle::ArrivalEstimates.find_by_agencies("24")
|
data/lib/frizzle.rb
CHANGED
@@ -15,29 +15,39 @@ require_relative 'frizzle/vehicles'
|
|
15
15
|
require_relative 'frizzle/arrival_estimates'
|
16
16
|
|
17
17
|
module Frizzle
|
18
|
+
class << self
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def agencies
|
21
|
+
Frizzle::Agencies
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def segments
|
25
|
+
Frizzle::Segments
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def routes
|
29
|
+
Frizzle::Routes
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def stops
|
33
|
+
Frizzle::Stops
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def vehicles
|
37
|
+
Frizzle::Vehicles
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def arrival_estimates
|
41
|
+
Frizzle::ArrivalEstimates
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_geo_radius=(radius)
|
45
|
+
Frizzle::Base.default_geo_radius = radius
|
46
|
+
end
|
42
47
|
|
48
|
+
def default_geo_radius
|
49
|
+
Frizzle::Base.default_geo_radius
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
43
53
|
end
|
data/lib/frizzle/agencies.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class Agencies < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def all
|
6
|
+
fetch("/agencies.json")
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def find(options={})
|
10
|
+
fetch("/agencies.json",
|
11
|
+
:query => options )
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def find_by_id(agencies)
|
15
|
+
fetch("/agencies.json",
|
16
|
+
:query => { :agencies => formatted_list(agencies) })
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def find_by_geo_area(geo_area_first, geo_area_second=nil)
|
20
|
+
fetch("/agencies.json",
|
21
|
+
:query => { :geo_area => formatted_geo_area(geo_area_first, geo_area_second) })
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def find_by_id_and_geo_area(agencies, geo_area_first, geo_area_second=nil)
|
25
|
+
fetch("/agencies.json",
|
26
|
+
:query => {
|
27
|
+
:agencies => formatted_list(agencies),
|
28
|
+
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
29
|
+
})
|
30
|
+
end
|
30
31
|
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
@@ -1,41 +1,42 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class ArrivalEstimates < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def find(options={})
|
6
|
+
fetch("/arrival-estimates.json",
|
7
|
+
:query => options )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
def find_by_agencies(agencies)
|
11
|
+
fetch("/arrival-estimates.json",
|
12
|
+
:query => { :agencies => formatted_list(agencies) })
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def self.find_by_agencies_and_stops(agencies, stops)
|
24
|
-
fetch("/arrival-estimates.json",
|
25
|
-
:query => {
|
26
|
-
:agencies => formatted_list(agencies),
|
27
|
-
:stops => formatted_list(stops)
|
28
|
-
})
|
29
|
-
end
|
15
|
+
def find_by_agencies_and_routes(agencies, routes)
|
16
|
+
fetch("/arrival-estimates.json",
|
17
|
+
:query => {
|
18
|
+
:agencies => formatted_list(agencies),
|
19
|
+
:routes => formatted_list(routes)
|
20
|
+
})
|
21
|
+
end
|
30
22
|
|
31
|
-
|
32
|
-
|
23
|
+
def find_by_agencies_and_stops(agencies, stops)
|
24
|
+
fetch("/arrival-estimates.json",
|
33
25
|
:query => {
|
34
26
|
:agencies => formatted_list(agencies),
|
35
|
-
:routes => formatted_list(routes),
|
36
27
|
:stops => formatted_list(stops)
|
37
|
-
|
38
|
-
|
28
|
+
})
|
29
|
+
end
|
39
30
|
|
31
|
+
def find_by_agencies_and_routes_and_stops(agencies, routes, stops)
|
32
|
+
fetch("/arrival-estimates.json",
|
33
|
+
:query => {
|
34
|
+
:agencies => formatted_list(agencies),
|
35
|
+
:routes => formatted_list(routes),
|
36
|
+
:stops => formatted_list(stops)
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/frizzle/base.rb
CHANGED
@@ -4,55 +4,60 @@ module Frizzle
|
|
4
4
|
include HTTParty
|
5
5
|
|
6
6
|
API_VERSION = "1.2".freeze
|
7
|
-
DEFAULT_GEO_RADIUS = 100
|
8
7
|
|
9
8
|
base_uri "http://api.transloc.com/#{API_VERSION}"
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
"User-Agent" => "frizzle-ruby-#{Frizzle::VERSION}",
|
15
|
-
"Content-Type" => "application/json",
|
16
|
-
"Accept" => "application/json"
|
17
|
-
}
|
18
|
-
}.deep_merge(options)
|
19
|
-
end
|
10
|
+
@default_geo_radius = 100
|
11
|
+
|
12
|
+
class << self
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
response = get(url, options)
|
24
|
-
if response.success?
|
25
|
-
data = response.parsed_response['data']
|
26
|
-
elsif response.code == 403
|
27
|
-
raise "TransLoc API limit: #{response.response}"
|
28
|
-
else
|
29
|
-
raise TransLocAPIError.new, "#{response}"
|
14
|
+
def default_geo_radius=(radius)
|
15
|
+
@default_geo_radius = radius
|
30
16
|
end
|
31
|
-
end
|
32
17
|
|
33
|
-
|
34
|
-
|
35
|
-
|
18
|
+
def default_geo_radius
|
19
|
+
@default_geo_radius || Frizzle::Base.default_geo_radius
|
20
|
+
end
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
def init_settings(options={})
|
23
|
+
{
|
24
|
+
:headers => {
|
25
|
+
"User-Agent" => "frizzle-ruby-#{Frizzle::VERSION}",
|
26
|
+
"Content-Type" => "application/json",
|
27
|
+
"Accept" => "application/json"
|
28
|
+
}
|
29
|
+
}.deep_merge(options)
|
40
30
|
end
|
41
|
-
list.to_s
|
42
|
-
end
|
43
31
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
32
|
+
def fetch(url, options = {})
|
33
|
+
options = self.init_settings(options)
|
34
|
+
response = get(url, options)
|
35
|
+
if response.success?
|
36
|
+
response.parsed_response['data']
|
37
|
+
elsif response.code == 403
|
38
|
+
raise "TransLoc API limit: #{response.response}"
|
39
|
+
else
|
40
|
+
raise TransLocAPIError.new, "#{response}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_numeric?(obj)
|
45
|
+
obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
|
46
|
+
end
|
47
|
+
|
48
|
+
def formatted_list(list)
|
49
|
+
if list.instance_of? Array
|
50
|
+
list = list.join(',')
|
51
|
+
end
|
52
|
+
list.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def formatted_geo_area(first_geo, second_geo=nil)
|
56
|
+
return "#{first_geo.join(',')}|#{second_geo.join(',')}" if first_geo.instance_of?(Array) && second_geo.instance_of?(Array)
|
57
|
+
return "#{first_geo.join(',')}|#{second_geo}" if first_geo.instance_of?(Array) && !second_geo.nil?
|
58
|
+
return "#{first_geo.join(',')}|#{self.default_geo_radius}" if first_geo.instance_of?(Array) && second_geo.nil?
|
52
59
|
raise(ArgumentError, "Geo arguments do not match the required format")
|
53
60
|
end
|
54
|
-
"#{coordinates}"
|
55
61
|
end
|
56
|
-
|
57
62
|
end
|
58
63
|
end
|
data/lib/frizzle/routes.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class Routes < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def find(options={})
|
6
|
+
fetch("/routes.json",
|
7
|
+
:query => options )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def find_by_agencies(agencies)
|
11
|
+
fetch("/routes.json",
|
12
|
+
:query => { :agencies => formatted_list(agencies) })
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=nil)
|
16
|
+
fetch("/routes.json",
|
17
|
+
:query => {
|
18
|
+
:agencies => formatted_list(agencies),
|
19
|
+
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
20
|
+
})
|
21
|
+
end
|
21
22
|
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/frizzle/segments.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class Segments < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def find(options={})
|
6
|
+
fetch("/segments.json",
|
7
|
+
:query => options )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def find_by_agencies(agencies)
|
11
|
+
fetch("/segments.json",
|
12
|
+
:query => { :agencies => formatted_list(agencies) })
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def find_by_agencies_and_routes(agencies, routes)
|
16
|
+
fetch("/segments.json",
|
17
|
+
:query => {
|
18
|
+
:agencies => formatted_list(agencies),
|
19
|
+
:routes => formatted_list(routes)
|
20
|
+
})
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=nil)
|
24
|
+
fetch("/segments.json",
|
25
|
+
:query => {
|
26
|
+
:agencies => formatted_list(agencies),
|
27
|
+
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
28
|
+
})
|
29
|
+
end
|
29
30
|
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/frizzle/stops.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class Stops < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def find(options={})
|
6
|
+
fetch("/stops.json",
|
7
|
+
:query => options )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def find_by_agencies(agencies)
|
11
|
+
fetch("/stops.json",
|
12
|
+
:query => { :agencies => formatted_list(agencies) })
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=nil)
|
16
|
+
fetch("/stops.json",
|
17
|
+
:query => {
|
18
|
+
:agencies => formatted_list(agencies),
|
19
|
+
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
20
|
+
})
|
21
|
+
end
|
21
22
|
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/frizzle/vehicles.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
1
|
module Frizzle
|
2
2
|
class Vehicles < Base
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def find(options={})
|
6
|
+
fetch("/vehicles.json",
|
7
|
+
:query => options )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def find_by_agencies(agencies)
|
11
|
+
fetch("/vehicles.json",
|
12
|
+
:query => { :agencies => formatted_list(agencies) })
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def self.find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
|
23
|
-
fetch("/vehicles.json",
|
24
|
-
:query => {
|
25
|
-
:agencies => formatted_list(agencies),
|
26
|
-
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
27
|
-
})
|
28
|
-
end
|
15
|
+
def find_by_agencies_and_routes(agencies, routes)
|
16
|
+
fetch("/vehicles.json",
|
17
|
+
:query => {
|
18
|
+
:agencies => formatted_list(agencies),
|
19
|
+
:routes => formatted_list(routes)
|
20
|
+
})
|
21
|
+
end
|
29
22
|
|
30
|
-
|
31
|
-
|
23
|
+
def find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=nil)
|
24
|
+
fetch("/vehicles.json",
|
32
25
|
:query => {
|
33
26
|
:agencies => formatted_list(agencies),
|
34
|
-
:routes => formatted_list(routes),
|
35
27
|
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
36
|
-
|
37
|
-
|
28
|
+
})
|
29
|
+
end
|
38
30
|
|
31
|
+
def find_by_agencies_and_routes_and_geo_area(agencies, routes, geo_area_first, geo_area_second=nil)
|
32
|
+
fetch("/vehicles.json",
|
33
|
+
:query => {
|
34
|
+
:agencies => formatted_list(agencies),
|
35
|
+
:routes => formatted_list(routes),
|
36
|
+
:geo_area => formatted_geo_area(geo_area_first, geo_area_second)
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/frizzle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frizzle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- .gitignore
|
133
|
+
- CHANGELOG
|
133
134
|
- Gemfile
|
134
135
|
- LICENSE
|
135
136
|
- README.md
|