papapi 0.0.1
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +31 -0
- data/lib/papapi.rb +9 -0
- data/lib/papapi/affiliate.rb +26 -0
- data/lib/papapi/affiliate_commission.rb +30 -0
- data/lib/papapi/filter.rb +34 -0
- data/lib/papapi/form_request.rb +28 -0
- data/lib/papapi/form_response.rb +21 -0
- data/lib/papapi/grid_request.rb +34 -0
- data/lib/papapi/grid_response.rb +24 -0
- data/lib/papapi/merchant.rb +18 -0
- data/lib/papapi/merchant_commision.rb +36 -0
- data/lib/papapi/multi_request.rb +27 -0
- data/lib/papapi/request.rb +67 -0
- data/lib/papapi/response.rb +41 -0
- data/lib/papapi/session.rb +62 -0
- data/lib/papapi/version.rb +3 -0
- data/papapi.gemspec +25 -0
- data/spec/affiliate.rb +11 -0
- data/spec/affiliate_commission_spec.rb +10 -0
- data/spec/form_request_spec.rb +15 -0
- data/spec/grid_request_spec.rb +24 -0
- data/spec/helpers/settings.rb +23 -0
- data/spec/merchnat_commision_spec.rb +0 -0
- data/spec/request_spec.rb +16 -0
- data/spec/session_spec.rb +34 -0
- data/spec/spec_helper.rb +21 -0
- metadata +125 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 53aa81d9f5c989af7d1667fadab4c27b2ac049e5
|
|
4
|
+
data.tar.gz: dbd2d020d24d5a9af94cc7b6d3cf5baa8c329870
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 245abc66a25fa7e1c59f65bbe279d75cc9dea63a6292c65101ca00fbf43429fe3ef443bcd047aacfa4a7796b2b42679f97d1e70bc4ff57aa65b5eedefc1077b5
|
|
7
|
+
data.tar.gz: 44f329d9f5986679279e3a84846df124e2f6e4049cf64e9f7f3066ca75e6d90e669fd488468def017633893332c4cb72060e077ce6e14ece0662e753556a0abd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (C) 2011 Dmitry Nizovtsev
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Papapi
|
|
2
|
+
|
|
3
|
+
A gem to interface for Post Affiliate Pro API.
|
|
4
|
+
|
|
5
|
+
# Getting started example
|
|
6
|
+
|
|
7
|
+
Create session as merchant
|
|
8
|
+
```
|
|
9
|
+
session = new Papapi::Session("http://demo.postaffiliatepro.com/scripts/server.php");
|
|
10
|
+
session.login("merchant@example.com", "demo")
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Create session as affiliate in debug mode
|
|
14
|
+
```
|
|
15
|
+
session = new Papapi::Session("http://demo.postaffiliatepro.com/scripts/server.php",true);
|
|
16
|
+
session.login("affiliate@example.com", "demo")
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Get information about affiliate
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
affiliate = Papapi::Affiliate.new(session)
|
|
23
|
+
affiliate.load()
|
|
24
|
+
affiliate[:username]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
More documentation, and examples can be found [there](https://support.qualityunit.com/712031-API)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
data/lib/papapi.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'grid_request'
|
|
3
|
+
require_relative 'multi_request'
|
|
4
|
+
class Affiliate
|
|
5
|
+
|
|
6
|
+
def initialize(session)
|
|
7
|
+
@session = session
|
|
8
|
+
raise "Affiliate session is required" if !@session.is_affiliate?
|
|
9
|
+
@response = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def load
|
|
13
|
+
data = Papapi::FormRequest.new('Pap_Affiliates_Profile_PersonalDetailsForm', 'load', affiliate_session)
|
|
14
|
+
@response = request.send
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def id
|
|
18
|
+
@response ? @response[:userid] : nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def [] (key)
|
|
22
|
+
fields[key.to_sym]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'grid_request'
|
|
3
|
+
require_relative 'multi_request'
|
|
4
|
+
class Affiliate::Commission
|
|
5
|
+
|
|
6
|
+
def initialize(session)
|
|
7
|
+
@session = session
|
|
8
|
+
raise "Affiliate session is required" if !@session.is_affiliate?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def by_orders(order_ids)
|
|
12
|
+
requests = order_ids.map do |order_id|
|
|
13
|
+
r = GridRequest.new("Pap_Affiliates_Reports_TransactionsGrid", "getRows", @session)
|
|
14
|
+
r.set_param("isInitRequest","Y")
|
|
15
|
+
r.set_param("filterType","transaction_filter")
|
|
16
|
+
r.add_filter("orderid","E",order_id)
|
|
17
|
+
r
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
commissions = Hash[order_ids.map {|i| [i.to_s, 0.0]}]
|
|
21
|
+
responses = MultiRequest.new(requests).send
|
|
22
|
+
responses.each do |resp|
|
|
23
|
+
resp.each do |row|
|
|
24
|
+
commissions[row['orderid']] += row['commission'].to_f
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
commissions
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
class Filter
|
|
3
|
+
LIKE = "L"
|
|
4
|
+
NOT_LIKE = "NL"
|
|
5
|
+
EQUALS = "E"
|
|
6
|
+
NOT_EQUALS = "NE"
|
|
7
|
+
|
|
8
|
+
DATE_EQUALS = "D="
|
|
9
|
+
DATE_GREATER = "D>"
|
|
10
|
+
DATE_LOWER = "D<"
|
|
11
|
+
DATE_EQUALS_GREATER = "D>="
|
|
12
|
+
DATE_EQUALS_LOWER = "D<="
|
|
13
|
+
DATERANGE_IS = "DP"
|
|
14
|
+
TIME_EQUALS = "T="
|
|
15
|
+
TIME_GREATER = "T>"
|
|
16
|
+
TIME_LOWER = "T<"
|
|
17
|
+
TIME_EQUALS_GREATER = "T>="
|
|
18
|
+
TIME_EQUALS_LOWER = "T<="
|
|
19
|
+
|
|
20
|
+
RANGE_TODAY = 'T'
|
|
21
|
+
RANGE_YESTERDAY = 'Y'
|
|
22
|
+
RANGE_LAST_7_DAYS = 'L7D'
|
|
23
|
+
RANGE_LAST_30_DAYS = 'L30D'
|
|
24
|
+
RANGE_LAST_90_DAYS = 'L90D'
|
|
25
|
+
RANGE_THIS_WEEK = 'TW'
|
|
26
|
+
RANGE_LAST_WEEK = 'LW'
|
|
27
|
+
RANGE_LAST_2WEEKS = 'L2W'
|
|
28
|
+
RANGE_LAST_WORKING_WEEK = 'LWW'
|
|
29
|
+
RANGE_THIS_MONTH = 'TM'
|
|
30
|
+
RANGE_LAST_MONTH = 'LM'
|
|
31
|
+
RANGE_THIS_YEAR = 'TY'
|
|
32
|
+
RANGE_LAST_YEAR = 'LY'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'request'
|
|
3
|
+
class FormRequest < Request
|
|
4
|
+
|
|
5
|
+
def set_field(key, value)
|
|
6
|
+
@fields = [["name", "value"]] if ! @fields
|
|
7
|
+
@fields.push([key, value])
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def set_fields(f)
|
|
11
|
+
@fields = [["name", "value"]] if ! @fields
|
|
12
|
+
f.each do |key, value|
|
|
13
|
+
@fields << [key, value]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def response(http_response)
|
|
18
|
+
FormResponse.new(http_response, self)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_data
|
|
22
|
+
data = super
|
|
23
|
+
data[:fields] = @fields if @fields
|
|
24
|
+
data
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'response'
|
|
3
|
+
class FormResponse < Response
|
|
4
|
+
|
|
5
|
+
def fields
|
|
6
|
+
unless @fields
|
|
7
|
+
@fields = {}
|
|
8
|
+
self.parsed['fields'].each do |field|
|
|
9
|
+
next if REMOVE_VARS.include? field[0]
|
|
10
|
+
@fields[field[0].to_sym] = field[1]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
@fields
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [] (key)
|
|
17
|
+
fields[key.to_sym]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'request'
|
|
3
|
+
class GridRequest < Request
|
|
4
|
+
DEFAULT_LIMIT = 30
|
|
5
|
+
|
|
6
|
+
attr_accessor :sort_col, :sort_asc, :offset, :limit
|
|
7
|
+
|
|
8
|
+
def add_filter(code, op, value)
|
|
9
|
+
@filters = [] if ! @filters
|
|
10
|
+
@filters << [code , op, value]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def response(http_response)
|
|
14
|
+
GridResponse.new(http_response, self)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_column(column)
|
|
18
|
+
@columns = [['id']] if ! @columns
|
|
19
|
+
@columns << [column]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_data
|
|
23
|
+
data = super
|
|
24
|
+
data[:filters] = @filters || []
|
|
25
|
+
data[:columns] = @columns || []
|
|
26
|
+
data[:sort_col] = sort_col || ""
|
|
27
|
+
data[:sort_asc] = sort_asc || false
|
|
28
|
+
data[:offset] = offset || 0
|
|
29
|
+
data[:limit] = limit || DEFAULT_LIMIT
|
|
30
|
+
data
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'response'
|
|
3
|
+
class GridResponse < Response
|
|
4
|
+
include Enumerable
|
|
5
|
+
|
|
6
|
+
def attributes
|
|
7
|
+
parsed['rows'].first
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def count
|
|
11
|
+
parsed['count']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def rows
|
|
15
|
+
parsed['rows'].slice(1, parsed['rows'].count-1)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def each
|
|
19
|
+
rows.each do |row|
|
|
20
|
+
yield Hash[*attributes.zip(row).flatten]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'grid_request'
|
|
3
|
+
class Merchant
|
|
4
|
+
|
|
5
|
+
def initialize(session)
|
|
6
|
+
@session = session
|
|
7
|
+
raise "Merchant session is required" if !@session.is_merchant?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def details
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def load
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
require_relative 'grid_request'
|
|
3
|
+
require_relative 'merchant'
|
|
4
|
+
class Merchant::Commission
|
|
5
|
+
|
|
6
|
+
def initialize(session)
|
|
7
|
+
@session = session
|
|
8
|
+
raise "Merchant session is required" if !@session.is_merchant?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def by_orders(order_ids,affiliate_id = nil)
|
|
12
|
+
requests = order_ids.map do |order_id|
|
|
13
|
+
r = GridRequest.new("Pap_Merchants_Transaction_TransactionsGrid", "getRows", @session)
|
|
14
|
+
r.set_param("isInitRequest","Y")
|
|
15
|
+
r.set_param("filterType","transaction_filter")
|
|
16
|
+
r.add_filter("orderid","E",order_id)
|
|
17
|
+
r.add_filter("userid","E",affiliate_id) if affiliate_id
|
|
18
|
+
r.add_column("id")
|
|
19
|
+
r.add_column("userid")
|
|
20
|
+
r.add_column("commission")
|
|
21
|
+
r.add_column("orderid")
|
|
22
|
+
r
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
commissions = Hash[order_ids.map {|i| [i.to_s, 0.0]}]
|
|
26
|
+
responses = MultiRequest.new(requests).send
|
|
27
|
+
responses.each do |resp|
|
|
28
|
+
resp.each do |row|
|
|
29
|
+
commissions[row['orderid']] += row['commission'].to_f
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
commissions
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
class MultiRequest
|
|
3
|
+
|
|
4
|
+
def initialize(requests = nil)
|
|
5
|
+
@request = nil
|
|
6
|
+
if requests && requests.length > 0
|
|
7
|
+
@request = requests[0]
|
|
8
|
+
requests.slice(1, requests.count-1).each do |r|
|
|
9
|
+
@request.add_request(r)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_request(request)
|
|
15
|
+
if ! @request
|
|
16
|
+
@request = request
|
|
17
|
+
else
|
|
18
|
+
@request.add_request(request)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def send
|
|
23
|
+
resp = @request.send
|
|
24
|
+
[resp] + resp.responses
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
class Request
|
|
3
|
+
|
|
4
|
+
SERVER_CLASS_NAME = 'Gpf_Rpc_Server'
|
|
5
|
+
RUN_METHOD = 'run'
|
|
6
|
+
BODY_DATA_NAME = 'D'
|
|
7
|
+
|
|
8
|
+
attr_accessor :class_name,
|
|
9
|
+
:method_name,
|
|
10
|
+
:session
|
|
11
|
+
|
|
12
|
+
attr_reader :requests
|
|
13
|
+
|
|
14
|
+
def initialize (class_name, method_name, session)
|
|
15
|
+
@class_name = class_name
|
|
16
|
+
@method_name = method_name
|
|
17
|
+
@session = session
|
|
18
|
+
@params = {}
|
|
19
|
+
@requests = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set_param(name, value)
|
|
23
|
+
@params[name] = value
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def set_params(p)
|
|
27
|
+
@params = @params.merge(p)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_request(request)
|
|
31
|
+
@requests << request
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_data
|
|
35
|
+
{
|
|
36
|
+
"C" => @class_name,
|
|
37
|
+
"M" => @method_name,
|
|
38
|
+
}.merge(@params)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def send
|
|
42
|
+
vars = {
|
|
43
|
+
"C" => SERVER_CLASS_NAME,
|
|
44
|
+
"M" => RUN_METHOD,
|
|
45
|
+
"isFromApi" => "Y",
|
|
46
|
+
"requests" => ([self] + @requests).map { |r| r.to_data }
|
|
47
|
+
}
|
|
48
|
+
vars['S'] = @session.id if @session && @session.id
|
|
49
|
+
|
|
50
|
+
request_body = {BODY_DATA_NAME => vars.to_json }
|
|
51
|
+
|
|
52
|
+
p "REQUEST# #{vars}" if @session.debug
|
|
53
|
+
http_response = send_now(@session.url, request_body)
|
|
54
|
+
p "RESPONE# #{http_response.body}" if session.debug
|
|
55
|
+
response(http_response)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def response(http_response)
|
|
59
|
+
Response.new(http_response, self)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def send_now(url, request_body)
|
|
63
|
+
Net::HTTP.post_form(URI.parse(url), request_body)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
class Response
|
|
3
|
+
|
|
4
|
+
REMOVE_VARS = ['name', 'correspondsApi', 'language']
|
|
5
|
+
|
|
6
|
+
attr_reader :responses
|
|
7
|
+
|
|
8
|
+
def initialize (http_response, request)
|
|
9
|
+
@http_response = http_response
|
|
10
|
+
@request = request
|
|
11
|
+
@responses = []
|
|
12
|
+
check_for_errors
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def parsed
|
|
16
|
+
return @parsed if @parsed
|
|
17
|
+
if @http_response.is_a? Net::HTTPResponse
|
|
18
|
+
parsed_response = JSON.parse(@http_response.body)
|
|
19
|
+
@parsed = parsed_response.shift
|
|
20
|
+
|
|
21
|
+
#handle multi responses
|
|
22
|
+
@request.requests.each do |req|
|
|
23
|
+
resp = parsed_response.shift
|
|
24
|
+
@responses << req.response(resp) if resp
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
@parsed = @http_response
|
|
28
|
+
end
|
|
29
|
+
@parsed
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def check_for_errors
|
|
35
|
+
return if ! parsed.kind_of?(Hash)
|
|
36
|
+
raise parsed['message'] if parsed['success'] != 'Y' && parsed['message']
|
|
37
|
+
raise parsed['e'] if parsed['e']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Papapi
|
|
2
|
+
class Session
|
|
3
|
+
|
|
4
|
+
MERCHANT = 'M'
|
|
5
|
+
AFFILIATE = 'A'
|
|
6
|
+
API_VERSION = '70544a5f74e11e13b7b61c4d98ae77e'
|
|
7
|
+
AUTHENTICATE_CLASS_NAME = 'Gpf_Api_AuthService'
|
|
8
|
+
AUTHENTICATE_METHOD_NAME = 'authenticate'
|
|
9
|
+
|
|
10
|
+
attr_reader :url
|
|
11
|
+
attr_accessor :debug
|
|
12
|
+
|
|
13
|
+
def initialize (url, debug = false)
|
|
14
|
+
@url = url
|
|
15
|
+
@debug = debug
|
|
16
|
+
@response = nil
|
|
17
|
+
@role = nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def login (username, password, role = Session::MERCHANT, languageCode = 'en-US')
|
|
21
|
+
request = FormRequest.new(AUTHENTICATE_CLASS_NAME, AUTHENTICATE_METHOD_NAME, self)
|
|
22
|
+
request.set_fields({
|
|
23
|
+
:username => username,
|
|
24
|
+
:password => password,
|
|
25
|
+
:roleType => role,
|
|
26
|
+
:apiVersion => API_VERSION,
|
|
27
|
+
:language => languageCode
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
@response = request.send
|
|
31
|
+
@role = role
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def loginWithAuthToken(auth_token, role = Session::MERCHANT,languageCode = 'en-US')
|
|
36
|
+
request = FormRequest.new(AUTHENTICATE_CLASS_NAME, AUTHENTICATE_METHOD_NAME, self)
|
|
37
|
+
request.set_fields({
|
|
38
|
+
:authToken => auth_token,
|
|
39
|
+
:roleType => role,
|
|
40
|
+
:apiVersion => API_VERSION,
|
|
41
|
+
:language => languageCode
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
@response = request.send
|
|
45
|
+
@role = role
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def id
|
|
50
|
+
@response ? @response[:S] : nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def is_merchant?
|
|
54
|
+
@role && @role == MERCHANT
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def is_affiliate?
|
|
58
|
+
@role && @role == AFFILIATE
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
data/papapi.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'papapi/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "papapi"
|
|
8
|
+
spec.version = Papapi::VERSION
|
|
9
|
+
spec.authors = ["Dmitry Nizovtsev"]
|
|
10
|
+
spec.email = ["dmitry@rubyriders.com"]
|
|
11
|
+
spec.summary = %q{A client for the Post Affiliate Pro API}
|
|
12
|
+
spec.homepage = "https://github.com/JSBizon/papapi"
|
|
13
|
+
spec.description = "Low level API for Post Affiliate Pro GridRequest, FormRequest, etc"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
25
|
+
end
|
data/spec/affiliate.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::Affiliate::Commission do
|
|
5
|
+
it "#send" do
|
|
6
|
+
session = Papapi::Session.new(script_url).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
7
|
+
affiliate = Papapi::Affiliate.new(session)
|
|
8
|
+
affiliate.load()
|
|
9
|
+
expect(affiliate.id).to be eql('11111111')
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::Affiliate::Commission do
|
|
5
|
+
it "#send" do
|
|
6
|
+
session = Papapi::Session.new(script_url).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
7
|
+
commission = Papapi::Affiliate::Commission.new(session)
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::FormRequest do
|
|
5
|
+
|
|
6
|
+
context "load affiliate details" do
|
|
7
|
+
it "#send" do
|
|
8
|
+
affiliate_session = Papapi::Session.new(script_url).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
9
|
+
request = Papapi::FormRequest.new('Pap_Affiliates_Profile_PersonalDetailsForm', 'load', affiliate_session)
|
|
10
|
+
response = request.send
|
|
11
|
+
expect(response[:username]).to eql('affiliate@example.com')
|
|
12
|
+
expect(response['username']).to eql('affiliate@example.com')
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::GridRequest do
|
|
5
|
+
|
|
6
|
+
context "load merchant transaction grid" do
|
|
7
|
+
it "#send" do
|
|
8
|
+
merchant_session = Papapi::Session.new(script_url).login(merchant_login, merchant_password)
|
|
9
|
+
request = Papapi::GridRequest.new("Pap_Merchants_Transaction_TransactionsGrid", "getRows", merchant_session)
|
|
10
|
+
request.add_filter('userid', 'E', '11111111')
|
|
11
|
+
response = request.send
|
|
12
|
+
expect(response.count).to be > 1
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "load affiliate transaction grid" do
|
|
17
|
+
it "#send" do
|
|
18
|
+
affiliate_session = Papapi::Session.new(script_url,true).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
19
|
+
request = Papapi::GridRequest.new("Pap_Affiliates_Reports_TransactionsGrid", "getRows", affiliate_session)
|
|
20
|
+
response = request.send
|
|
21
|
+
expect(response.count).to be > 1
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Helpers
|
|
2
|
+
module Settings
|
|
3
|
+
def script_url
|
|
4
|
+
'http://demo.postaffiliatepro.com/scripts/server.php'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def merchant_login
|
|
8
|
+
'merchant@example.com'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def merchant_password
|
|
12
|
+
'demo'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def affiliate_login
|
|
16
|
+
'affiliate@example.com'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def affiliate_password
|
|
20
|
+
'demo'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::Request do
|
|
5
|
+
let(:session) { Papapi::Session.new(script_url,true).login(merchant_login, merchant_password) }
|
|
6
|
+
|
|
7
|
+
context "load statistics data" do
|
|
8
|
+
it "#send" do
|
|
9
|
+
request = Papapi::Request.new('Pap_Merchants_Reports_TrafficStatsData', 'load', session)
|
|
10
|
+
request.set_param('filters', [["rstatus", "IN", 'A'],["datetime", Papapi::Filter::DATERANGE_IS, Papapi::Filter::RANGE_LAST_30_DAYS]])
|
|
11
|
+
response = request.send
|
|
12
|
+
expect(response.parsed.kind_of?(Array)).to be true
|
|
13
|
+
expect(response.parsed.length).to eq(6)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'papapi'
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Papapi::Session do
|
|
5
|
+
let(:session) { described_class.new(script_url) }
|
|
6
|
+
|
|
7
|
+
context "as merchant" do
|
|
8
|
+
it "#login ok" do
|
|
9
|
+
expect(session.id).to be_nil
|
|
10
|
+
session.login(merchant_login, merchant_password)
|
|
11
|
+
expect(session.id).to_not be_nil
|
|
12
|
+
expect(session.id.length).to be > 8
|
|
13
|
+
expect(session.is_merchant?).to be true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "#login not ok" do
|
|
17
|
+
expect { session.login("bad login", "bad password") }.to raise_error
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "as affiliate" do
|
|
22
|
+
it "#login ok" do
|
|
23
|
+
expect(session.id).to be_nil
|
|
24
|
+
session.login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
25
|
+
expect(session.id).to_not be_nil
|
|
26
|
+
expect(session.id.length).to be > 8
|
|
27
|
+
expect(session.is_affiliate?).to be true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "#login not ok" do
|
|
31
|
+
expect { session.login("bad login", "bad password", Papapi::Session::AFFILIATE) }.to raise_error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
|
4
|
+
# loaded once.
|
|
5
|
+
#
|
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
7
|
+
|
|
8
|
+
require "papapi"
|
|
9
|
+
require "helpers/settings"
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
config.run_all_when_everything_filtered = true
|
|
13
|
+
config.filter_run :focus
|
|
14
|
+
|
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
17
|
+
# the seed, which is printed after each run.
|
|
18
|
+
# --seed 1234
|
|
19
|
+
config.order = 'random'
|
|
20
|
+
config.include Helpers::Settings
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: papapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dmitry Nizovtsev
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.7'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.4'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.4'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.2'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.2'
|
|
55
|
+
description: Low level API for Post Affiliate Pro GridRequest, FormRequest, etc
|
|
56
|
+
email:
|
|
57
|
+
- dmitry@rubyriders.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE
|
|
66
|
+
- README.md
|
|
67
|
+
- lib/papapi.rb
|
|
68
|
+
- lib/papapi/affiliate.rb
|
|
69
|
+
- lib/papapi/affiliate_commission.rb
|
|
70
|
+
- lib/papapi/filter.rb
|
|
71
|
+
- lib/papapi/form_request.rb
|
|
72
|
+
- lib/papapi/form_response.rb
|
|
73
|
+
- lib/papapi/grid_request.rb
|
|
74
|
+
- lib/papapi/grid_response.rb
|
|
75
|
+
- lib/papapi/merchant.rb
|
|
76
|
+
- lib/papapi/merchant_commision.rb
|
|
77
|
+
- lib/papapi/multi_request.rb
|
|
78
|
+
- lib/papapi/request.rb
|
|
79
|
+
- lib/papapi/response.rb
|
|
80
|
+
- lib/papapi/session.rb
|
|
81
|
+
- lib/papapi/version.rb
|
|
82
|
+
- papapi.gemspec
|
|
83
|
+
- spec/affiliate.rb
|
|
84
|
+
- spec/affiliate_commission_spec.rb
|
|
85
|
+
- spec/form_request_spec.rb
|
|
86
|
+
- spec/grid_request_spec.rb
|
|
87
|
+
- spec/helpers/settings.rb
|
|
88
|
+
- spec/merchnat_commision_spec.rb
|
|
89
|
+
- spec/request_spec.rb
|
|
90
|
+
- spec/session_spec.rb
|
|
91
|
+
- spec/spec_helper.rb
|
|
92
|
+
homepage: https://github.com/JSBizon/papapi
|
|
93
|
+
licenses:
|
|
94
|
+
- MIT
|
|
95
|
+
metadata: {}
|
|
96
|
+
post_install_message:
|
|
97
|
+
rdoc_options: []
|
|
98
|
+
require_paths:
|
|
99
|
+
- lib
|
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
requirements: []
|
|
111
|
+
rubyforge_project:
|
|
112
|
+
rubygems_version: 2.4.5
|
|
113
|
+
signing_key:
|
|
114
|
+
specification_version: 4
|
|
115
|
+
summary: A client for the Post Affiliate Pro API
|
|
116
|
+
test_files:
|
|
117
|
+
- spec/affiliate.rb
|
|
118
|
+
- spec/affiliate_commission_spec.rb
|
|
119
|
+
- spec/form_request_spec.rb
|
|
120
|
+
- spec/grid_request_spec.rb
|
|
121
|
+
- spec/helpers/settings.rb
|
|
122
|
+
- spec/merchnat_commision_spec.rb
|
|
123
|
+
- spec/request_spec.rb
|
|
124
|
+
- spec/session_spec.rb
|
|
125
|
+
- spec/spec_helper.rb
|