Class: ListingcheckApi::Client

Inherits:
Object
  • Object
show all
Includes:
APISmith::Client
Defined in:
lib/listingcheck_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Options:

  • :auth_token - Your ListingCheck Authentication token (API)

  • :version - Version (defaults to 1)

  • :base_uri - Set if you want to use development version



86
87
88
89
90
91
92
93
94
# File 'lib/listingcheck_api.rb', line 86

def initialize(options = {})
  @auth_token = options[:auth_token]
  @version = options[:version] || '1'

  self.class.base_uri(options[:base_uri] || 'api.listingcheck.com')
  self.class.endpoint("api/v#{version}")

  add_query_options!(:auth_token => auth_token)
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



80
81
82
# File 'lib/listingcheck_api.rb', line 80

def auth_token
  @auth_token
end

#versionObject (readonly)

Returns the value of attribute version.



80
81
82
# File 'lib/listingcheck_api.rb', line 80

def version
  @version
end

Instance Method Details

#check_response_errors(response) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/listingcheck_api.rb', line 127

def check_response_errors(response)
  # In 2XX range is success otherwise it's probably error (3XX redirects range is handled by HTTParty).
  # In case of error we lookup error class or default to ApiError.
  if not (200..299).include?(response.code)
    raise "Got HTTP code #{response.code} (#{response.message}) from API."
  end

  # Check JSON for error
  # if response.parsed_response.is_a?(Hash) and (error = response.parsed_response['error'])
  #   raise error
  # end
end

#create_listing(type, uid) ⇒ Object

Gets or creates a new Listing of a particular type.



118
119
120
# File 'lib/listingcheck_api.rb', line 118

def create_listing(type, uid)
  self.put("listing_types/#{type}/listings/#{uid}.json", :transform => Listing)
end

#create_scan(scan) ⇒ Object

Creates a new Scan. Requires a associated Place.



102
103
104
# File 'lib/listingcheck_api.rb', line 102

def create_scan(scan)
  self.post('listings_scans.json', {:extra_query => {:listings_scan => scan}, :transform => Scan})
end

#listing(type, uid) ⇒ Object

Gets a existing Listing of a particular type.

listing('facebook_places_listing', 142709532406955)


113
114
115
# File 'lib/listingcheck_api.rb', line 113

def listing(type, uid)
  self.get("listing_types/#{type}/listings/#{uid}.json", :transform => Listing)
end

#perform_scan(access_token) ⇒ Object

Performs a Scan (scans for Listings).



107
108
109
# File 'lib/listingcheck_api.rb', line 107

def perform_scan(access_token)
  self.put("listings_scans/#{access_token}/scan.json", :transform => Scan)
end

#refresh_listing(type, uid) ⇒ Object

Updates an existing Listing of a particular type with the latest info from the API.



123
124
125
# File 'lib/listingcheck_api.rb', line 123

def refresh_listing(type, uid)
  self.put("listing_types/#{type}/listings/#{uid}/refresh.json", :transform => Listing)
end

#scan(access_token) ⇒ Object

Opens a (Listing)Scan.



97
98
99
# File 'lib/listingcheck_api.rb', line 97

def scan(access_token)
  self.get("listings_scans/#{access_token}.json", :transform => Scan)
end