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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71bc610a691f498af1e64c506af3e9feb243a57a
4
- data.tar.gz: b7288a68dac615ec55f7b00b5b156adc1cf649df
3
+ metadata.gz: a0f2dc3dc4aa57ce91c3701aa899733408a44c8c
4
+ data.tar.gz: 94904f848e313f2c57ab7505618fee2493d17dbb
5
5
  SHA512:
6
- metadata.gz: 5bb87668fbc62c30b59c3e5742276933dba444b790dcbb9abe487ed12aea3e3a96d102e3a6656b5bc786e745e0a9c61583061d5f8323aef7b01d2bf610f453d4
7
- data.tar.gz: eb362163b28ec7ef909eaec05a5a480a363b3082fd5b5fa417fd503adc73f7d2c01fc158338b018236649a0ed42e5cfa5cf10ea69f24dcafebfb17b593f6fd79
6
+ metadata.gz: ea42bff16df76c9664a574d7143cbc755b24f55010b8c020789569be8496a68fec0ee1bc196391c9531dd896bab2cf73944ef997a927efa6bdf13de6815c88ac
7
+ data.tar.gz: 8d71b7e6459de9a8c9e00d098a2371b1d206651bb450764a620620e8da4208aa8c2555ce979289d8bd4eea8605be85812b1ed9887423465e86711632e107a3bf
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ Version 0.0.1: Intial Frizzle gem is released
2
+ Version 0.0.2: Fixed README formatting for RubyDoc.info
3
+ Version 0.1.0: The default geo radius can now be changed
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. 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.
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
- ##### Examples:
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
- ##### Examples:
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
- ###### Examples:
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
- ###### Examples:
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
- ###### Examples:
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
- ###### Examples:
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
- def self.agencies
20
- Frizzle::Agencies
21
- end
20
+ def agencies
21
+ Frizzle::Agencies
22
+ end
22
23
 
23
- def self.segments
24
- Frizzle::Segments
25
- end
24
+ def segments
25
+ Frizzle::Segments
26
+ end
26
27
 
27
- def self.routes
28
- Frizzle::Routes
29
- end
28
+ def routes
29
+ Frizzle::Routes
30
+ end
30
31
 
31
- def self.stops
32
- Frizzle::Stops
33
- end
32
+ def stops
33
+ Frizzle::Stops
34
+ end
34
35
 
35
- def self.vehicles
36
- Frizzle::Vehicles
37
- end
36
+ def vehicles
37
+ Frizzle::Vehicles
38
+ end
38
39
 
39
- def self.arrival_estimates
40
- Frizzle::ArrivalEstimates
41
- end
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
@@ -1,32 +1,34 @@
1
1
  module Frizzle
2
2
  class Agencies < Base
3
+ class << self
3
4
 
4
- def self.all
5
- fetch("/agencies.json")
6
- end
5
+ def all
6
+ fetch("/agencies.json")
7
+ end
7
8
 
8
- def self.find(options={})
9
- fetch("/agencies.json",
10
- :query => options )
11
- end
9
+ def find(options={})
10
+ fetch("/agencies.json",
11
+ :query => options )
12
+ end
12
13
 
13
- def self.find_by_id(agencies)
14
- fetch("/agencies.json",
15
- :query => { :agencies => formatted_list(agencies) })
16
- end
14
+ def find_by_id(agencies)
15
+ fetch("/agencies.json",
16
+ :query => { :agencies => formatted_list(agencies) })
17
+ end
17
18
 
18
- def self.find_by_geo_area(geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
19
- fetch("/agencies.json",
20
- :query => { :geo_area => formatted_geo_area(geo_area_first, geo_area_second) })
21
- end
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
- def self.find_by_id_and_geo_area(agencies, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
24
- fetch("/agencies.json",
25
- :query => {
26
- :agencies => formatted_list(agencies),
27
- :geo_area => formatted_geo_area(geo_area_first, geo_area_second)
28
- })
29
- end
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
- def self.find(options={})
5
- fetch("/arrival-estimates.json",
6
- :query => options )
7
- end
5
+ def find(options={})
6
+ fetch("/arrival-estimates.json",
7
+ :query => options )
8
+ end
8
9
 
9
- # 168,275
10
- def self.find_by_agencies(agencies)
11
- fetch("/arrival-estimates.json",
12
- :query => { :agencies => formatted_list(agencies) })
13
- end
10
+ def find_by_agencies(agencies)
11
+ fetch("/arrival-estimates.json",
12
+ :query => { :agencies => formatted_list(agencies) })
13
+ end
14
14
 
15
- def self.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
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
- def self.find_by_agencies_and_routes_and_stops(agencies, routes, stops)
32
- fetch("/arrival-estimates.json",
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
- end
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
- def self.init_settings(options={})
12
- {
13
- :headers => {
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
- def self.fetch(url, options = {})
22
- options = self.init_settings(options)
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
- def self.is_numeric?(obj)
34
- obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
35
- end
18
+ def default_geo_radius
19
+ @default_geo_radius || Frizzle::Base.default_geo_radius
20
+ end
36
21
 
37
- def self.formatted_list(list)
38
- if list.instance_of? Array
39
- list = list.join(',')
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
- # Rectangle form: http://api.transloc.com/1.2/agencies.json?geo_area=35.80176,-78.64347|35.78061,-78.68218
45
- # Point and radius form: http://api.transloc.com/1.2/agencies.json?geo_area=35.80176,-78.64347|75.5
46
- def self.formatted_geo_area(first_geo, second_geo=DEFAULT_GEO_RADIUS)
47
- if first_geo.instance_of?(Array) && second_geo.instance_of?(Array)
48
- coordinates = "#{first_geo.join(',')}|#{second_geo.join(',')}"
49
- elsif first_geo.instance_of?(Array) && is_numeric?(second_geo)
50
- coordinates = "#{first_geo.join(',')}|#{second_geo}"
51
- else
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
@@ -1,23 +1,25 @@
1
1
  module Frizzle
2
2
  class Routes < Base
3
+ class << self
3
4
 
4
- def self.find(options={})
5
- fetch("/routes.json",
6
- :query => options )
7
- end
5
+ def find(options={})
6
+ fetch("/routes.json",
7
+ :query => options )
8
+ end
8
9
 
9
- def self.find_by_agencies(agencies)
10
- fetch("/routes.json",
11
- :query => { :agencies => formatted_list(agencies) })
12
- end
10
+ def find_by_agencies(agencies)
11
+ fetch("/routes.json",
12
+ :query => { :agencies => formatted_list(agencies) })
13
+ end
13
14
 
14
- def self.find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
15
- fetch("/routes.json",
16
- :query => {
17
- :agencies => formatted_list(agencies),
18
- :geo_area => formatted_geo_area(geo_area_first, geo_area_second)
19
- })
20
- end
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
@@ -1,31 +1,33 @@
1
1
  module Frizzle
2
2
  class Segments < Base
3
+ class << self
3
4
 
4
- def self.find(options={})
5
- fetch("/segments.json",
6
- :query => options )
7
- end
5
+ def find(options={})
6
+ fetch("/segments.json",
7
+ :query => options )
8
+ end
8
9
 
9
- def self.find_by_agencies(agencies)
10
- fetch("/segments.json",
11
- :query => { :agencies => formatted_list(agencies) })
12
- end
10
+ def find_by_agencies(agencies)
11
+ fetch("/segments.json",
12
+ :query => { :agencies => formatted_list(agencies) })
13
+ end
13
14
 
14
- def self.find_by_agencies_and_routes(agencies, routes)
15
- fetch("/segments.json",
16
- :query => {
17
- :agencies => formatted_list(agencies),
18
- :routes => formatted_list(routes)
19
- })
20
- end
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
- def self.find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
23
- fetch("/segments.json",
24
- :query => {
25
- :agencies => formatted_list(agencies),
26
- :geo_area => formatted_geo_area(geo_area_first, geo_area_second)
27
- })
28
- end
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
- def self.find(options={})
5
- fetch("/stops.json",
6
- :query => options )
7
- end
5
+ def find(options={})
6
+ fetch("/stops.json",
7
+ :query => options )
8
+ end
8
9
 
9
- def self.find_by_agencies(agencies)
10
- fetch("/stops.json",
11
- :query => { :agencies => formatted_list(agencies) })
12
- end
10
+ def find_by_agencies(agencies)
11
+ fetch("/stops.json",
12
+ :query => { :agencies => formatted_list(agencies) })
13
+ end
13
14
 
14
- def self.find_by_agencies_and_geo_area(agencies, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
15
- fetch("/stops.json",
16
- :query => {
17
- :agencies => formatted_list(agencies),
18
- :geo_area => formatted_geo_area(geo_area_first, geo_area_second)
19
- })
20
- end
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
@@ -1,40 +1,42 @@
1
1
  module Frizzle
2
2
  class Vehicles < Base
3
+ class << self
3
4
 
4
- def self.find(options={})
5
- fetch("/vehicles.json",
6
- :query => options )
7
- end
5
+ def find(options={})
6
+ fetch("/vehicles.json",
7
+ :query => options )
8
+ end
8
9
 
9
- def self.find_by_agencies(agencies)
10
- fetch("/vehicles.json",
11
- :query => { :agencies => formatted_list(agencies) })
12
- end
10
+ def find_by_agencies(agencies)
11
+ fetch("/vehicles.json",
12
+ :query => { :agencies => formatted_list(agencies) })
13
+ end
13
14
 
14
- def self.find_by_agencies_and_routes(agencies, routes)
15
- fetch("/vehicles.json",
16
- :query => {
17
- :agencies => formatted_list(agencies),
18
- :routes => formatted_list(routes)
19
- })
20
- end
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
- def self.find_by_agencies_and_routes_and_geo_area(agencies, routes, geo_area_first, geo_area_second=Frizzle::Base::DEFAULT_GEO_RADIUS)
31
- fetch("/vehicles.json",
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
- end
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
@@ -1,3 +1,3 @@
1
1
  module Frizzle
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,7 +3,7 @@ require_relative '../../spec_helper'
3
3
  describe Frizzle::VERSION do
4
4
 
5
5
  it "must be the correct Gem version" do
6
- Frizzle::VERSION.must_equal "0.0.1"
6
+ Frizzle::VERSION.must_equal "0.1.0"
7
7
  end
8
8
 
9
9
  end
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.2
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-02 00:00:00.000000000 Z
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