Class: Dillo::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dillo.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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dillo.rb', line 37

def initialize
  @connection = Faraday.new(:url => self.class.root) do |builder|
    builder.use SocrataAppTokenMiddleware
    builder.use Dillo::Response::RaiseClientError
    builder.response :json, :content_type => /\bjson$/

    # Enable logger output with [email protected] = true
    if Dillo.debug
      builder.response :logger
    end

    builder.adapter Faraday.default_adapter 
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



35
36
37
# File 'lib/dillo.rb', line 35

def connection
  @connection
end

Class Method Details

.rootObject



31
32
33
# File 'lib/dillo.rb', line 31

def self.root
  "http://data.austintexas.gov"
end

Instance Method Details

#bodyObject



52
53
54
55
56
57
# File 'lib/dillo.rb', line 52

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

#inspectObject



70
71
72
# File 'lib/dillo.rb', line 70

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

#jsonObject



62
63
64
65
66
67
68
# File 'lib/dillo.rb', line 62

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? || !body.respond_to?(:force_encoding)
  #puts body
  json ||= body
end

#prepare_request(request) ⇒ Object



59
60
# File 'lib/dillo.rb', line 59

def prepare_request(request)
end