affiliate_window 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +67 -0
- data/lib/affiliate_window.rb +7 -0
- data/lib/affiliate_window/base.rb +132 -0
- data/lib/affiliate_window/client.rb +43 -0
- data/lib/affiliate_window/error_handler.rb +13 -0
- data/lib/affiliate_window/parser.rb +17 -0
- data/lib/affiliate_window/version.rb +3 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 879c6696972ede3c678d902070ada3515332070a
|
4
|
+
data.tar.gz: 99fdd2cc8dcbc40799a681eb1dbe33e981c95e02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: add29aba090cd27d2cb35652d4b8236c425538a84029b9008d9d34d9e5fd0fb4952b7ae62cce4b406469f3f4ebbb6ebc47a3d8efcd4fc44a30371f316d38c414
|
7
|
+
data.tar.gz: 20b094621c3c50d30c623ac5f1f24891b7f3139e9dd42bdea3bc77d85adc7578b4b50feae194dacd53ce7f888d8dacfee32054991f4f2584c8606a8b7c95f77b
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
## Affiliate Window
|
2
|
+
|
3
|
+
This gem lets you make requests to Affiliate Window's Publisher Service API.
|
4
|
+
At the time of writing, it is on version 6. The API is documented
|
5
|
+
[here](http://wiki.affiliatewindow.com/index.php/Publisher_Service_API).
|
6
|
+
|
7
|
+
There is [an existing gem](https://github.com/andyt/affiliate-window) for
|
8
|
+
communicating with Affiliate Window but it looks to be unsupported and doesn't
|
9
|
+
work with its Publisher Service API.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
client = AffiliateWindow.login(
|
15
|
+
account_id: 1234,
|
16
|
+
affiliate_api_password: "your api key",
|
17
|
+
)
|
18
|
+
|
19
|
+
response = client.get_transaction_list(
|
20
|
+
start_date: "2006-08-04T00:00:00",
|
21
|
+
end_date: "2006-08-14T23:59:59",
|
22
|
+
date_type: "transaction",
|
23
|
+
)
|
24
|
+
|
25
|
+
response.dig(:results, :transaction, 0)
|
26
|
+
#=> {
|
27
|
+
# i_id: "1",
|
28
|
+
# s_status: "confirmed",
|
29
|
+
# b_paid: true,
|
30
|
+
# m_sale_amount: {
|
31
|
+
# d_amount: "50.00",
|
32
|
+
# s_currency: "GBP"
|
33
|
+
# },
|
34
|
+
# ...
|
35
|
+
```
|
36
|
+
|
37
|
+
The gem follows the convention that all API methods are called by their
|
38
|
+
snake case name. Parameter names mirror the API, for example:
|
39
|
+
|
40
|
+
```
|
41
|
+
iMerchantId -> merchant_id
|
42
|
+
aTransactionIds -> transaction_ids
|
43
|
+
aStatus -> status
|
44
|
+
```
|
45
|
+
|
46
|
+
If the endpoint returns metadata about how many records were returned, this is
|
47
|
+
returned in the `pagination` key of the output, e.g.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
response
|
51
|
+
#=> {
|
52
|
+
# pagination: {
|
53
|
+
# i_rows_returned: "10",
|
54
|
+
# i_rows_available: "50"
|
55
|
+
# }
|
56
|
+
```
|
57
|
+
|
58
|
+
## Debugging
|
59
|
+
|
60
|
+
You can print the SOAP request bodies by enabling debug mode:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
client.debug = true
|
64
|
+
client.get_merchant_list
|
65
|
+
# <?xml version='1.0' encoding='UTF-8'?>
|
66
|
+
# ...
|
67
|
+
```
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# For full API documentation, refer to:
|
2
|
+
# http://wiki.affiliatewindow.com/index.php/Publisher_Service_API
|
3
|
+
|
4
|
+
class AffiliateWindow
|
5
|
+
attr_accessor :client, :error_handler, :parser, :debug
|
6
|
+
|
7
|
+
def self.login(account_id:, affiliate_api_password:)
|
8
|
+
client = Client.new(
|
9
|
+
account_id: account_id,
|
10
|
+
affiliate_api_password: affiliate_api_password,
|
11
|
+
)
|
12
|
+
|
13
|
+
new(client: client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(client:, error_handler: ErrorHandler, parser: Parser)
|
17
|
+
self.client = client
|
18
|
+
self.error_handler = error_handler
|
19
|
+
self.parser = parser
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gets the commission values for a given commission group and advertiser
|
23
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getCommissionGroup
|
24
|
+
def get_commission_group(merchant_id:, commission_group_code:)
|
25
|
+
call(
|
26
|
+
:get_commission_group,
|
27
|
+
iMerchantId: merchant_id,
|
28
|
+
sCommissionGroupCode: commission_group_code,
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets an array of commission groups for an advertiser
|
33
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getCommissionGroupList
|
34
|
+
def get_commission_group_list(merchant_id:)
|
35
|
+
call(:get_commission_group_list, iMerchantId: merchant_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Gets products for the specified transaction # http://wiki.affiliatewindow.com/index.php/AS:getTransactionProduct
|
39
|
+
def get_transaction_product(transaction_ids:)
|
40
|
+
call(:get_transaction_product, aTransactionIds: transaction_ids)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Gets the transactions that fall under the specified criteria
|
44
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getTransactionList
|
45
|
+
def get_transaction_list(merchant_ids: nil, start_date:, end_date:, date_type:, transaction_status: nil, limit: nil, offset: nil)
|
46
|
+
call(
|
47
|
+
:get_transaction_list,
|
48
|
+
aMerchantIds: merchant_ids,
|
49
|
+
dStartDate: start_date,
|
50
|
+
dEndDate: end_date,
|
51
|
+
sDateType: date_type,
|
52
|
+
sTransactionStatus: transaction_status,
|
53
|
+
iLimit: limit,
|
54
|
+
iOffset: offset,
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Gets the requested transactions
|
59
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getTransaction
|
60
|
+
def get_transaction(transaction_ids:)
|
61
|
+
call(:get_transaction, aTransactionIds: transaction_ids)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Gets the requested advertisers
|
65
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getMerchant
|
66
|
+
def get_merchant(merchant_ids:)
|
67
|
+
call(:get_merchant, aMerchantIds: merchant_ids)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets the advertisers that fall under the specified criteria
|
71
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getMerchantList
|
72
|
+
def get_merchant_list(relationship: nil)
|
73
|
+
call(:get_merchant_list, sRelationship: relationship)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Gets the requested transaction queries
|
77
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getTransactionQuerys
|
78
|
+
def get_transaction_queries(merchant_ids: nil, status: nil, click_refs:, offset: nil, limit: nil)
|
79
|
+
call(
|
80
|
+
:get_transaction_queries,
|
81
|
+
aMerchantIds: merchant_ids,
|
82
|
+
aStatus: status,
|
83
|
+
aClickRefs: click_refs,
|
84
|
+
iOffset: offset,
|
85
|
+
iLimit: limit,
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Gets the requested link click stats
|
90
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getClickStats
|
91
|
+
def get_click_stats(start_date:, end_date:, merchant_ids: nil, date_type:, offset: nil, limit: nil)
|
92
|
+
call(
|
93
|
+
:get_click_stats,
|
94
|
+
dStartDate: start_date,
|
95
|
+
dEndDate: end_date,
|
96
|
+
aMerchantIds: merchant_ids,
|
97
|
+
sDateType: date_type,
|
98
|
+
iOffset: offset,
|
99
|
+
iLimit: limit,
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Gets the requested link impression stats
|
104
|
+
# http://wiki.affiliatewindow.com/index.php/AS:getImpressionStats
|
105
|
+
def get_impression_stats(start_date:, end_date:, merchant_ids: nil, date_type:, offset: nil, limit: nil)
|
106
|
+
call(
|
107
|
+
:get_impression_stats,
|
108
|
+
dStartDate: start_date,
|
109
|
+
dEndDate: end_date,
|
110
|
+
aMerchantIds: merchant_ids,
|
111
|
+
sDateType: date_type,
|
112
|
+
iOffset: offset,
|
113
|
+
iLimit: limit,
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def call(method, params)
|
120
|
+
params = remove_nils(params)
|
121
|
+
|
122
|
+
response = error_handler.handle do
|
123
|
+
client.call(method, params, debug)
|
124
|
+
end
|
125
|
+
|
126
|
+
parser.parse(response, method)
|
127
|
+
end
|
128
|
+
|
129
|
+
def remove_nils(params)
|
130
|
+
params.reject { |_, value| value.nil? }
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class AffiliateWindow
|
2
|
+
class Client
|
3
|
+
def initialize(account_id:, affiliate_api_password:)
|
4
|
+
self.savon_client = Savon.client(
|
5
|
+
wsdl: "http://api.affiliatewindow.com/v6/AffiliateService?wsdl",
|
6
|
+
namespace: "http://api.affiliatewindow.com/",
|
7
|
+
soap_header: {
|
8
|
+
"api:UserAuthentication" => {
|
9
|
+
"api:iId" => account_id.to_s,
|
10
|
+
"api:sPassword" => affiliate_api_password,
|
11
|
+
"api:sType" => "affiliate",
|
12
|
+
},
|
13
|
+
},
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(method, params, debug = false)
|
18
|
+
params = convert_to_soap_arrays(params)
|
19
|
+
|
20
|
+
print_request(method, params) if debug
|
21
|
+
savon_client.call(method, message: params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_request(method, params)
|
25
|
+
request = savon_client.build_request(method, message: params)
|
26
|
+
document = REXML::Document.new(request.body)
|
27
|
+
|
28
|
+
formatter = REXML::Formatters::Pretty.new
|
29
|
+
formatter.write(document, $stdout)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def convert_to_soap_arrays(params)
|
35
|
+
params.each.with_object({}) do |(key, value), hash|
|
36
|
+
value = value.is_a?(Array) ? { int: value } : value
|
37
|
+
hash.merge!(key => value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_accessor :savon_client
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AffiliateWindow
|
2
|
+
module Parser
|
3
|
+
def self.parse(response, method)
|
4
|
+
body = response.body
|
5
|
+
root = body.fetch(:"#{method}_response")
|
6
|
+
|
7
|
+
results = root.fetch(:"#{method}_return")
|
8
|
+
pagination = root.fetch(:"#{method}_count_return", nil)
|
9
|
+
|
10
|
+
if pagination
|
11
|
+
{ pagination: pagination, results: results }
|
12
|
+
else
|
13
|
+
results
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: affiliate_window
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Reevoo Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '11.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '11.3'
|
97
|
+
description: A gem for communicating with Affiliate Window's Publisher Service API.
|
98
|
+
email: developers@reevoo.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- README.md
|
104
|
+
- lib/affiliate_window.rb
|
105
|
+
- lib/affiliate_window/base.rb
|
106
|
+
- lib/affiliate_window/client.rb
|
107
|
+
- lib/affiliate_window/error_handler.rb
|
108
|
+
- lib/affiliate_window/parser.rb
|
109
|
+
- lib/affiliate_window/version.rb
|
110
|
+
homepage: https://github.com/reevoo/affiliate_window
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.5.1
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: 'Affiliate Window: Publisher Service API'
|
134
|
+
test_files: []
|