ebay_enterprise_affiliate_network 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/ebay_enterprise_affiliate_network.gemspec +33 -0
- data/lib/ebay_enterprise_affiliate_network.rb +45 -0
- data/lib/ebay_enterprise_affiliate_network/api_resource.rb +66 -0
- data/lib/ebay_enterprise_affiliate_network/api_response.rb +31 -0
- data/lib/ebay_enterprise_affiliate_network/errors/authentication_error.rb +4 -0
- data/lib/ebay_enterprise_affiliate_network/errors/connection_error.rb +4 -0
- data/lib/ebay_enterprise_affiliate_network/errors/error.rb +15 -0
- data/lib/ebay_enterprise_affiliate_network/errors/invalid_request_error.rb +4 -0
- data/lib/ebay_enterprise_affiliate_network/publisher.rb +4 -0
- data/lib/ebay_enterprise_affiliate_network/version.rb +3 -0
- data/test/ebay_enterprise_affiliate_network_test.rb +299 -0
- data/test/test_helper.rb +7 -0
- metadata +228 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :test do
|
5
|
+
watch(%r{^test/.+_test\.rb$})
|
6
|
+
watch("test/test_helper.rb") { "test" }
|
7
|
+
|
8
|
+
watch(%r{^app/models/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
9
|
+
watch(%r{^app/validators/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
10
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013- Venture Media Labs, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# eBay Enterprise Affiliate Network API
|
2
|
+
|
3
|
+
Ruby wrapper for [eBay Enterprise Affiliate Network API](http://help.pepperjamnetwork.com/api/) (formerly PepperJam Exchange API). Only [Publisher API](http://help.pepperjamnetwork.com/api/publisher) is supported at this moment. If you need [Advertiser API](http://help.pepperjamnetwork.com/api/advertiser) or [Partner API](http://help.pepperjamnetwork.com/api/partner), feel free to [contribute](#contributing).
|
4
|
+
|
5
|
+
For questions or bugs please [create an issue](issues/new).
|
6
|
+
|
7
|
+
## <a id="installation"></a>Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ebay_enterprise_affiliate_network'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ebay_enterprise_affiliate_network
|
20
|
+
|
21
|
+
## <a id="requirement"></a>Requirements
|
22
|
+
|
23
|
+
[Ruby](http://www.ruby-lang.org/en/downloads/) 1.9 or above.
|
24
|
+
|
25
|
+
## <a id="usage"></a>Usage
|
26
|
+
|
27
|
+
The gem is designed to support all existing and future [Publisher API](http://help.pepperjamnetwork.com/api/publisher) resources.
|
28
|
+
|
29
|
+
To start using the gem, you need to set up the api key first. If you use Ruby on Rails, the API key can be set in a configuration file (i.e. `app/config/initializers/ebay_enterprise_affiliate_network.rb`), otherwise just set it in your script. API Key can be found at http://www.pepperjamnetwork.com/affiliate/api/.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "ebay_enterprise_affiliate_network" # no need for RoR
|
33
|
+
EBayEnterpriseAffiliateNetwork.api_key = ENV["EEAN_API_KEY"]
|
34
|
+
```
|
35
|
+
|
36
|
+
### Examples
|
37
|
+
|
38
|
+
#### <a href="http://help.pepperjamnetwork.com/api/publisher#advertiser-category" target="_blank" title="Advertiser Categories">Advertiser Categories</a>
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
42
|
+
response = publisher.get("advertiser/category")
|
43
|
+
response.data.each do |category|
|
44
|
+
puts "#{category.name} (ID #{category.id})"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieve the actual request URL sent to the API
|
48
|
+
puts response.request.uri.to_s
|
49
|
+
```
|
50
|
+
|
51
|
+
#### <a href="http://help.pepperjamnetwork.com/api/publisher#advertiser" target="_blank" title="Advertisers">Advertiser Details</a>
|
52
|
+
|
53
|
+
Get the list of [advertisers](http://help.pepperjamnetwork.com/api/publisher#advertiser) that you have a `joined` relationship with. The second argument of `get` method accepts a `Hash` of parameters. See the [API documentation](http://help.pepperjamnetwork.com/api/publisher) for a list of parameters for each API resource.
|
54
|
+
Note that the API resource used must match the ones available in documentation, except the `publisher/` prefix that needs to be removed.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
58
|
+
response = publisher.get("advertiser", status: :joined)
|
59
|
+
# Return the number of total records
|
60
|
+
response.meta.pagination.total_results
|
61
|
+
# Return the number of pages
|
62
|
+
response.meta.pagination.total_pages
|
63
|
+
|
64
|
+
response.data.each do |advertiser|
|
65
|
+
# Do something
|
66
|
+
end
|
67
|
+
```
|
68
|
+
If there are multiple pages (each page has a maximum of 500 records, value that cannot be changed), you can retrieve all pages by using the `all` method, as follows:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
response.all.each do |advertiser|
|
72
|
+
# Do something
|
73
|
+
end
|
74
|
+
```
|
75
|
+
When using the `all` method, `response` object is updated with the data returned by the last API request (last page). `response.all` returns the `data` array.
|
76
|
+
|
77
|
+
#### <a href="http://help.pepperjamnetwork.com/api/publisher#creative-product" target="_blank" title="Product Creatives">Product Creatives</a>
|
78
|
+
|
79
|
+
Filter [Target](http://www.target.com) products by `canon camera` keywords.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
params = {
|
83
|
+
programIds: 6759, # Target ID
|
84
|
+
keywords: "canon camera"
|
85
|
+
}
|
86
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
87
|
+
response = publisher.get("creative/product", params)
|
88
|
+
response.data.each do |product|
|
89
|
+
puts "<a href=\"#{product.buy_url}\" title=\"#{product.name}\" target=\"_blank\">#{product.name}</a>"
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
#### <a href="http://help.pepperjamnetwork.com/api/publisher#report-transaction-details" target="_blank" title="Transaction Details">Transaction Details</a>
|
94
|
+
|
95
|
+
Retrieve all transactions in the last day
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
require "date"
|
99
|
+
# Note that the API uses ET as time zone, although is not specified anywhere
|
100
|
+
yesterday = (Date.today - 1).to_s
|
101
|
+
today = Date.today.to_s
|
102
|
+
params = {
|
103
|
+
startDate: yesterday,
|
104
|
+
endDate: today,
|
105
|
+
website: 12345 # replace with your website id
|
106
|
+
}
|
107
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
108
|
+
response = publisher.get("report/transaction-details", params)
|
109
|
+
response.data.each do |transaction|
|
110
|
+
# Generate report
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Website ID can be retrieved from http://www.pepperjamnetwork.com/affiliate.
|
115
|
+
|
116
|
+
### Extra Configuration
|
117
|
+
|
118
|
+
* `EBayEnterpriseAffiliateNetwork.api_base_url` - default value is `http://api.pepperjamnetwork.com`
|
119
|
+
* `EBayEnterpriseAffiliateNetwork.api_version` - default value is `20120402`
|
120
|
+
* `EBayEnterpriseAffiliateNetwork.api_timeout` - the timeout set when initiating requests to eBay Enterprise Affiliate Network API (default value is 30 seconds)
|
121
|
+
|
122
|
+
## <a id="contributing"></a>Contributing
|
123
|
+
|
124
|
+
1. Fork it
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create new Pull Request
|
129
|
+
|
130
|
+
## <a id="license"></a>License
|
131
|
+
|
132
|
+
[MIT](LICENSE.md)
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ebay_enterprise_affiliate_network/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ebay_enterprise_affiliate_network"
|
8
|
+
s.version = EBayEnterpriseAffiliateNetwork::VERSION
|
9
|
+
s.authors = ["Razvan Marescu"]
|
10
|
+
s.email = ["razvan@marescu.net"]
|
11
|
+
s.description = %q{Ruby wrapper for eBay Enterprise Affiliate Network API (formerly PepperJam Exchange API). See http://help.pepperjamnetwork.com/api for details.}
|
12
|
+
s.summary = %q{eBay Enterprise Affiliate Network API}
|
13
|
+
s.homepage = "https://github.com/rmarescu/ebay_enterprise_affiliate_network"
|
14
|
+
s.license = "MIT"
|
15
|
+
s.required_ruby_version = ">= 1.9"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.test_files = s.files.grep(%r{^(test|s|features)/})
|
19
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "addressable", "~> 2.3.5"
|
23
|
+
s.add_dependency "htmlentities", "~> 4.3.1"
|
24
|
+
s.add_dependency "httparty", "~> 0.11.0"
|
25
|
+
s.add_dependency "json", "~> 1.8.0"
|
26
|
+
s.add_dependency "recursive-open-struct", "~> 0.4.3"
|
27
|
+
|
28
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
s.add_development_dependency "rake"
|
30
|
+
s.add_development_dependency "webmock"
|
31
|
+
s.add_development_dependency "test-unit"
|
32
|
+
s.add_development_dependency "guard-test"
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "addressable/uri"
|
2
|
+
require "cgi"
|
3
|
+
require "htmlentities"
|
4
|
+
require "httparty"
|
5
|
+
require "json"
|
6
|
+
require "net/http"
|
7
|
+
require "recursive_open_struct"
|
8
|
+
require "uri"
|
9
|
+
|
10
|
+
# Version
|
11
|
+
require "ebay_enterprise_affiliate_network/version"
|
12
|
+
|
13
|
+
# Resources
|
14
|
+
require "ebay_enterprise_affiliate_network/api_resource"
|
15
|
+
require "ebay_enterprise_affiliate_network/publisher"
|
16
|
+
require "ebay_enterprise_affiliate_network/api_response"
|
17
|
+
|
18
|
+
# Errors
|
19
|
+
require "ebay_enterprise_affiliate_network/errors/error"
|
20
|
+
require "ebay_enterprise_affiliate_network/errors/authentication_error"
|
21
|
+
require "ebay_enterprise_affiliate_network/errors/connection_error"
|
22
|
+
require "ebay_enterprise_affiliate_network/errors/invalid_request_error"
|
23
|
+
|
24
|
+
module EBayEnterpriseAffiliateNetwork
|
25
|
+
@api_base_url = "http://api.pepperjamnetwork.com"
|
26
|
+
@api_version = 20120402
|
27
|
+
@api_timeout = 30
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_accessor :api_key, :api_base_url
|
31
|
+
attr_reader :api_version, :api_timeout
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.api_version=(version)
|
35
|
+
raise ArgumentError, "Version must be a Fixnum (YYYYMMDD format); got #{version.class} instead." unless version.is_a? Fixnum
|
36
|
+
raise ArgumentError, "Please provide the version of the API Key." unless version > 0
|
37
|
+
@api_version = version
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.api_timeout=(timeout)
|
41
|
+
raise ArgumentError, "Timeout must be a Fixnum; got #{timeout.class} instead" unless timeout.is_a? Fixnum
|
42
|
+
raise ArgumentError, "Timeout must be > 0; got #{timeout} instead" unless timeout > 0
|
43
|
+
@api_timeout = timeout
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module EBayEnterpriseAffiliateNetwork
|
2
|
+
class APIResource
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def class_name
|
6
|
+
self.class.name.split('::')[-1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_path
|
10
|
+
if self == APIResource
|
11
|
+
raise NotImplementedError.new("APIResource is an abstract class. You should perform actions on its subclasses (i.e. Publisher)")
|
12
|
+
end
|
13
|
+
"/#{EBayEnterpriseAffiliateNetwork.api_version}/#{CGI.escape(class_name.downcase)}/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(api_resource, params = {})
|
17
|
+
@resource ||= api_resource
|
18
|
+
unless api_key ||= EBayEnterpriseAffiliateNetwork.api_key
|
19
|
+
raise AuthenticationError.new(
|
20
|
+
"No API key provided. Set your API key using 'EBayEnterpriseAffiliateNetwork.api_key = <API-KEY>'. " +
|
21
|
+
"You can retrieve your API key from the eBay Enterprise web interface. " +
|
22
|
+
"See http://www.pepperjamnetwork.com/affiliate/api/ for details."
|
23
|
+
)
|
24
|
+
end
|
25
|
+
if api_key =~ /\s/
|
26
|
+
raise AuthenticationError.new(
|
27
|
+
"Your API key looks invalid. " +
|
28
|
+
"Double-check your API key at http://www.pepperjamnetwork.com/affiliate/api/"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
32
|
+
|
33
|
+
params.merge!({
|
34
|
+
apiKey: api_key,
|
35
|
+
format: :json
|
36
|
+
})
|
37
|
+
resource_url = EBayEnterpriseAffiliateNetwork.api_base_url + base_path + api_resource
|
38
|
+
request(resource_url, params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def request(resource_url, params)
|
42
|
+
timeout = EBayEnterpriseAffiliateNetwork.api_timeout
|
43
|
+
begin
|
44
|
+
response = self.class.get(resource_url, query: params, timeout: timeout)
|
45
|
+
rescue Timeout::Error
|
46
|
+
raise ConnectionError.new("Timeout error (#{timeout}s)")
|
47
|
+
end
|
48
|
+
process(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def process(response)
|
54
|
+
case response.code
|
55
|
+
when 200, 201, 204
|
56
|
+
APIResponse.new(response)
|
57
|
+
when 400, 404
|
58
|
+
raise InvalidRequestError.new(response.message, response.code)
|
59
|
+
when 401
|
60
|
+
raise AuthenticationError.new(response.message, response.code)
|
61
|
+
else
|
62
|
+
raise Error.new(response.message, response.code)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module EBayEnterpriseAffiliateNetwork
|
2
|
+
class APIResponse
|
3
|
+
attr_reader :meta, :data, :request
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@request = response.request
|
7
|
+
body = JSON.parse(response.body)
|
8
|
+
@meta = RecursiveOpenStruct.new(body["meta"])
|
9
|
+
@data = parse(body["data"])
|
10
|
+
end
|
11
|
+
|
12
|
+
def all
|
13
|
+
while meta.pagination.next
|
14
|
+
uri = Addressable::URI.parse(meta.pagination.next.href)
|
15
|
+
next_page_response = EBayEnterpriseAffiliateNetwork::Publisher.new.request(uri.origin + uri.path, uri.query_values)
|
16
|
+
@meta = next_page_response.meta
|
17
|
+
@data += next_page_response.data
|
18
|
+
end
|
19
|
+
@data
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def parse(raw_data)
|
25
|
+
data = []
|
26
|
+
data = [raw_data] if raw_data.is_a?(Hash) # If we got exactly one result, put it in an array.
|
27
|
+
raw_data.each { |item| data << RecursiveOpenStruct.new(item) } if raw_data
|
28
|
+
data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EBayEnterpriseAffiliateNetwork
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :message, :code
|
4
|
+
|
5
|
+
def initialize(message = nil, code = nil)
|
6
|
+
@message = message
|
7
|
+
@code = code
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
code_string = code.nil? ? "" : " (Code #{code})"
|
12
|
+
"#{message}#{code_string}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,299 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class EBayEnterpriseAffiliateNetworkTest < Test::Unit::TestCase
|
4
|
+
def test_with_invalid_key
|
5
|
+
EBayEnterpriseAffiliateNetwork.api_key = nil
|
6
|
+
ebay = EBayEnterpriseAffiliateNetwork::Publisher.new
|
7
|
+
assert_raise EBayEnterpriseAffiliateNetwork::AuthenticationError do
|
8
|
+
ebay.get('advertiser')
|
9
|
+
end
|
10
|
+
|
11
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key with spaces"
|
12
|
+
assert_raise EBayEnterpriseAffiliateNetwork::AuthenticationError do
|
13
|
+
ebay.get('advertiser')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_invalid_version
|
18
|
+
assert_raise ArgumentError do
|
19
|
+
EBayEnterpriseAffiliateNetwork.api_version = ""
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_raise ArgumentError do
|
23
|
+
EBayEnterpriseAffiliateNetwork.api_version = 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_invalid_timeout
|
28
|
+
assert_raise ArgumentError do
|
29
|
+
EBayEnterpriseAffiliateNetwork.api_timeout = ""
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_raise ArgumentError do
|
33
|
+
EBayEnterpriseAffiliateNetwork.api_timeout = "20"
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_raise ArgumentError do
|
37
|
+
EBayEnterpriseAffiliateNetwork.api_timeout = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_raise ArgumentError do
|
41
|
+
EBayEnterpriseAffiliateNetwork.api_timeout = -1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_new_publisher
|
46
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
47
|
+
assert_nothing_raised do
|
48
|
+
EBayEnterpriseAffiliateNetwork::Publisher.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_invalid_params_for_resource
|
53
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
54
|
+
assert_raise ArgumentError do
|
55
|
+
EBayEnterpriseAffiliateNetwork::Publisher.new.get("advertiser", "foo")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_publisher_base_path
|
60
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
61
|
+
assert_equal "/#{EBayEnterpriseAffiliateNetwork.api_version}/publisher/", publisher.base_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_raise_invalid_request_error_on_code_400
|
65
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
66
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
67
|
+
json_response = <<-JSON
|
68
|
+
{
|
69
|
+
"meta": {
|
70
|
+
"status": { "code": 400, "message": "foo is not a valid program status option." },
|
71
|
+
"requests": { "current": 384, "maximum": 1500 }
|
72
|
+
},
|
73
|
+
"data": []
|
74
|
+
}
|
75
|
+
JSON
|
76
|
+
stub_request(
|
77
|
+
:get,
|
78
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&status=foo").
|
79
|
+
with(headers: {}).
|
80
|
+
to_return(
|
81
|
+
status: [400, "foo is not a valid program status option."],
|
82
|
+
body: json_response,
|
83
|
+
headers: {}
|
84
|
+
)
|
85
|
+
e = assert_raise EBayEnterpriseAffiliateNetwork::InvalidRequestError do
|
86
|
+
publisher.get("advertiser", status: :foo)
|
87
|
+
end
|
88
|
+
assert_equal "foo is not a valid program status option. (Code 400)", e.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_raise_error_on_code_500
|
92
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
93
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
94
|
+
json_response = <<-JSON
|
95
|
+
{
|
96
|
+
"meta": {
|
97
|
+
"status": { "code": 500, "message": "Internal Server Error" },
|
98
|
+
"requests": { "current": 384, "maximum": 1500 }
|
99
|
+
},
|
100
|
+
"data": []
|
101
|
+
}
|
102
|
+
JSON
|
103
|
+
stub_request(
|
104
|
+
:get,
|
105
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json").
|
106
|
+
with(headers: {}).
|
107
|
+
to_return(
|
108
|
+
status: [500, "Internal Server Error"],
|
109
|
+
body: json_response,
|
110
|
+
headers: {}
|
111
|
+
)
|
112
|
+
e = assert_raise EBayEnterpriseAffiliateNetwork::Error do
|
113
|
+
publisher.get("advertiser/category")
|
114
|
+
end
|
115
|
+
assert_equal "Internal Server Error (Code 500)", e.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_raise_error_on_code_401
|
119
|
+
EBayEnterpriseAffiliateNetwork.api_key = "wrong_key"
|
120
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
121
|
+
json_response = <<-JSON
|
122
|
+
{
|
123
|
+
meta: {
|
124
|
+
status: {
|
125
|
+
code: 401,
|
126
|
+
message: "Authentication error."
|
127
|
+
}
|
128
|
+
},
|
129
|
+
data: []
|
130
|
+
}
|
131
|
+
JSON
|
132
|
+
stub_request(
|
133
|
+
:get,
|
134
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json").
|
135
|
+
with(headers: {}).
|
136
|
+
to_return(
|
137
|
+
status: [401, "Authentication error."],
|
138
|
+
body: json_response,
|
139
|
+
headers: {}
|
140
|
+
)
|
141
|
+
e = assert_raise EBayEnterpriseAffiliateNetwork::AuthenticationError do
|
142
|
+
publisher.get("advertiser/category")
|
143
|
+
end
|
144
|
+
assert_equal "Authentication error. (Code 401)", e.to_s
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_publisher_get_category_resource
|
148
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
149
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
150
|
+
json_response = <<-JSON
|
151
|
+
{
|
152
|
+
"meta": {
|
153
|
+
"status": { "code": 200, "message": "OK" },
|
154
|
+
"pagination": { "total_results": 3, "total_pages": 1 },
|
155
|
+
"requests": { "current": 359, "maximum": 1500 }
|
156
|
+
},
|
157
|
+
"data": [
|
158
|
+
{ "name": "Commerce", "id": "1" },
|
159
|
+
{ "name": "Computer & Electronics", "id": "2" },
|
160
|
+
{ "name": "Education", "id": "3" },
|
161
|
+
{ "name": "Accessories", "id": "7" }
|
162
|
+
]
|
163
|
+
}
|
164
|
+
JSON
|
165
|
+
stub_request(
|
166
|
+
:get,
|
167
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json").
|
168
|
+
with(headers: {}).
|
169
|
+
to_return(status: 200, body: json_response, headers: {})
|
170
|
+
|
171
|
+
response = publisher.get("advertiser/category")
|
172
|
+
check_results(response)
|
173
|
+
|
174
|
+
assert_equal 200, response.meta.status.code
|
175
|
+
assert_equal 3, response.meta.pagination.total_results
|
176
|
+
assert_equal 1, response.meta.pagination.total_pages
|
177
|
+
assert_equal 4, response.data.size
|
178
|
+
assert_equal "Commerce", response.data.first.name
|
179
|
+
assert_equal "1", response.data.first.id
|
180
|
+
assert_equal "Accessories", response.data.last.name
|
181
|
+
assert_equal "7", response.data.last.id
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_publisher_get_all_results
|
185
|
+
EBayEnterpriseAffiliateNetwork.api_key = "key"
|
186
|
+
publisher = EBayEnterpriseAffiliateNetwork::Publisher.new
|
187
|
+
response_page_1 = <<-JSON
|
188
|
+
{
|
189
|
+
"meta": {
|
190
|
+
"status": { "code": 200, "message": "OK" },
|
191
|
+
"pagination": {
|
192
|
+
"total_results": 10,
|
193
|
+
"total_pages": 3,
|
194
|
+
"next": {
|
195
|
+
"rel": "next",
|
196
|
+
"href": "http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=2",
|
197
|
+
"description": "Next Page"
|
198
|
+
}
|
199
|
+
},
|
200
|
+
"requests": { "current": 359, "maximum": 1500 }
|
201
|
+
},
|
202
|
+
"data": [
|
203
|
+
{ "name": "Commerce", "id": "1" },
|
204
|
+
{ "name": "Computer & Electronics", "id": "2" },
|
205
|
+
{ "name": "Education", "id": "3" },
|
206
|
+
{ "name": "Accessories", "id": "7" }
|
207
|
+
]
|
208
|
+
}
|
209
|
+
JSON
|
210
|
+
response_page_2 = <<-JSON
|
211
|
+
{
|
212
|
+
"meta": {
|
213
|
+
"status": { "code": 200, "message": "OK" },
|
214
|
+
"pagination": {
|
215
|
+
"total_results": 10,
|
216
|
+
"total_pages": 3,
|
217
|
+
"next": {
|
218
|
+
"rel": "next",
|
219
|
+
"href": "http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=3",
|
220
|
+
"description": "Next Page"
|
221
|
+
},
|
222
|
+
"prev": {
|
223
|
+
"rel": "prev",
|
224
|
+
"href": "http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=1",
|
225
|
+
"description": "Previous Page"
|
226
|
+
}
|
227
|
+
},
|
228
|
+
"requests": { "current": 360, "maximum": 1500 }
|
229
|
+
},
|
230
|
+
"data": [
|
231
|
+
{ "name": "Art/Photo/Music", "id": "9" },
|
232
|
+
{ "name": "Automotive", "id": "11" },
|
233
|
+
{ "name": "Books/Media", "id": "13" },
|
234
|
+
{ "name": "Business", "id": "15" }
|
235
|
+
]
|
236
|
+
}
|
237
|
+
JSON
|
238
|
+
response_page_3 = <<-JSON
|
239
|
+
{
|
240
|
+
"meta": {
|
241
|
+
"status": { "code": 200, "message": "OK" },
|
242
|
+
"pagination": {
|
243
|
+
"total_results": 10,
|
244
|
+
"total_pages": 3,
|
245
|
+
"prev": {
|
246
|
+
"rel": "prev",
|
247
|
+
"href": "http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=2",
|
248
|
+
"description": "Previous Page"
|
249
|
+
}
|
250
|
+
},
|
251
|
+
"requests": { "current": 361, "maximum": 1500 }
|
252
|
+
},
|
253
|
+
"data": [
|
254
|
+
{ "name": "Careers", "id": "17" },
|
255
|
+
{ "name": "Clothing/Apparel", "id": "19" },
|
256
|
+
{ "name": "Entertainment", "id": "23" }
|
257
|
+
]
|
258
|
+
}
|
259
|
+
JSON
|
260
|
+
stub_request(
|
261
|
+
:get,
|
262
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json").
|
263
|
+
with(headers: {}).
|
264
|
+
to_return(status: 200, body: response_page_1, headers: {})
|
265
|
+
|
266
|
+
response = publisher.get("advertiser/category")
|
267
|
+
stub_request(
|
268
|
+
:get,
|
269
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=2").
|
270
|
+
with(headers: {}).
|
271
|
+
to_return(status: 200, body: response_page_2, headers: {})
|
272
|
+
stub_request(
|
273
|
+
:get,
|
274
|
+
"http://api.pepperjamnetwork.com/20120402/publisher/advertiser/category?apiKey=#{EBayEnterpriseAffiliateNetwork.api_key}&format=json&page=3").
|
275
|
+
with(headers: {}).
|
276
|
+
to_return(status: 200, body: response_page_3, headers: {})
|
277
|
+
all_categories = response.all
|
278
|
+
check_results(response)
|
279
|
+
|
280
|
+
assert_equal 11, all_categories.count
|
281
|
+
assert_equal 23, all_categories.last.id.to_i
|
282
|
+
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
def check_results(response)
|
287
|
+
assert_instance_of(RecursiveOpenStruct, response.meta)
|
288
|
+
assert_instance_of(Fixnum, response.meta.status.code)
|
289
|
+
assert_instance_of(String, response.meta.status.message)
|
290
|
+
assert_instance_of(Fixnum, response.meta.pagination.total_results)
|
291
|
+
assert_instance_of(Fixnum, response.meta.pagination.total_pages)
|
292
|
+
assert_instance_of(Array, response.data)
|
293
|
+
|
294
|
+
response.data.each do |item|
|
295
|
+
assert_instance_of(RecursiveOpenStruct, item)
|
296
|
+
assert_respond_to(item, :name)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ebay_enterprise_affiliate_network
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Razvan Marescu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: addressable
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: htmlentities
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.3.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.3.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: httparty
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.11.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.11.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: recursive-open-struct
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.4.3
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.4.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.3'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: webmock
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: test-unit
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: guard-test
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Ruby wrapper for eBay Enterprise Affiliate Network API (formerly PepperJam
|
175
|
+
Exchange API). See http://help.pepperjamnetwork.com/api for details.
|
176
|
+
email:
|
177
|
+
- razvan@marescu.net
|
178
|
+
executables: []
|
179
|
+
extensions: []
|
180
|
+
extra_rdoc_files: []
|
181
|
+
files:
|
182
|
+
- .gitignore
|
183
|
+
- Gemfile
|
184
|
+
- Guardfile
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- VERSION
|
189
|
+
- ebay_enterprise_affiliate_network.gemspec
|
190
|
+
- lib/ebay_enterprise_affiliate_network.rb
|
191
|
+
- lib/ebay_enterprise_affiliate_network/api_resource.rb
|
192
|
+
- lib/ebay_enterprise_affiliate_network/api_response.rb
|
193
|
+
- lib/ebay_enterprise_affiliate_network/errors/authentication_error.rb
|
194
|
+
- lib/ebay_enterprise_affiliate_network/errors/connection_error.rb
|
195
|
+
- lib/ebay_enterprise_affiliate_network/errors/error.rb
|
196
|
+
- lib/ebay_enterprise_affiliate_network/errors/invalid_request_error.rb
|
197
|
+
- lib/ebay_enterprise_affiliate_network/publisher.rb
|
198
|
+
- lib/ebay_enterprise_affiliate_network/version.rb
|
199
|
+
- test/ebay_enterprise_affiliate_network_test.rb
|
200
|
+
- test/test_helper.rb
|
201
|
+
homepage: https://github.com/rmarescu/ebay_enterprise_affiliate_network
|
202
|
+
licenses:
|
203
|
+
- MIT
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ! '>='
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '1.9'
|
214
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
|
+
none: false
|
216
|
+
requirements:
|
217
|
+
- - ! '>='
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: '0'
|
220
|
+
requirements: []
|
221
|
+
rubyforge_project:
|
222
|
+
rubygems_version: 1.8.23
|
223
|
+
signing_key:
|
224
|
+
specification_version: 3
|
225
|
+
summary: eBay Enterprise Affiliate Network API
|
226
|
+
test_files:
|
227
|
+
- test/ebay_enterprise_affiliate_network_test.rb
|
228
|
+
- test/test_helper.rb
|