Class: Windy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/windy.rb

Direct Known Subclasses

Collection, PaginatedCollection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/windy.rb', line 26

def initialize
  @connection = Faraday.new(:url => self.class.root) do |builder|
    builder.use SocrataAppTokenMiddleware
    builder.request :json

    # Enable logger output with Windy.debug = true
    if Windy.debug
      builder.response :logger
    end

    builder.adapter :net_http
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



24
25
26
# File 'lib/windy.rb', line 24

def connection
  @connection
end

Class Method Details

.rootObject



20
21
22
# File 'lib/windy.rb', line 20

def self.root
  "http://data.cityofchicago.org"
end

Instance Method Details

#bodyObject



40
41
42
43
44
45
# File 'lib/windy.rb', line 40

def body
  @body ||= connection.get(path) do |request|
    prepare_request(request)
    # warn "Fetching #{request.to_env(@connection)[:url]}"
  end.body
end

#inspectObject



57
58
59
# File 'lib/windy.rb', line 57

def inspect
  "#<#{self.class.name} #{self.class.root}#{path}>"
end

#jsonObject



50
51
52
53
54
55
# File 'lib/windy.rb', line 50

def json
  # For some reason ruby 1.9.x seems to be trying to parse the
  # API JSON output as ASCII instead of UTF-8
  body.force_encoding("UTF-8") unless body.nil?
  @json ||= MultiJson.decode(body)
end

#prepare_request(request) ⇒ Object



47
48
# File 'lib/windy.rb', line 47

def prepare_request(request)
end