affiliate_window 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 879c6696972ede3c678d902070ada3515332070a
4
- data.tar.gz: 99fdd2cc8dcbc40799a681eb1dbe33e981c95e02
3
+ metadata.gz: 1f599f12f683a8242dc1e001853e42ed561102f8
4
+ data.tar.gz: c1d5e58a250b962fe56aa559e12afbcdb19d26eb
5
5
  SHA512:
6
- metadata.gz: add29aba090cd27d2cb35652d4b8236c425538a84029b9008d9d34d9e5fd0fb4952b7ae62cce4b406469f3f4ebbb6ebc47a3d8efcd4fc44a30371f316d38c414
7
- data.tar.gz: 20b094621c3c50d30c623ac5f1f24891b7f3139e9dd42bdea3bc77d85adc7578b4b50feae194dacd53ce7f888d8dacfee32054991f4f2584c8606a8b7c95f77b
6
+ metadata.gz: 3f57cd4ef2d9c07c0981eec18375789c3343fcbb5286ce661d7c390480ce8ec735bca2b4005767e3e7084aa44cebab56353b6959864581816e5e82c2b554f5f8
7
+ data.tar.gz: 10b9264d5c7c972bfbc6c13f4af6e7dfaa059512712a7d558b1fcc9ea29cafa614782af57d597bab69cbdfed56f0ae17cb73881ea111a6f1b530684a2637ddd9
data/README.md CHANGED
@@ -55,6 +55,19 @@ response
55
55
  # }
56
56
  ```
57
57
 
58
+ ## Quota
59
+
60
+ The API provides a daily quota of 15,000 requests per account. The remaining
61
+ quota is returned in the header of each response. If this quota is reached,
62
+ subsequent requests to the API will raise errors.
63
+
64
+ You can check the remaining quota with:
65
+
66
+ ```ruby
67
+ client.remaining_quota
68
+ #=> 14997
69
+ ```
70
+
58
71
  ## Debugging
59
72
 
60
73
  You can print the SOAP request bodies by enabling debug mode:
@@ -2,7 +2,7 @@
2
2
  # http://wiki.affiliatewindow.com/index.php/Publisher_Service_API
3
3
 
4
4
  class AffiliateWindow
5
- attr_accessor :client, :error_handler, :parser, :debug
5
+ attr_accessor :client, :error_handler, :parser, :debug, :remaining_quota
6
6
 
7
7
  def self.login(account_id:, affiliate_api_password:)
8
8
  client = Client.new(
@@ -114,6 +114,12 @@ class AffiliateWindow
114
114
  )
115
115
  end
116
116
 
117
+ def remaining_quota
118
+ @remaining_quota || raise(UnknownQuotaError,
119
+ "No requests have been made, so the remaining quota is unknown."
120
+ )
121
+ end
122
+
117
123
  private
118
124
 
119
125
  def call(method, params)
@@ -123,10 +129,14 @@ class AffiliateWindow
123
129
  client.call(method, params, debug)
124
130
  end
125
131
 
132
+ self.remaining_quota = parser.parse_quota(response)
133
+
126
134
  parser.parse(response, method)
127
135
  end
128
136
 
129
137
  def remove_nils(params)
130
138
  params.reject { |_, value| value.nil? }
131
139
  end
140
+
141
+ class UnknownQuotaError < StandardError; end
132
142
  end
@@ -10,6 +10,7 @@ class AffiliateWindow
10
10
  "api:sPassword" => affiliate_api_password,
11
11
  "api:sType" => "affiliate",
12
12
  },
13
+ "api:getQuota" => true,
13
14
  },
14
15
  )
15
16
  end
@@ -13,5 +13,12 @@ class AffiliateWindow
13
13
  results
14
14
  end
15
15
  end
16
+
17
+ def self.parse_quota(response)
18
+ header = response.header
19
+ quota = header.fetch(:get_quota_response)
20
+
21
+ Integer(quota)
22
+ end
16
23
  end
17
24
  end
@@ -1,3 +1,3 @@
1
1
  class AffiliateWindow
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: affiliate_window
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reevoo Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon