Class: Frizzle::Base
- Inherits:
-
Object
show all
- Includes:
- HTTParty, Singleton
- Defined in:
- lib/frizzle/base.rb
Constant Summary
collapse
- API_VERSION =
"1.2".freeze
Class Method Summary
collapse
Class Method Details
.default_geo_radius ⇒ Object
18
19
20
|
# File 'lib/frizzle/base.rb', line 18
def default_geo_radius
@default_geo_radius || Frizzle::Base.default_geo_radius
end
|
.default_geo_radius=(radius) ⇒ Object
14
15
16
|
# File 'lib/frizzle/base.rb', line 14
def default_geo_radius=(radius)
@default_geo_radius = radius
end
|
.fetch(url, options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/frizzle/base.rb', line 32
def fetch(url, options = {})
options = self.init_settings(options)
response = get(url, options)
if response.success?
response.parsed_response['data']
elsif response.code == 403
raise "TransLoc API limit: #{response.response}"
else
raise TransLocAPIError.new, "#{response}"
end
end
|
55
56
57
58
59
60
|
# File 'lib/frizzle/base.rb', line 55
def formatted_geo_area(first_geo, second_geo=nil)
return "#{first_geo.join(',')}|#{second_geo.join(',')}" if first_geo.instance_of?(Array) && second_geo.instance_of?(Array)
return "#{first_geo.join(',')}|#{second_geo}" if first_geo.instance_of?(Array) && !second_geo.nil?
return "#{first_geo.join(',')}|#{self.default_geo_radius}" if first_geo.instance_of?(Array) && second_geo.nil?
raise(ArgumentError, "Geo arguments do not match the required format")
end
|
48
49
50
51
52
53
|
# File 'lib/frizzle/base.rb', line 48
def formatted_list(list)
if list.instance_of? Array
list = list.join(',')
end
list.to_s
end
|
.init_settings(options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/frizzle/base.rb', line 22
def init_settings(options={})
{
:headers => {
"User-Agent" => "frizzle-ruby-#{Frizzle::VERSION}",
"Content-Type" => "application/json",
"Accept" => "application/json"
}
}.deep_merge(options)
end
|
.is_numeric?(obj) ⇒ Boolean
44
45
46
|
# File 'lib/frizzle/base.rb', line 44
def is_numeric?(obj)
obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
end
|