papapi 0.1.6 → 0.1.11
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 +5 -5
- data/README.md +18 -8
- data/lib/papapi/affiliate.rb +85 -3
- data/lib/papapi/form_request.rb +17 -1
- data/lib/papapi/form_response.rb +4 -0
- data/lib/papapi/grid_response.rb +10 -0
- data/lib/papapi/merchant.rb +22 -4
- data/lib/papapi/response.rb +10 -1
- data/lib/papapi/version.rb +1 -1
- data/spec/affiliate_spec.rb +44 -1
- data/spec/merchant_spec.rb +13 -2
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cd6aad4e54fde1cad008bb55236d5349a8c2a487be5def0c8b9377ffa886ef1f
|
|
4
|
+
data.tar.gz: 215b4a2c4cb47a56c2ffaa50c63a9750cd7db22ef6ec836cc04132fb9804b33d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c0935bd1dadd5178058896604da6646f09f997d86a72d8fea5b3fcc258d9b83ca3835080528b2220d24288783f75590fa354b6715b5555bc2002853aad12da3
|
|
7
|
+
data.tar.gz: 46b3a778eb747eaa532bada7b29465eaec1c88897023142a0302f153e7d42401a610b99fb2a25bd6cc6e4bd35c1e330dff3e76f3134564cd3533ccc392e095f2
|
data/README.md
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
# Papapi
|
|
2
2
|
|
|
3
|
-
A gem to
|
|
3
|
+
A gem for access to the Post Affiliate Pro API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Getting started example
|
|
6
6
|
|
|
7
|
-
Create session as merchant
|
|
8
|
-
|
|
7
|
+
###Create session as merchant
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
9
10
|
session = new Papapi::Session("http://demo.postaffiliatepro.com/scripts/server.php");
|
|
10
11
|
session.login("merchant@example.com", "demo")
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
Create session as affiliate in debug mode
|
|
14
|
-
|
|
14
|
+
###Create session as affiliate in debug mode
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
15
17
|
session = new Papapi::Session("http://demo.postaffiliatepro.com/scripts/server.php",true);
|
|
16
18
|
session.login("affiliate@example.com", "demo")
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
Get information about affiliate
|
|
21
|
+
###Get information about affiliate
|
|
20
22
|
|
|
21
|
-
```
|
|
23
|
+
```ruby
|
|
22
24
|
affiliate = Papapi::Affiliate.new(session)
|
|
23
25
|
affiliate.load()
|
|
24
26
|
affiliate[:username]
|
|
25
27
|
```
|
|
26
28
|
|
|
29
|
+
###Get information about merchant
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
merchant = Papapi::Merchant.new(session)
|
|
33
|
+
merchant.load()
|
|
34
|
+
merchant[:username]
|
|
35
|
+
```
|
|
36
|
+
|
|
27
37
|
More documentation, and examples can be found [there](https://support.qualityunit.com/712031-API)
|
|
28
38
|
|
|
29
39
|
|
data/lib/papapi/affiliate.rb
CHANGED
|
@@ -3,25 +3,107 @@ module Papapi
|
|
|
3
3
|
require_relative 'multi_request'
|
|
4
4
|
class Affiliate
|
|
5
5
|
|
|
6
|
+
A_ALLOWED_FIELDS = [:username, :rpassword, :firstname, :lastname, :photo, :refid, :data1, :data2, :data3,
|
|
7
|
+
:data4, :data5, :data6, :data7, :data8, :data9, :data10, :data11, :data12, :data13,
|
|
8
|
+
:data14, :data15, :data16, :data17, :data18, :data19, :data20, :data21, :data22,
|
|
9
|
+
:data23, :data24, :data25
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
M_ALLOWED_FIELDS = [:parentuserid, :rstatus, :agreeWithTerms] | A_ALLOWED_FIELDS
|
|
13
|
+
|
|
14
|
+
attr_accessor :response
|
|
15
|
+
|
|
6
16
|
def initialize(session, response = nil)
|
|
7
17
|
@session = session
|
|
8
|
-
|
|
18
|
+
if @session.is_affiliate?
|
|
19
|
+
@load_class = 'Pap_Affiliates_Profile_PersonalDetailsForm'
|
|
20
|
+
@save_class = 'Pap_Affiliates_Profile_PersonalDetailsForm'
|
|
21
|
+
else
|
|
22
|
+
@load_class = 'Pap_Signup_AffiliateForm'
|
|
23
|
+
@save_class = 'Pap_Merchants_User_AffiliateForm'
|
|
24
|
+
end
|
|
9
25
|
@response = response
|
|
26
|
+
@user_id = nil
|
|
27
|
+
@update_fields = {}
|
|
10
28
|
end
|
|
11
29
|
|
|
30
|
+
|
|
12
31
|
def load
|
|
13
|
-
request = Papapi::FormRequest.new(
|
|
32
|
+
request = Papapi::FormRequest.new(@load_class, 'load', @session)
|
|
33
|
+
|
|
34
|
+
unless @user_id.nil?
|
|
35
|
+
request.set_field("Id", @user_id)
|
|
36
|
+
request.set_field("userid", @user_id)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@response = request.send
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def save
|
|
45
|
+
raise "Affiliate id is required" if @session.is_merchant? && ! self.id
|
|
46
|
+
|
|
47
|
+
request = Papapi::FormRequest.new(@save_class, 'save', @session)
|
|
48
|
+
|
|
49
|
+
if @response
|
|
50
|
+
@response.fields.each do |key, value|
|
|
51
|
+
request.set_field(key, value) if (@session.is_affiliate? && A_ALLOWED_FIELDS.include?(key.to_sym)) ||
|
|
52
|
+
(@session.is_merchant? && M_ALLOWED_FIELDS.include?(key.to_sym))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@update_fields.each do |key, value|
|
|
57
|
+
request.set_field(key, value) if (@session.is_affiliate? && A_ALLOWED_FIELDS.include?(key.to_sym)) ||
|
|
58
|
+
(@session.is_merchant? && M_ALLOWED_FIELDS.include?(key.to_sym))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if @session.is_affiliate?
|
|
62
|
+
request.set_field("Id", "")
|
|
63
|
+
else
|
|
64
|
+
request.set_field("Id", self.id)
|
|
65
|
+
end
|
|
66
|
+
|
|
14
67
|
@response = request.send
|
|
68
|
+
@update_fields = {}
|
|
15
69
|
self
|
|
16
70
|
end
|
|
17
71
|
|
|
72
|
+
|
|
18
73
|
def id
|
|
19
|
-
@response ? @response[:userid] :
|
|
74
|
+
@response ? @response[:userid] : @user_id
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def getLoginKey
|
|
78
|
+
raise "Merchant session is required" if @session.is_affiliate?
|
|
79
|
+
|
|
80
|
+
request = Papapi::FormRequest.new('Pap_Auth_LoginKeyService', 'getLoginKey', @session)
|
|
81
|
+
request.set_param("userId", self.id)
|
|
82
|
+
|
|
83
|
+
response = request.send
|
|
84
|
+
|
|
85
|
+
return response[:LoginKey]
|
|
20
86
|
end
|
|
21
87
|
|
|
88
|
+
def id=(user_id)
|
|
89
|
+
@user_id = user_id
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
22
93
|
def [] (key)
|
|
23
94
|
@response ? @response[key.to_sym] : nil
|
|
24
95
|
end
|
|
25
96
|
|
|
97
|
+
|
|
98
|
+
def []= (key, value)
|
|
99
|
+
raise "Field #{key} can not be modified" if (@session.is_affiliate? && ! A_ALLOWED_FIELDS.include?(key.to_sym)) ||
|
|
100
|
+
(@session.is_merchant? && ! M_ALLOWED_FIELDS.include?(key.to_sym))
|
|
101
|
+
@update_fields[key.to_sym] = value
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def to_h
|
|
105
|
+
response ? response.to_h : {}
|
|
106
|
+
end
|
|
107
|
+
|
|
26
108
|
end
|
|
27
109
|
end
|
data/lib/papapi/form_request.rb
CHANGED
|
@@ -3,15 +3,25 @@ module Papapi
|
|
|
3
3
|
class FormRequest < Request
|
|
4
4
|
|
|
5
5
|
def set_field(key, value)
|
|
6
|
+
@fields = {} if ! @fields
|
|
7
|
+
@fields[key.to_sym] = value
|
|
8
|
+
=begin
|
|
6
9
|
@fields = [["name", "value"]] if ! @fields
|
|
7
10
|
@fields.push([key, value])
|
|
11
|
+
=end
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
def set_fields(f)
|
|
15
|
+
@fields = {} if ! @fields
|
|
16
|
+
f.each do |key, value|
|
|
17
|
+
@fields[key.to_sym] = value
|
|
18
|
+
end
|
|
19
|
+
=begin
|
|
11
20
|
@fields = [["name", "value"]] if ! @fields
|
|
12
21
|
f.each do |key, value|
|
|
13
22
|
@fields << [key, value]
|
|
14
23
|
end
|
|
24
|
+
=end
|
|
15
25
|
end
|
|
16
26
|
|
|
17
27
|
def response(http_response)
|
|
@@ -20,7 +30,13 @@ module Papapi
|
|
|
20
30
|
|
|
21
31
|
def to_data
|
|
22
32
|
data = super
|
|
23
|
-
|
|
33
|
+
if @fields
|
|
34
|
+
data_fields = [["name", "value"]]
|
|
35
|
+
@fields.each do |key, value|
|
|
36
|
+
data_fields << [key, value]
|
|
37
|
+
end
|
|
38
|
+
data[:fields] = data_fields
|
|
39
|
+
end
|
|
24
40
|
data
|
|
25
41
|
end
|
|
26
42
|
|
data/lib/papapi/form_response.rb
CHANGED
data/lib/papapi/grid_response.rb
CHANGED
|
@@ -15,10 +15,20 @@ module Papapi
|
|
|
15
15
|
parsed['rows'].slice(1, parsed['rows'].count-1)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def [] (key)
|
|
19
|
+
if rows[key.to_i]
|
|
20
|
+
return Hash[*attributes.zip(rows[key.to_i]).flatten]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
18
24
|
def each
|
|
19
25
|
rows.each do |row|
|
|
20
26
|
yield Hash[*attributes.zip(row).flatten]
|
|
21
27
|
end
|
|
22
28
|
end
|
|
29
|
+
|
|
30
|
+
def to_a
|
|
31
|
+
rows
|
|
32
|
+
end
|
|
23
33
|
end
|
|
24
34
|
end
|
data/lib/papapi/merchant.rb
CHANGED
|
@@ -16,6 +16,8 @@ module Papapi
|
|
|
16
16
|
:phone => :data8
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
attr_accessor :response
|
|
20
|
+
|
|
19
21
|
def initialize(session, response = nil)
|
|
20
22
|
@session = session
|
|
21
23
|
raise "Merchant session is required" if !@session.is_merchant?
|
|
@@ -32,10 +34,6 @@ module Papapi
|
|
|
32
34
|
request.set_fields(request_fields)
|
|
33
35
|
response = request.send
|
|
34
36
|
response
|
|
35
|
-
#affiliate = Papapi::Affiliate.new(Papapi::Session.new(@session.url).
|
|
36
|
-
# login(request_fields[:username], request_fields[:rpassword], Papapi::Session::AFFILIATE))
|
|
37
|
-
#affiliate.load
|
|
38
|
-
#affiliate
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def remove_affiliate(affiliate_id)
|
|
@@ -103,6 +101,22 @@ module Papapi
|
|
|
103
101
|
affiliates
|
|
104
102
|
end
|
|
105
103
|
|
|
104
|
+
def affiliate_by_username(username)
|
|
105
|
+
request = Papapi::GridRequest.new("Pap_Merchants_User_AffiliatesGridSimple", "getRows", @session)
|
|
106
|
+
request.add_filter('username', Papapi::Filter::EQUALS, username)
|
|
107
|
+
|
|
108
|
+
response = request.send
|
|
109
|
+
if response.count > 0
|
|
110
|
+
user = response[0]
|
|
111
|
+
p user['id']
|
|
112
|
+
affiliate = Papapi::Affiliate.new(@session)
|
|
113
|
+
affiliate.id = user['userid'] || user['id']
|
|
114
|
+
affiliate.load
|
|
115
|
+
return affiliate
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
106
120
|
def id
|
|
107
121
|
@response ? @response[:authid] : nil
|
|
108
122
|
end
|
|
@@ -111,5 +125,9 @@ module Papapi
|
|
|
111
125
|
@response ? @response[key.to_sym] : nil
|
|
112
126
|
end
|
|
113
127
|
|
|
128
|
+
def to_h
|
|
129
|
+
response ? response.to_h : {}
|
|
130
|
+
end
|
|
131
|
+
|
|
114
132
|
end
|
|
115
133
|
end
|
data/lib/papapi/response.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Papapi
|
|
2
2
|
class Response
|
|
3
|
-
|
|
4
3
|
REMOVE_VARS = ['name', 'correspondsApi', 'language']
|
|
5
4
|
|
|
6
5
|
attr_reader :responses
|
|
6
|
+
attr_reader :request
|
|
7
7
|
|
|
8
8
|
def initialize (http_response, request)
|
|
9
9
|
@http_response = http_response
|
|
@@ -29,6 +29,15 @@ module Papapi
|
|
|
29
29
|
@parsed
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def to_h
|
|
33
|
+
h = {}
|
|
34
|
+
parsed.each_with_index do |p, index|
|
|
35
|
+
next if index == 0
|
|
36
|
+
h[p[0].to_sym] = p[1]
|
|
37
|
+
end
|
|
38
|
+
h
|
|
39
|
+
end
|
|
40
|
+
|
|
32
41
|
private
|
|
33
42
|
|
|
34
43
|
def check_for_errors
|
data/lib/papapi/version.rb
CHANGED
data/spec/affiliate_spec.rb
CHANGED
|
@@ -5,8 +5,51 @@ RSpec.describe Papapi::Affiliate::Commission do
|
|
|
5
5
|
it "#load" do
|
|
6
6
|
session = Papapi::Session.new(script_url).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
7
7
|
affiliate = Papapi::Affiliate.new(session)
|
|
8
|
-
affiliate.load
|
|
8
|
+
affiliate.load
|
|
9
9
|
expect(affiliate.id).to eq('11111111')
|
|
10
10
|
expect(affiliate[:username]).to eq('affiliate@example.com')
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
it "#load - by merchant session" do
|
|
14
|
+
session = Papapi::Session.new(script_url).login(merchant_login, merchant_password)
|
|
15
|
+
affiliate = Papapi::Affiliate.new(session)
|
|
16
|
+
affiliate.id = '11111111'
|
|
17
|
+
affiliate.load
|
|
18
|
+
expect(affiliate.id).to eq('11111111')
|
|
19
|
+
expect(affiliate[:username]).to eq('affiliate@example.com')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "#save" do
|
|
23
|
+
session = Papapi::Session.new(script_url).login(affiliate_login, affiliate_password, Papapi::Session::AFFILIATE)
|
|
24
|
+
affiliate = Papapi::Affiliate.new(session)
|
|
25
|
+
affiliate.load
|
|
26
|
+
expect(affiliate.id).to eq('11111111')
|
|
27
|
+
affiliate[:data1] = 'http://google.com'
|
|
28
|
+
affiliate[:data2] = 'Fake inc.'
|
|
29
|
+
affiliate[:data3] = 'str. Fake'
|
|
30
|
+
affiliate[:data4] = 'Fake'
|
|
31
|
+
affiliate[:data5] = 'CA'
|
|
32
|
+
affiliate[:data6] = 'USA'
|
|
33
|
+
affiliate[:firstname] = 'papapi_a_test'
|
|
34
|
+
affiliate.save
|
|
35
|
+
expect(affiliate[:firstname]).to eq('papapi_a_test')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "#save - by merchant session" do
|
|
39
|
+
session = Papapi::Session.new(script_url).login(merchant_login, merchant_password)
|
|
40
|
+
affiliate = Papapi::Affiliate.new(session)
|
|
41
|
+
affiliate.id = '11111111'
|
|
42
|
+
affiliate.load
|
|
43
|
+
expect(affiliate.id).to eq('11111111')
|
|
44
|
+
affiliate[:data1] = 'http://google.com'
|
|
45
|
+
affiliate[:data2] = 'Fake inc.'
|
|
46
|
+
affiliate[:data3] = 'str. Fake'
|
|
47
|
+
affiliate[:data4] = 'Fake'
|
|
48
|
+
affiliate[:data5] = 'CA'
|
|
49
|
+
affiliate[:data6] = 'USA'
|
|
50
|
+
affiliate[:firstname] = 'papapi_m_test'
|
|
51
|
+
affiliate.save
|
|
52
|
+
expect(affiliate[:firstname]).to eq('papapi_m_test')
|
|
53
|
+
end
|
|
54
|
+
|
|
12
55
|
end
|
data/spec/merchant_spec.rb
CHANGED
|
@@ -27,13 +27,13 @@ RSpec.describe Papapi::Affiliate::Commission do
|
|
|
27
27
|
:country => 'US',
|
|
28
28
|
:zip => '90210',
|
|
29
29
|
:phone => '3234789181',
|
|
30
|
-
:refid => '
|
|
30
|
+
:refid => 'tomfoolery',
|
|
31
31
|
:rstatus => 'A'
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
expect(affiliate[:username]).to eq('user@example.com')
|
|
36
|
-
expect(affiliate[:refid]).to eq('
|
|
36
|
+
#expect(affiliate[:refid]).to eq('tomfoolery')
|
|
37
37
|
|
|
38
38
|
merchant.remove_affiliate(affiliate[:Id])
|
|
39
39
|
|
|
@@ -57,4 +57,15 @@ RSpec.describe Papapi::Affiliate::Commission do
|
|
|
57
57
|
expect(affiliates[0]['username']).to eq('affiliate@example.com')
|
|
58
58
|
|
|
59
59
|
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
it "#affiliate_by_username" do
|
|
63
|
+
session = Papapi::Session.new(script_url).login(merchant_login, merchant_password)
|
|
64
|
+
merchant = Papapi::Merchant.new(session)
|
|
65
|
+
|
|
66
|
+
affiliate = merchant.affiliate_by_username('affiliate@example.com')
|
|
67
|
+
|
|
68
|
+
expect(affiliate[:username]).to eq('affiliate@example.com')
|
|
69
|
+
expect(affiliate.id).to eq('11111111')
|
|
70
|
+
end
|
|
60
71
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: papapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Nizovtsev
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -94,7 +94,7 @@ homepage: https://github.com/JSBizon/papapi
|
|
|
94
94
|
licenses:
|
|
95
95
|
- MIT
|
|
96
96
|
metadata: {}
|
|
97
|
-
post_install_message:
|
|
97
|
+
post_install_message:
|
|
98
98
|
rdoc_options: []
|
|
99
99
|
require_paths:
|
|
100
100
|
- lib
|
|
@@ -109,9 +109,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '0'
|
|
111
111
|
requirements: []
|
|
112
|
-
rubyforge_project:
|
|
113
|
-
rubygems_version: 2.
|
|
114
|
-
signing_key:
|
|
112
|
+
rubyforge_project:
|
|
113
|
+
rubygems_version: 2.7.11
|
|
114
|
+
signing_key:
|
|
115
115
|
specification_version: 4
|
|
116
116
|
summary: A client for the Post Affiliate Pro API
|
|
117
117
|
test_files:
|