teilashare 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/checks.yml +26 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +460 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/teilashare/api_resource.rb +61 -0
- data/lib/teilashare/authentication.rb +30 -0
- data/lib/teilashare/client.rb +106 -0
- data/lib/teilashare/errors.rb +13 -0
- data/lib/teilashare/parsers/csv_parser.rb +13 -0
- data/lib/teilashare/parsers/pipe_parser.rb +13 -0
- data/lib/teilashare/parsers/xml_parser.rb +13 -0
- data/lib/teilashare/request.rb +52 -0
- data/lib/teilashare/resources/activity_detail.rb +15 -0
- data/lib/teilashare/resources/activity_summary.rb +11 -0
- data/lib/teilashare/resources/api_resource.rb +63 -0
- data/lib/teilashare/resources/api_token_count.rb +11 -0
- data/lib/teilashare/resources/balance_inquiry.rb +11 -0
- data/lib/teilashare/resources/coupon_deal.rb +11 -0
- data/lib/teilashare/resources/edit_trail.rb +15 -0
- data/lib/teilashare/resources/invalid_links.rb +11 -0
- data/lib/teilashare/resources/ledger_report.rb +11 -0
- data/lib/teilashare/resources/merchant_creative.rb +17 -0
- data/lib/teilashare/resources/merchant_datafeed.rb +11 -0
- data/lib/teilashare/resources/merchant_gift_card.rb +11 -0
- data/lib/teilashare/resources/merchant_search.rb +11 -0
- data/lib/teilashare/resources/merchant_search_by_product.rb +15 -0
- data/lib/teilashare/resources/merchant_status.rb +11 -0
- data/lib/teilashare/resources/merchant_timespan.rb +15 -0
- data/lib/teilashare/resources/monthly_summary.rb +15 -0
- data/lib/teilashare/resources/order_inquiry.rb +15 -0
- data/lib/teilashare/resources/payment_summary.rb +15 -0
- data/lib/teilashare/resources/products.rb +15 -0
- data/lib/teilashare/resources/today_stats.rb +11 -0
- data/lib/teilashare/resources/traffic.rb +15 -0
- data/lib/teilashare/resources/void_trail.rb +15 -0
- data/lib/teilashare/version.rb +5 -0
- data/lib/teilashare.rb +49 -0
- data/teilashare.gemspec +39 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: abb4351dd7c047c4acefb060e5e2c52bc026c7c8ce1a798896d97c5cb19dabaf
|
4
|
+
data.tar.gz: 72e5f25e1ab0813313c16c790586f1ea0dae7575f1037db2698a44db979c4547
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a96dfa2b30317efdf9e97cb6acad582110bc1e0a01be270dae400a17933ff6ffd1973597a122af8ddb33d5505ecf0d1bbcc14ec36aa9e00f55782e25bb053a0
|
7
|
+
data.tar.gz: 93568b6160b12d35cb4f1406841494945dc0f24a742886274bcf2899d3c5915bec4a6abd7f5e6d6c5e6b4dd1e9ebd828b2cbc371545e7b181116a747bf9b86e7
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Tests and Linter
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ main ]
|
5
|
+
pull_request:
|
6
|
+
branches: [ main ]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
|
15
|
+
with:
|
16
|
+
ruby-version: 3.0.0
|
17
|
+
- name: Install dependencies
|
18
|
+
run: bundle install
|
19
|
+
- name: Run tests
|
20
|
+
env:
|
21
|
+
TOKEN: rand-token-not-real
|
22
|
+
AFFILIATE_ID: 123456789
|
23
|
+
API_SECRET: very-secret-secret
|
24
|
+
run: bundle exec rspec
|
25
|
+
- name: Run Rubocop
|
26
|
+
run: bundle exec rubocop
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Thomas Carney
|
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,460 @@
|
|
1
|
+
# Teilashare
|
2
|
+
|
3
|
+
This is an *unofficial* client library for the ShareaSale affiliate reporting API. It does not include the publisher API or any other APIs at the moment. Please see below for the supported endpoints as well as a required and optional parameters on each endpoint.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'teilashare'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install teilashare
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Instantiate a client via:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
credentials = {
|
31
|
+
token: ENV['TOKEN'],
|
32
|
+
api_secret: ENV['API_SECRET'],
|
33
|
+
affiliate_id: ENV['affiliate_id']
|
34
|
+
}
|
35
|
+
|
36
|
+
client = Teilashare.new(credentials)
|
37
|
+
```
|
38
|
+
|
39
|
+
You can then request reports on this client via:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
result = client.today_stats(format: 'xml')
|
43
|
+
```
|
44
|
+
|
45
|
+
Please refer to the Teilashare documentation for required and optional parameters
|
46
|
+
for your desired report. The default format is CSV, but you can request XML format or pipe formatted data (PSV?) via the format option.
|
47
|
+
|
48
|
+
### Activity Details
|
49
|
+
|
50
|
+
required params:
|
51
|
+
- action
|
52
|
+
- version
|
53
|
+
- affiliateId
|
54
|
+
- token
|
55
|
+
- dateStart
|
56
|
+
|
57
|
+
optional
|
58
|
+
- dateEnd
|
59
|
+
- merchantId
|
60
|
+
- lockDate,
|
61
|
+
- paidDate
|
62
|
+
- sortCol
|
63
|
+
- sortDir
|
64
|
+
- XMLFormat
|
65
|
+
- xml_format
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
client.activity_details(
|
69
|
+
start_date: '07-31-2020',
|
70
|
+
end_date: '08-31-2020',
|
71
|
+
merchant_id: 234234234
|
72
|
+
)
|
73
|
+
```
|
74
|
+
|
75
|
+
### Activity Summary
|
76
|
+
required params:
|
77
|
+
- action
|
78
|
+
- version
|
79
|
+
- affiliateId
|
80
|
+
- token
|
81
|
+
|
82
|
+
optional params
|
83
|
+
- merchantId Merchant Id Value
|
84
|
+
- filterCol hits, sales, OR commissions
|
85
|
+
- filterSpan month OR total
|
86
|
+
- filterValue Number
|
87
|
+
- sortCol hitsmonth, salesmonth, salestotal, commissionsmonth, commissionstotal, organization
|
88
|
+
- sortDir asc or desc
|
89
|
+
- XMLFormat 0 or 1
|
90
|
+
- format pipe, xml, csv
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
client.activity_summary(sort_col: 'salestotal', sort_dir: 'asc')
|
94
|
+
```
|
95
|
+
|
96
|
+
### Merchant Timespan Report
|
97
|
+
required params:
|
98
|
+
- dateStart
|
99
|
+
|
100
|
+
optional params
|
101
|
+
- dateEnd mm/dd/yyyy
|
102
|
+
- merchantId Merchant Id Value
|
103
|
+
- sortCol hits, grosssales, reversals, netsales, sales, mcredits, commissions
|
104
|
+
- sortDir asc or desc
|
105
|
+
- XMLFormat 0 or 1
|
106
|
+
- format pipe, xml, csv
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
csv = client.merchant_timespan(date_start: '12/31/2020')
|
110
|
+
```
|
111
|
+
|
112
|
+
### Today's Stats
|
113
|
+
required params
|
114
|
+
- none
|
115
|
+
|
116
|
+
optional params
|
117
|
+
- distinctlink 1 or 0
|
118
|
+
- sortCol commissions, hits, sales
|
119
|
+
- sortDir asc or desc
|
120
|
+
- XMLFormat 0 or 1
|
121
|
+
- format pipe, xml, csv
|
122
|
+
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
client.today_stats(
|
126
|
+
distinct_link: 1,
|
127
|
+
sort_col: 'commissions',
|
128
|
+
sort_dir: 'asc'
|
129
|
+
)
|
130
|
+
```
|
131
|
+
|
132
|
+
### Monthly Summary
|
133
|
+
required params
|
134
|
+
- dateMonth mm/dd/yyyy
|
135
|
+
|
136
|
+
optional params
|
137
|
+
- sortCol merchantId, commissionsum, salesum
|
138
|
+
- sortDir asc or desc
|
139
|
+
- XMLFormat 0 or 1
|
140
|
+
- format pipe, xml, csv
|
141
|
+
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
client.monthly_summary(
|
145
|
+
date_month: '12/01/2020',
|
146
|
+
sort_col: 'commissions',
|
147
|
+
sort_dir: 'asc'
|
148
|
+
)
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
### Void Trail
|
153
|
+
required params
|
154
|
+
- dateStart mm/dd/yyyy
|
155
|
+
|
156
|
+
optional params
|
157
|
+
- dateEnd mm/dd/yyyy
|
158
|
+
- merchantID Valid merchant ID.
|
159
|
+
- XMLFormat 0 or 1
|
160
|
+
- format pipe, xml, csv
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
client.void_trail(
|
164
|
+
date_start: '12/01/2020'
|
165
|
+
)
|
166
|
+
```
|
167
|
+
|
168
|
+
### Traffic
|
169
|
+
required params
|
170
|
+
- dateStart
|
171
|
+
|
172
|
+
optional params
|
173
|
+
- dateEnd mm/dd/yyyy
|
174
|
+
- groupBy bannerID or afftrack
|
175
|
+
- bannerID Valid bannerID value. MerchantID must also be specified when using this parameter. BannerType must also be specified when using this parameter.
|
176
|
+
- afftrack Valid afftrack value. MerchantID must also be specified when using this parameter.
|
177
|
+
- sortCol hits, commissions, numberOfSales, numberOfVoids, conversion, epc
|
178
|
+
- sortDir asc or desc
|
179
|
+
- XMLFormat 0 or 1
|
180
|
+
- format pipe, xml, csv
|
181
|
+
|
182
|
+
conditionally required
|
183
|
+
- bannerType Click for values.
|
184
|
+
- merchantId Valid Merchant Id
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
client.traffic(
|
188
|
+
date_start: '12/01/2020'
|
189
|
+
)
|
190
|
+
```
|
191
|
+
|
192
|
+
### API Token Count
|
193
|
+
required params
|
194
|
+
- n/a
|
195
|
+
|
196
|
+
optional params
|
197
|
+
- XMLFormat 0 or 1
|
198
|
+
- format pipe, xml, csv
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
client.api_token_count
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
|
206
|
+
### Products
|
207
|
+
required params
|
208
|
+
- keyword Word or Phrase
|
209
|
+
|
210
|
+
optional params
|
211
|
+
- merchantId Valid Merchant Id
|
212
|
+
- excludeMerchants List of Merchant Id
|
213
|
+
- XMLFormat 0 or 1
|
214
|
+
- format pipe, xml, csv
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
client.products(
|
218
|
+
keyword: 'wool hats'
|
219
|
+
)
|
220
|
+
```
|
221
|
+
|
222
|
+
### Invalid Links
|
223
|
+
required params
|
224
|
+
- n/a
|
225
|
+
|
226
|
+
optional params
|
227
|
+
- merchantIdList Comma delimited list of valid Merchant IDs
|
228
|
+
- XMLFormat 0 or 1
|
229
|
+
- format pipe, xml, csv
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
client.invalid_links(
|
233
|
+
merchantIdList: 12342,1234234,234234
|
234
|
+
)
|
235
|
+
```
|
236
|
+
|
237
|
+
### Order Inquiry
|
238
|
+
required params
|
239
|
+
- merchantId Valid Merchant Id
|
240
|
+
- orderDate mm/dd/yyyy
|
241
|
+
- orderNumber Merchant's order number (alpha-numeric)
|
242
|
+
|
243
|
+
optional params
|
244
|
+
- XMLFormat 0 or 1
|
245
|
+
- format pipe, xml, csv
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
client.order_inquiry(
|
249
|
+
merchant_id: 1234,
|
250
|
+
order_date: '12/31/2020',
|
251
|
+
order_number: abcdef234
|
252
|
+
)
|
253
|
+
```
|
254
|
+
|
255
|
+
### Merchant Datafeeds
|
256
|
+
required params
|
257
|
+
- n/a
|
258
|
+
|
259
|
+
optional params
|
260
|
+
- blnMemberOf 1 or 0
|
261
|
+
- blnNotMemberOf 1 or 0
|
262
|
+
- category Click for values.
|
263
|
+
- updateDate mm/dd/yyyy
|
264
|
+
- keyword word or phrase
|
265
|
+
- sortCol 7DayEpc, 30DayEpc, saleCommissionAmount, productcount, datafeedupdated, organization
|
266
|
+
- sortDir asc or desc
|
267
|
+
- XMLFormat 0 or 1
|
268
|
+
- format pipe, xml, csv
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
client.merchant_datafeed
|
272
|
+
```
|
273
|
+
|
274
|
+
### Coupon Deals
|
275
|
+
required params
|
276
|
+
- n/a
|
277
|
+
|
278
|
+
optional params
|
279
|
+
- current 1
|
280
|
+
- modifiedSince mm/dd/yyyy
|
281
|
+
- merchantId Valid Merchant Id number.
|
282
|
+
- XMLFormat 0 or 1
|
283
|
+
- format pipe, xml, csv
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
client.coupon_deal
|
287
|
+
```
|
288
|
+
|
289
|
+
### Merchant Status
|
290
|
+
required params
|
291
|
+
- n/a
|
292
|
+
|
293
|
+
optional params
|
294
|
+
- merchantId List of Merchant Id
|
295
|
+
- category Click for values.
|
296
|
+
- programStatus online, offline, lowfunds, onlineNotLowFunds
|
297
|
+
- keyword word or phrase
|
298
|
+
- sortCol organization, salescommission, hitcommission, leadcommission, merchantStatus, category, applydate
|
299
|
+
- sortDir asc or desc
|
300
|
+
- XMLFormat 0 or 1
|
301
|
+
- format pipe, xml, csv
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
client.merchant_status
|
305
|
+
```
|
306
|
+
|
307
|
+
### Merchant Creatives
|
308
|
+
required params
|
309
|
+
- n/a
|
310
|
+
|
311
|
+
optional params
|
312
|
+
- sortCol bannerId, bannerHeight, bannerWidth, category, type
|
313
|
+
- sortDir asc or desc
|
314
|
+
- XMLFormat 0 or 1
|
315
|
+
- format pipe, xml, csv
|
316
|
+
|
317
|
+
conditional params
|
318
|
+
- merchantId Valid Merchant Id. Required unless modifiedDate is present.
|
319
|
+
- modifiedDate Valid date no more than 31 days in the past. Required unless merchantID is present. Format MM/DD/YYYY
|
320
|
+
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
client.merchant_creative
|
324
|
+
```
|
325
|
+
|
326
|
+
|
327
|
+
### Merchant Gift Cards
|
328
|
+
required params
|
329
|
+
- n/a
|
330
|
+
|
331
|
+
optional params
|
332
|
+
- sortCol giftcardId, publishdate, title, merchantId, organization
|
333
|
+
- sortDir asc or desc
|
334
|
+
- XMLFormat 0 or 1
|
335
|
+
- format pipe, xml, csv
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
client.merchant_gift_cards
|
339
|
+
```
|
340
|
+
|
341
|
+
### Edit Trail
|
342
|
+
required params
|
343
|
+
- dateStart mm/dd/yyyy
|
344
|
+
|
345
|
+
optional params
|
346
|
+
- dateEnd mm/dd/yyyy
|
347
|
+
- merchantID Valid merchant ID.
|
348
|
+
- XMLFormat 0 or 1
|
349
|
+
- format pipe, xml, csv
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
client.edit_trail
|
353
|
+
```
|
354
|
+
|
355
|
+
### Payment Summary
|
356
|
+
required params
|
357
|
+
- paymentDate mm/dd/yyyy must be 20th of month in the last 12 months
|
358
|
+
|
359
|
+
optional params
|
360
|
+
|
361
|
+
- sortCol organization, merchantID, commissions, numberofsales
|
362
|
+
- sortDir asc or desc
|
363
|
+
- XMLFormat 0 or 1
|
364
|
+
- format pipe, xml, csv
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
client.payment_summary
|
368
|
+
```
|
369
|
+
|
370
|
+
### Merchant Search
|
371
|
+
required params
|
372
|
+
- n/a
|
373
|
+
|
374
|
+
optional params
|
375
|
+
- Keyword Word or Phrase
|
376
|
+
- Category Click for values.
|
377
|
+
- activatedSince mm/dd/yyyy
|
378
|
+
- -tjoined 1 or 0
|
379
|
+
- datafeed 1 or 0
|
380
|
+
- autodeposit 1 or 0
|
381
|
+
- autoapprove 1 or 0
|
382
|
+
- epc Any number
|
383
|
+
- avgsale Any number
|
384
|
+
- reversalrate Any number
|
385
|
+
- cookielength Any Number
|
386
|
+
- sortCol a7dayepc,a30dayepc,salecommission,leadcommission,hitcommission,organization,organization,startdate,cookielength,powerrank,relationshipID
|
387
|
+
- sortDir asc or desc
|
388
|
+
- XMLFormat 0 or 1
|
389
|
+
- format pipe, xml, csv
|
390
|
+
|
391
|
+
```ruby
|
392
|
+
client.merchant_search(keyword: 'wool')
|
393
|
+
```
|
394
|
+
|
395
|
+
### Merchant Search by Product
|
396
|
+
required params
|
397
|
+
- keyword Word or Phrase
|
398
|
+
|
399
|
+
optional params
|
400
|
+
- -tjoined 1 or 0
|
401
|
+
- merchantId Valid Merchant Id
|
402
|
+
- excludeMerchants List of Merchant Id
|
403
|
+
- XMLFormat 0 or 1
|
404
|
+
- format pipe, xml, csv
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
client.merchant_search_by_product(keyword: 'shoes')
|
408
|
+
```
|
409
|
+
|
410
|
+
### Ledger Report
|
411
|
+
required params
|
412
|
+
- n/a
|
413
|
+
|
414
|
+
optional params
|
415
|
+
- dateStart mm/dd/yyyy
|
416
|
+
- dateEnd mm/dd/yyyy
|
417
|
+
- includeOrderDetails 0 or 1
|
418
|
+
- includeMerchantDetails 0 or 1
|
419
|
+
- XMLFormat 0 or 1
|
420
|
+
- format pipe, xml, csv
|
421
|
+
|
422
|
+
```ruby
|
423
|
+
client.ledger_report
|
424
|
+
```
|
425
|
+
|
426
|
+
### Balance Inquiry
|
427
|
+
required params
|
428
|
+
- n/a
|
429
|
+
|
430
|
+
optional params
|
431
|
+
- XMLFormat 0 or 1
|
432
|
+
- format pipe, xml, csv
|
433
|
+
|
434
|
+
```ruby
|
435
|
+
client.balance_inquiry
|
436
|
+
```
|
437
|
+
|
438
|
+
## Development
|
439
|
+
|
440
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
441
|
+
|
442
|
+
If you want to record API requests, you'll need to export environment variables in the format:
|
443
|
+
|
444
|
+
```bash
|
445
|
+
export TOKEN=abc
|
446
|
+
export AFFILIATE_ID=123456789
|
447
|
+
export API_SECRET=def
|
448
|
+
export API_VERSION=2.3
|
449
|
+
```
|
450
|
+
|
451
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
452
|
+
|
453
|
+
## Contributing
|
454
|
+
|
455
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tommycarney/partagerasale.
|
456
|
+
|
457
|
+
|
458
|
+
## License
|
459
|
+
|
460
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'teilashare'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Teilashare
|
4
|
+
class APIResource
|
5
|
+
PATH = '/x.cfm'
|
6
|
+
HOST = 'api.shareasale.com'
|
7
|
+
|
8
|
+
attr_reader :client, :opts
|
9
|
+
|
10
|
+
def initialize(client, opts = {})
|
11
|
+
@client = client
|
12
|
+
@opts = default_opts.merge(opts).with_indifferent_access
|
13
|
+
validate_required_opts
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
response = Request.new(client, self).call
|
18
|
+
# the API returns 200 OK on invalid authentication GET requests, so need to parse error from body instead
|
19
|
+
raise Errors::InvalidRequestError, response.body if response.body.match?(/\AInvalid Request/)
|
20
|
+
|
21
|
+
parser.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def action_verb
|
25
|
+
raise NotImplementedError, 'please define in a subclass'
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def validate_required_opts
|
31
|
+
missing_opts = []
|
32
|
+
required_opts.each { |opt| missing_opts << opt if opts[opt].nil? }
|
33
|
+
return if missing_opts.empty?
|
34
|
+
|
35
|
+
raise ArgumentError, "#{missing_opts.join(', ')} are missing"
|
36
|
+
end
|
37
|
+
|
38
|
+
def required_opts
|
39
|
+
[]
|
40
|
+
end
|
41
|
+
|
42
|
+
def parser
|
43
|
+
case @opts[:format]
|
44
|
+
when 'csv'
|
45
|
+
Parsers::CsvParser
|
46
|
+
when 'xml'
|
47
|
+
Parsers::XmlParser
|
48
|
+
when 'pipe'
|
49
|
+
Parsers::PipeParser
|
50
|
+
else
|
51
|
+
raise Teilashare::Errors::UnsupportedFormat, "Format: #{@opts[:format]} not supported."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_opts
|
56
|
+
{
|
57
|
+
format: 'csv'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Teilashare
|
4
|
+
class Authentication
|
5
|
+
attr_reader :client, :action_verb
|
6
|
+
|
7
|
+
def initialize(client, action_verb)
|
8
|
+
@client = client
|
9
|
+
@action_verb = action_verb
|
10
|
+
end
|
11
|
+
|
12
|
+
def hash
|
13
|
+
Digest::SHA256.hexdigest(authentication_string).upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def date_string
|
17
|
+
date.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def authentication_string
|
23
|
+
"#{client.token}:#{date_string}:#{action_verb}:#{client.api_secret}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def date
|
27
|
+
@date ||= Time.now.utc
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|