Class: ListingcheckApi::Client
- Inherits:
-
Object
- Object
- ListingcheckApi::Client
- Includes:
- APISmith::Client
- Defined in:
- lib/listingcheck_api.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #check_response_errors(response) ⇒ Object
-
#create_listing(type, uid) ⇒ Object
Gets or creates a new Listing of a particular type.
-
#create_scan(scan) ⇒ Object
Creates a new Scan.
-
#initialize(options = {}) ⇒ Client
constructor
Options: * :auth_token - Your ListingCheck Authentication token (API) * :version - Version (defaults to 1) * :base_uri - Set if you want to use development version.
-
#listing(type, uid) ⇒ Object
Gets a existing Listing of a particular type.
-
#perform_scan(access_token) ⇒ Object
Performs a Scan (scans for Listings).
-
#refresh_listing(type, uid) ⇒ Object
Updates an existing Listing of a particular type with the latest info from the API.
-
#scan(access_token) ⇒ Object
Opens a (Listing)Scan.
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( = {}) @auth_token = [:auth_token] @version = [:version] || '1' self.class.base_uri([:base_uri] || 'api.listingcheck.com') self.class.endpoint("api/v#{version}") (:auth_token => auth_token) end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
80 81 82 |
# File 'lib/listingcheck_api.rb', line 80 def auth_token @auth_token end |
#version ⇒ Object (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.}) 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 |