viglink-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/Gemfile +10 -0
- data/Guardfile +5 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +119 -0
- data/Rakefile +7 -0
- data/VigLinkCatalogAPIDocumentation.html +129 -0
- data/lib/viglink_api.rb +46 -0
- data/lib/viglink_api/client.rb +56 -0
- data/lib/viglink_api/country.rb +18 -0
- data/lib/viglink_api/deal.rb +67 -0
- data/lib/viglink_api/merchant.rb +45 -0
- data/lib/viglink_api/product.rb +25 -0
- data/lib/viglink_api/purchases.rb +63 -0
- data/lib/viglink_api/request.rb +30 -0
- data/lib/viglink_api/version.rb +3 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/viglink_api/client_spec.rb +11 -0
- data/spec/viglink_api/country_spec.rb +20 -0
- data/spec/viglink_api/deal_spec.rb +104 -0
- data/spec/viglink_api/merchant_spec.rb +104 -0
- data/spec/viglink_api/product_spec.rb +55 -0
- data/spec/viglink_api/purchases_spec.rb +61 -0
- data/spec/viglink_api_spec.rb +17 -0
- data/viglink_api.gemspec +34 -0
- metadata +290 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ViglinkApi
|
4
|
+
module Country
|
5
|
+
|
6
|
+
##
|
7
|
+
# Retrieve the list of supported Countries
|
8
|
+
#
|
9
|
+
# @return [Hashie::Mash] Country
|
10
|
+
def find_countries
|
11
|
+
options = {}
|
12
|
+
options[:key] = @api_key
|
13
|
+
countries_response = get('/vigcatalog/countries.xml', options)
|
14
|
+
countries_response.response if countries_response.response
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ViglinkApi
|
4
|
+
module Deal
|
5
|
+
|
6
|
+
##
|
7
|
+
# Retrieve the list of Deals
|
8
|
+
#
|
9
|
+
# @param :full [Boolean] If set to true|y|yes then this will return
|
10
|
+
# the complete response
|
11
|
+
#
|
12
|
+
# @return [Hashie::Mash] Deal
|
13
|
+
def find_deals(options={})
|
14
|
+
full_response = options.delete(:full) if options[:full]
|
15
|
+
options[:key] = @api_key
|
16
|
+
deals_response = get('/vigcatalog/deals.xml', options)
|
17
|
+
|
18
|
+
if full_response.to_s.to_bool or @api_full_response
|
19
|
+
deals_response.response if deals_response.response
|
20
|
+
else
|
21
|
+
deals_response.response.results.deals if deals_response.response.results
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Retrieve the list of Deal Types
|
27
|
+
#
|
28
|
+
# @param :full [Boolean] If set to true|y|yes then this will return
|
29
|
+
# the complete response
|
30
|
+
#
|
31
|
+
# @return [Hashie::Mash] DealType
|
32
|
+
def find_deal_types(options = {})
|
33
|
+
full_response = options.delete(:full) if options[:full]
|
34
|
+
options[:key] = @api_key
|
35
|
+
deal_types_response = get('/vigcatalog/deal_types.xml', options)
|
36
|
+
|
37
|
+
if full_response.to_s.to_bool or @api_full_response
|
38
|
+
deal_types_response.response if deal_types_response.response
|
39
|
+
else
|
40
|
+
deal_types_response.response.results.deal_types if deal_types_response.response.results
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
=begin
|
48
|
+
Optional search parameters for find_deals
|
49
|
+
|
50
|
+
Param name Type Kind Allowed Values Default Value Description
|
51
|
+
end_on range filter The end on date a deal is still valid for. Pass in a single date for an exact match, or pass in a range of dates delimited with a dash '-'.
|
52
|
+
end_on_max range filter The maximum end on date for a deal.
|
53
|
+
deal_type selection filter The deal type ID a deal belongs to.
|
54
|
+
keyword query A term or phrase you want to find in the deal name or description.
|
55
|
+
keyword_description query A term or phrase you want to find in the deal description.
|
56
|
+
keyword_name query A term or phrase you want to find in the deal name.
|
57
|
+
merchant selection filter The merchant ID of the merchant a deal belongs to.
|
58
|
+
merchant_type selection filter The merchant type ID that a deal's merchant belongs to.
|
59
|
+
page item pagination 1-100 1 The page number of the results you want returned.
|
60
|
+
results_per_page item pagination 1-100 20 The number of deals to return in every response.
|
61
|
+
session session Zipped info used to build more relevant filter values in the response in order to get back to previous filtered states. You do NOT to generate session value, it is provided in the parameters block. Pass it forward for any additional calls you make.
|
62
|
+
site_wide item filter all, yes, no all Indicates whether or not a deal applies site wide on a merchant's site, as opposed to being for a specific product or specific category within the merchant's site.
|
63
|
+
sort_deal sort relevance, name_asc relevance The sort order the deals are returned in
|
64
|
+
start_on range filter The start on date a deal is valid for. Pass in a single date for an exact match, or pass in a range of dates delimited with a dash '-'.
|
65
|
+
start_on_max range filter The maximum start on date for a deal.
|
66
|
+
start_on_min range filter The minimum start on date for a deal.
|
67
|
+
=end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ViglinkApi
|
4
|
+
module Merchant
|
5
|
+
|
6
|
+
##
|
7
|
+
# Retrieve the list of Merchants
|
8
|
+
#
|
9
|
+
# @param :full [Boolean] If set to true|y|yes then this will return
|
10
|
+
# the complete response
|
11
|
+
#
|
12
|
+
# @return [Hashie::Mash] Merchant
|
13
|
+
def find_merchants(options={})
|
14
|
+
full_response = options.delete(:full) if options[:full]
|
15
|
+
options[:key] = @api_key
|
16
|
+
merchants_response = get('/vigcatalog/merchants.xml', options)
|
17
|
+
|
18
|
+
if full_response.to_s.to_bool or @api_full_response
|
19
|
+
merchants_response.response if merchants_response.response
|
20
|
+
else
|
21
|
+
merchants_response.response.results.merchants if merchants_response.response.results
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Retrieve the list of MerchantTypes
|
27
|
+
#
|
28
|
+
# @param :full [Boolean] If set to true|y|yes then this will return
|
29
|
+
# the complete response
|
30
|
+
#
|
31
|
+
# @return [Hashie::Mash] MerchantType
|
32
|
+
def find_merchant_types(options={})
|
33
|
+
full_response = options.delete(:full) if options[:full]
|
34
|
+
options[:key] = @api_key
|
35
|
+
merchant_types_response = get('/vigcatalog/merchant_types.xml', options)
|
36
|
+
|
37
|
+
if full_response.to_s.to_bool or @api_full_response
|
38
|
+
merchant_types_response.response if merchant_types_response.response
|
39
|
+
else
|
40
|
+
merchant_types_response.response.results.merchant_types if merchant_types_response.response.results
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ViglinkApi
|
4
|
+
module Product
|
5
|
+
|
6
|
+
##
|
7
|
+
# Retrieve the list of Products
|
8
|
+
# @param :full [Boolean] If set to true|y|yes then this will return
|
9
|
+
# the complete response
|
10
|
+
#
|
11
|
+
# @return [Hashie::Mash] Product
|
12
|
+
def find_products(options={})
|
13
|
+
full_response = options.delete(:full) if options[:full]
|
14
|
+
options[:key] = @api_key
|
15
|
+
products_response = get('/vigcatalog/products.xml', options)
|
16
|
+
|
17
|
+
if full_response.to_s.to_bool or @api_full_response
|
18
|
+
products_response.response if products_response.response
|
19
|
+
else
|
20
|
+
products_response.response.results.products if products_response.response.results
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'forwardable'
|
3
|
+
require 'viglink_api/request'
|
4
|
+
|
5
|
+
module ViglinkApi
|
6
|
+
class Purchases
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
include Request
|
10
|
+
|
11
|
+
attr_reader :api_secret, :api_cuid_url, :last_date, :period
|
12
|
+
|
13
|
+
##
|
14
|
+
# Create a new ViglinkApi::Client object
|
15
|
+
#
|
16
|
+
# @params options [Hash]
|
17
|
+
def initialize(options={})
|
18
|
+
@api_secret = options[:api_secret] || ViglinkApi.api_secret
|
19
|
+
@api_cuid_url = options[:api_cuid_url] || ViglinkApi.api_cuid_url
|
20
|
+
@last_date = options[:last_date] || 1.day.ago.strftime("%Y/%m/%d")
|
21
|
+
@period = options[:period] || "day"
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Create a Faraday::Connection object
|
26
|
+
#
|
27
|
+
# @return [Faraday::Connection]
|
28
|
+
def connection
|
29
|
+
params = {}
|
30
|
+
@connection = Faraday.new(url: api_cuid_url, params: params, headers: default_headers, ssl: {verify:false}) do |faraday|
|
31
|
+
faraday.use FaradayMiddleware::Mashify
|
32
|
+
faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
33
|
+
faraday.adapter Faraday.default_adapter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def find_purchases(options={})
|
39
|
+
options[:secret] = @api_secret
|
40
|
+
if options.has_key?(:last_date)
|
41
|
+
options[:lastDate] = options.delete(:last_date)
|
42
|
+
else
|
43
|
+
options[:lastDate] = @last_date
|
44
|
+
end
|
45
|
+
unless options.has_key?(:period)
|
46
|
+
options[:period] = @period
|
47
|
+
end
|
48
|
+
purchases_response = get('', options)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def default_headers
|
55
|
+
headers = {
|
56
|
+
accept: '*/*',
|
57
|
+
content_type: 'text/json',
|
58
|
+
user_agent: "Ruby Gem #{ViglinkApi::VERSION}"
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module ViglinkApi
|
5
|
+
module Request
|
6
|
+
|
7
|
+
def get(path, options)
|
8
|
+
request(:get, path, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(path, options)
|
12
|
+
request(:post, path, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def request(method, path, options)
|
16
|
+
response = connection.send(method) do |request|
|
17
|
+
case method
|
18
|
+
when :get
|
19
|
+
request.url(path, options)
|
20
|
+
when :put, :post
|
21
|
+
request.path = path
|
22
|
+
request.body = options.to_xml unless options.empty?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
response.body
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "viglink-api"
|
2
|
+
require "vcr"
|
3
|
+
require "simplecov"
|
4
|
+
require "simplecov-rcov"
|
5
|
+
|
6
|
+
class SimpleCov::Formatter::MergedFormatter
|
7
|
+
def format(result)
|
8
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
9
|
+
SimpleCov::Formatter::RcovFormatter.new.format(result)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
|
14
|
+
SimpleCov.start do
|
15
|
+
add_filter '/vendor'
|
16
|
+
end
|
17
|
+
|
18
|
+
VCR.configure do |c|
|
19
|
+
c.allow_http_connections_when_no_cassette = true
|
20
|
+
c.cassette_library_dir = 'spec/cassettes'
|
21
|
+
c.hook_into :webmock
|
22
|
+
c.configure_rspec_metadata!
|
23
|
+
c.default_cassette_options = {record: :new_episodes}
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |c|
|
28
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
29
|
+
|
30
|
+
# Add gem specific configure for easy access
|
31
|
+
#
|
32
|
+
c.before(:each) do
|
33
|
+
ViglinkApi.configure do |config|
|
34
|
+
config.api_key = 'your-api-key'
|
35
|
+
config.api_url = 'http://catalog.viglink.com'
|
36
|
+
config.api_secret = 'your-secret-key'
|
37
|
+
config.api_cuid_url = 'https://www.viglink.com/service/v1/cuidRevenue'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Viglink::Country do
|
5
|
+
|
6
|
+
let(:client) { Viglink::Client.new }
|
7
|
+
|
8
|
+
describe "#find_countries" do
|
9
|
+
|
10
|
+
context "without search options" do
|
11
|
+
|
12
|
+
it "returns a list of supported countries", vcr: true do
|
13
|
+
client.find_countries.should be_kind_of Hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Viglink::Deal do
|
5
|
+
|
6
|
+
let(:client) { Viglink::Client.new }
|
7
|
+
|
8
|
+
describe "#find_deals" do
|
9
|
+
context "without search options" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@deals_response = client.find_deals
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns a Hash of deals", vcr: true do
|
16
|
+
@deals_response.should be_kind_of Hash
|
17
|
+
end
|
18
|
+
|
19
|
+
it "retuns the total count of deals", vcr: true do
|
20
|
+
@deals_response[:count].should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "retuns an Array of deals", vcr: true do
|
24
|
+
@deals_response.deal.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with search options" do
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
@deals_response = client.find_deals({full: true})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a Hash of deals", vcr: true do
|
36
|
+
@deals_response.should be_kind_of Hash
|
37
|
+
end
|
38
|
+
|
39
|
+
context "response resources of merchant" do
|
40
|
+
it "returns the `results`", vcr: true do
|
41
|
+
@deals_response[:results].should_not be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the `parameters`", vcr: true do
|
45
|
+
@deals_response[:parameters].should_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns an `deals`", vcr: true do
|
49
|
+
@deals_response.results.deals.should_not be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#find_deal_types" do
|
56
|
+
|
57
|
+
context "without search options" do
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@deal_types_response = client.find_deal_types
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a Hash of deal_types", vcr: true do
|
64
|
+
@deal_types_response.should be_kind_of Hash
|
65
|
+
end
|
66
|
+
|
67
|
+
it "retuns the total count of deal_types", vcr: true do
|
68
|
+
@deal_types_response[:count].should_not be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "retuns an Array of deal_types", vcr: true do
|
72
|
+
@deal_types_response.deal_type.should_not be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with search options" do
|
78
|
+
|
79
|
+
before(:each) do
|
80
|
+
@deal_types_response = client.find_deal_types({full: true})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns a Hash of deal_types", vcr: true do
|
84
|
+
@deal_types_response.should be_kind_of Hash
|
85
|
+
end
|
86
|
+
|
87
|
+
context "response resources of product" do
|
88
|
+
it "returns the `results`", vcr: true do
|
89
|
+
@deal_types_response[:results].should_not be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns the `parameters`", vcr: true do
|
93
|
+
@deal_types_response[:parameters].should_not be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns an `deal_types`", vcr: true do
|
97
|
+
@deal_types_response.results.deal_types.should_not be_nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Viglink::Merchant do
|
5
|
+
|
6
|
+
let(:client) { Viglink::Client.new }
|
7
|
+
|
8
|
+
describe "#find_merchants" do
|
9
|
+
context "without search options" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@merchants_response = client.find_merchants
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns a Hash of merchants", vcr: true do
|
16
|
+
@merchants_response.should be_kind_of Hash
|
17
|
+
end
|
18
|
+
|
19
|
+
it "retuns the total count of merchants", vcr: true do
|
20
|
+
@merchants_response[:count].should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "retuns an Array of merchants", vcr: true do
|
24
|
+
@merchants_response.merchant.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with search options" do
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
@merchants_response = client.find_merchants({full: true})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a Hash of merchants", vcr: true do
|
36
|
+
@merchants_response.should be_kind_of Hash
|
37
|
+
end
|
38
|
+
|
39
|
+
context "response resources of merchant" do
|
40
|
+
it "returns the `results`", vcr: true do
|
41
|
+
@merchants_response[:results].should_not be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the `parameters`", vcr: true do
|
45
|
+
@merchants_response[:parameters].should_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns an `merchants`", vcr: true do
|
49
|
+
@merchants_response.results.merchants.should_not be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#find_merchant_types" do
|
56
|
+
|
57
|
+
context "without search options" do
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@merchant_types_response = client.find_merchant_types
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a Hash of merchant_types", vcr: true do
|
64
|
+
@merchant_types_response.should be_kind_of Hash
|
65
|
+
end
|
66
|
+
|
67
|
+
it "retuns the total count of merchant_types", vcr: true do
|
68
|
+
@merchant_types_response[:count].should_not be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "retuns an Array of merchant_types", vcr: true do
|
72
|
+
@merchant_types_response.merchant_type.should_not be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with search options" do
|
78
|
+
|
79
|
+
before(:each) do
|
80
|
+
@merchant_types_response = client.find_merchant_types({full: true})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns a Hash of merchant_types", vcr: true do
|
84
|
+
@merchant_types_response.should be_kind_of Hash
|
85
|
+
end
|
86
|
+
|
87
|
+
context "response resources of product" do
|
88
|
+
it "returns the `results`", vcr: true do
|
89
|
+
@merchant_types_response[:results].should_not be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns the `parameters`", vcr: true do
|
93
|
+
@merchant_types_response[:parameters].should_not be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns an `merchant_types`", vcr: true do
|
97
|
+
@merchant_types_response.results.merchant_types.should_not be_nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|