Skip to content
Browse files

Adding deals endpoint for v2 compliance :warning: enpoint still

inconsistent
  • Loading branch information...
1 parent 84c984a commit beff7e41f012c44698dde7ca60773fa09cd40e81 @baldrailers baldrailers committed Jul 23, 2012
View
5 lib/sqoot.rb
@@ -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"
@jessedearing
jessedearing added a note Jul 23, 2012

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
@baldrailers
baldrailers added a note Jul 23, 2012

It's here: 4855a9b

@jessedearing
jessedearing added a note Jul 23, 2012

I don't see /v1 there.

@baldrailers
baldrailers added a note Jul 23, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ self.api_url ||= "http://api.sqoot.com"
+ self.api_version ||= 2
end
end
View
5 lib/sqoot/client.rb
@@ -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
16 lib/sqoot/deal.rb
@@ -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
10 lib/sqoot/request.rb
@@ -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
View
195 spec/cassettes/Sqoot_Deal/should_return_mash_list_of_deals_given_location_parameter.yml
@@ -0,0 +1,195 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Sun, 22 Jul 2012 11:36:09 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?location=444%20Castro%20St.%20Mountain%20View&api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:09 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Sun, 22 Jul 2012 11:36:15 GMT
+ etag:
+ - ! '"229c08a89dbf8f4292a636f3254a99b6"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - 5f33ae8a0cf90a96d3abf0a7a55121ed
+ x-runtime:
+ - '0.180222'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '236'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":10,"location":{"address":"444
+ Castro St","locality":"Mountain View","region":"CA","postal_code":"94041-2008","country":"United
+ States","latitude":37.390751,"longitude":-122.080953}},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:15 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Mon, 23 Jul 2012 06:38:25 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?location=444%20Castro%20St.%20Mountain%20View&api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:25 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Mon, 23 Jul 2012 06:38:29 GMT
+ etag:
+ - ! '"229c08a89dbf8f4292a636f3254a99b6"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - e650fe1158cd833e373e912e81721818
+ x-runtime:
+ - '0.413365'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '236'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":10,"location":{"address":"444
+ Castro St","locality":"Mountain View","region":"CA","postal_code":"94041-2008","country":"United
+ States","latitude":37.390751,"longitude":-122.080953}},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:29 GMT
+recorded_with: VCR 2.0.1
View
191 .../cassettes/Sqoot_Deal/should_return_mash_list_of_deals_without_passing_any_parameters.yml
@@ -0,0 +1,191 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Sun, 22 Jul 2012 11:36:05 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:05 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Sun, 22 Jul 2012 11:36:08 GMT
+ etag:
+ - ! '"ce252d0cadb0ee52f4ec51cd6da22fbd"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - 1eb9bf85f015bdb55f185fc9184e8afc
+ x-runtime:
+ - '0.121898'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '74'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":10,"location":null},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:08 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Mon, 23 Jul 2012 06:38:20 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:20 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Mon, 23 Jul 2012 06:38:24 GMT
+ etag:
+ - ! '"ce252d0cadb0ee52f4ec51cd6da22fbd"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - d34d26fcabeb98e5c31767841e5681b8
+ x-runtime:
+ - '0.103374'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '74'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":10,"location":null},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:24 GMT
+recorded_with: VCR 2.0.1
View
191 spec/cassettes/Sqoot_Deal/should_return_per_page_result_passing_per_page_parameter.yml
@@ -0,0 +1,191 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Sun, 22 Jul 2012 11:36:16 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?per_page=3&api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:16 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Sun, 22 Jul 2012 11:36:20 GMT
+ etag:
+ - ! '"d7c9f80781af994a8f28302c26634049"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - 450ca5631dd2e39e0352ea50d1172e59
+ x-runtime:
+ - '0.106570'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '73'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":3,"location":null},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Sun, 22 Jul 2012 11:36:20 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 301
+ message: ! 'Moved Permanently '
+ headers:
+ cache-control:
+ - private
+ content-type:
+ - text/html
+ date:
+ - Mon, 23 Jul 2012 06:38:30 GMT
+ location:
+ - https://api.sqoot.com/v2/deals?per_page=3&api_key=API_KEY
+ 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:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ''
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:31 GMT
+- request:
+ method: get
+ uri: API_KEY
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ authorization: AUTHENTICATION_TOKEN
+ accept:
+ - ! '*/*'
+ accept-encoding:
+ - gzip
+ user-agent:
+ - Ruby gem
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: ! 'OK '
+ headers:
+ cache-control:
+ - must-revalidate, private, max-age=0
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Mon, 23 Jul 2012 06:38:36 GMT
+ etag:
+ - ! '"d7c9f80781af994a8f28302c26634049"'
+ server:
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
+ strict-transport-security:
+ - max-age=31536000
+ x-rack-cache:
+ - miss
+ x-request-id:
+ - ed6b649001a44b5c9308b347aeda8c82
+ x-runtime:
+ - '0.089983'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-length:
+ - '73'
+ connection:
+ - Close
+ body:
+ encoding: US-ASCII
+ string: ! '{"metadata":{"total":0,"page":1,"per_page":3,"location":null},"deals":[]}'
+ http_version: '1.1'
+ recorded_at: Mon, 23 Jul 2012 06:38:36 GMT
+recorded_with: VCR 2.0.1
View
19 spec/sqoot/deal_spec.rb
@@ -0,0 +1,19 @@
+# encoding: utf-8
+require "spec_helper"
+
+describe Sqoot::Deal do
+ let(:client) { Sqoot::Client.new }
+
+ it "should return mash list of deals without passing any parameters", :vcr do
+ client.deals.equal? Hashie::Mash
+ end
+
+ it "should return mash list of deals given location parameter", :vcr do
+ client.deals(:location => "444 Castro St. Mountain View").equal? Hashie::Mash
+ end
+
+ it "should return per_page result passing per_page parameter", :vcr do
+ client.deals(:per_page => 3).per_page == 3
+ end
+
+end
View
6 spec/sqoot_spec.rb
@@ -13,8 +13,12 @@
client.authentication_token == 'authentication_token'
end
+ it "should configure with default v2 for api_version" do
+ client.api_version == 2
+ end
+
it "should use HTTP API endpoint" do
- client.api_url.should == "http://api.sqoot.com/v1"
+ client.api_url.should == "http://api.sqoot.com"
end
end

0 comments on commit beff7e4

Please sign in to comment.
Something went wrong with that request. Please try again.