Class: Windy::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/windy.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/windy.rb', line 37
def initialize
@connection = Faraday.new(:url => self.class.root) do |builder|
builder.use SocrataAppTokenMiddleware
builder.use Windy::Response::RaiseClientError
builder.request :json
if Windy.debug
builder.response :logger
end
builder.adapter :net_http
end
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
35
36
37
|
# File 'lib/windy.rb', line 35
def connection
@connection
end
|
Class Method Details
.root ⇒ Object
31
32
33
|
# File 'lib/windy.rb', line 31
def self.root
"http://data.cityofchicago.org"
end
|
Instance Method Details
#body ⇒ Object
52
53
54
55
56
57
|
# File 'lib/windy.rb', line 52
def body
@body ||= connection.get(path) do |request|
prepare_request(request)
end.body
end
|
#inspect ⇒ Object
69
70
71
|
# File 'lib/windy.rb', line 69
def inspect
"#<#{self.class.name} #{self.class.root}#{path}>"
end
|
#json ⇒ Object
62
63
64
65
66
67
|
# File 'lib/windy.rb', line 62
def json
body.force_encoding("UTF-8") unless body.nil? || !body.respond_to?(:force_encoding)
@json ||= MultiJson.decode(body)
end
|
#prepare_request(request) ⇒ Object
59
60
|
# File 'lib/windy.rb', line 59
def prepare_request(request)
end
|