Class: Rentjuicer::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rentjuicer/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, http_timeout = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/rentjuicer/client.rb', line 9

def initialize(api_key, http_timeout = nil)
  self.api_key = api_key
  self.http_timeout = http_timeout
  self.class.base_uri "api.rentalapp.zillow.com/#{self.api_key}"
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/rentjuicer/client.rb', line 7

def api_key
  @api_key
end

#http_timeoutObject

Returns the value of attribute http_timeout.



7
8
9
# File 'lib/rentjuicer/client.rb', line 7

def http_timeout
  @http_timeout
end

Instance Method Details

#leadsObject



23
24
25
# File 'lib/rentjuicer/client.rb', line 23

def leads
  @leads ||= Rentjuicer::Lead.new(self)
end

#listingsObject



15
16
17
# File 'lib/rentjuicer/client.rb', line 15

def listings
  @listings ||= Rentjuicer::Listings.new(self)
end

#neighborhoodsObject



19
20
21
# File 'lib/rentjuicer/client.rb', line 19

def neighborhoods
  @neighborhoods ||= Rentjuicer::Neighborhoods.new(self)
end

#process_get(resource, params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rentjuicer/client.rb', line 27

def process_get(resource, params = {})
  begin
    http_params = {}
    unless params.blank?
      http_params[:query] = params
    end
    unless self.http_timeout.nil?
      http_params[:timeout] = self.http_timeout
    end
    self.class.get(resource, http_params)
  rescue Timeout::Error
    {"status" => "timeout", "code" => "0", "message" => "Rentjuice API is timing out."}
  rescue Exception
    {"status" => "busted", "code" => "0", "message" => "Rentjuice API is erroring."}
  end
end