Permalink
Browse files

Adding deals endpoint for v2 compliance ⚠️ enpoint still

inconsistent
  • Loading branch information...
baldrailers committed Jul 23, 2012
1 parent 84c984a commit beff7e41f012c44698dde7ca60773fa09cd40e81
View
@@ -8,7 +8,7 @@
module Sqoot
class << self
- attr_accessor :affiliate_token, :authentication_token, :api_url
+ attr_accessor :affiliate_token, :authentication_token, :api_url, :api_version
# Configure default credentials easily
#
@@ -20,7 +20,8 @@ def configure
end
def load_defaults
- self.api_url ||= "http://api.sqoot.com/v1"

This comment has been minimized.

Show comment
Hide comment
@jessedearing

jessedearing Jul 23, 2012

Contributor

Where do we handle adding the v1 to the end of this URL if it's version one? This broke for us in production because we weren't handling the redirect, which goes to https://api.sqoot.com/v1:

GET /v1/offers HTTP/1.1
Host: api.sqoot.com
Accept-Encoding: identity, deflate, compress, gzip
Accept: */*
User-Agent: HTTPie/0.2.5

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Date: Mon, 23 Jul 2012 14:34:22 GMT
Location: https://api.sqoot.com/v1/offers
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Strict-Transport-Security: max-age=31536000
X-Rack-Cache: miss
Content-Length: 0
Connection: keep-alive
@jessedearing

jessedearing Jul 23, 2012

Contributor

Where do we handle adding the v1 to the end of this URL if it's version one? This broke for us in production because we weren't handling the redirect, which goes to https://api.sqoot.com/v1:

GET /v1/offers HTTP/1.1
Host: api.sqoot.com
Accept-Encoding: identity, deflate, compress, gzip
Accept: */*
User-Agent: HTTPie/0.2.5

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Date: Mon, 23 Jul 2012 14:34:22 GMT
Location: https://api.sqoot.com/v1/offers
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Strict-Transport-Security: max-age=31536000
X-Rack-Cache: miss
Content-Length: 0
Connection: keep-alive

This comment has been minimized.

Show comment
Hide comment
@baldrailers

baldrailers Jul 23, 2012

Contributor

It's here: 4855a9b

@baldrailers

baldrailers Jul 23, 2012

Contributor

It's here: 4855a9b

This comment has been minimized.

Show comment
Hide comment
@jessedearing

jessedearing Jul 23, 2012

Contributor

I don't see /v1 there.

@jessedearing

jessedearing Jul 23, 2012

Contributor

I don't see /v1 there.

This comment has been minimized.

Show comment
Hide comment
@baldrailers

baldrailers Jul 23, 2012

Contributor

With faraday the /v1 after the .com is not being respected. So when doing a request if using blocks you need to add that per request /v1/offers or /v2/deals

That's the reason why i removed the /v1 there.

@baldrailers

baldrailers Jul 23, 2012

Contributor

With faraday the /v1 after the .com is not being respected. So when doing a request if using blocks you need to add that per request /v1/offers or /v2/deals

That's the reason why i removed the /v1 there.

+ self.api_url ||= "http://api.sqoot.com"
+ self.api_version ||= 2
end
end
View
@@ -4,6 +4,7 @@
require "sqoot/provider"
require "sqoot/commission"
require "sqoot/click"
+require "sqoot/deal"
require "sqoot/request"
require "sqoot/response/parse_gzip"
@@ -17,13 +18,15 @@ class Client
include Commission
include Click
include Request
+ include Deal
- attr_reader :affiliate_token, :authentication_token, :api_url
+ attr_reader :affiliate_token, :authentication_token, :api_url, :api_version
def initialize(options={})
@affiliate_token = options[:affiliate_token] || Sqoot.affiliate_token
@authentication_token = options[:authentication_token] || Sqoot.authentication_token
@api_url = options[:api_url] || Sqoot.api_url
+ @api_version = options[:api_version] || Sqoot.api_version
end
# Raw HTTP connection with Faraday::Connection
View
@@ -0,0 +1,16 @@
+module Sqoot
+ module Deal
+
+ # Retrieve a list of deals based on the following parameters
+ #
+ # @param [String] query (Search deals by title, description, fine print, merchant name, provider, and category.)
+ # @param [String] location (Limit results to a particular area. We'll resolve whatever you pass us (including an IP address) to coordinates and search near there.)
+ # @param [Integer] radius (Measured in miles. Defaults to 10.)
+ # @param [Integer] page (Which page of result to return. Default to 1.)
+ # @param [Integer] per_page (Number of results to return at once. Defaults to 10.)
+ def deals(options={})
+ get('/v2/deals', options)
+ end
+
+ end
+end
View
@@ -7,11 +7,19 @@ def get(path, options)
def convert_params(path, data={})
auth_endpoints = ['commissions', 'clicks']
+ private_beta_endpoints = ['deals', 'merchants']
if auth_endpoints.include? path.split('/')[2]
data['authentication_token'] = authentication_token
else
- data['affiliate_token'] = affiliate_token
+ # TODO:
+ # Temporary provisioned filter until
+ # v2 is publicly available
+ if private_beta_endpoints.include? path.split('/')[2]
+ data['api_key'] = affiliate_token
+ else
+ data['affiliate_token'] = affiliate_token
+ end
end
data

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit beff7e4

Please sign in to comment.