papapi 0.1.6 → 0.1.7

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: bc85d50e2012ff738a2165d92fb3e2c7ae232544
4
- data.tar.gz: 2103a176b9c2a7c31e48220e3772f8421e88180d
3
+ metadata.gz: ba0680e86df3b482fad2cc37335b613a5ab72654
4
+ data.tar.gz: 0528020605432d2f6646b0a0a816a7aac9fc5507
5
5
  SHA512:
6
- metadata.gz: 638975743a0870dbf58f79e13d75998f2bf883af840783648815ede897e378650901511b0ff4473696e6818f7d3773a8ae5c3e1471f5f958ee32ddae3ab6dd9d
7
- data.tar.gz: c639a66f4fb61ddd496409ba1a523b84098720c8778ea10ae35540ca321a9a044fb5386480b9914fc9961738b32a72dcd9667eafe2a32eb98caeecb2896c4922
6
+ metadata.gz: 91d7f5553d326427ba370c1488944ee23a2510f942286a5150cc3303cc3ecffbb91cac03c0aa086da1b252ea7cc23439b737792ffa85474f2f93889357475f97
7
+ data.tar.gz: c887130ee1303121b9380760f9f358a5b7b3be856dfcaa0173ff6ce0c1d02c8ce7c26d7ee4810d143a551c692e3e4a77e1086957d0ca50dbaefc8e00473cd9e5
@@ -5,18 +5,33 @@ module Papapi
5
5
 
6
6
  def initialize(session, response = nil)
7
7
  @session = session
8
- raise "Affiliate session is required" if !@session.is_affiliate?
8
+ if @session.is_affiliate?
9
+ @class = 'Pap_Affiliates_Profile_PersonalDetailsForm'
10
+ else
11
+ @class = 'Pap_Signup_AffiliateForm'
12
+ end
9
13
  @response = response
14
+ @user_id = nil
10
15
  end
11
16
 
12
17
  def load
13
- request = Papapi::FormRequest.new('Pap_Affiliates_Profile_PersonalDetailsForm', 'load', @session)
18
+ request = Papapi::FormRequest.new(@class, 'load', @session)
19
+
20
+ unless @user_id.nil?
21
+ request.set_field("Id", @user_id)
22
+ request.set_field("userid", @user_id)
23
+ end
24
+
14
25
  @response = request.send
15
26
  self
16
27
  end
17
28
 
18
29
  def id
19
- @response ? @response[:userid] : nil
30
+ @response ? @response[:userid] : @user_id
31
+ end
32
+
33
+ def id=(user_id)
34
+ @user_id = user_id
20
35
  end
21
36
 
22
37
  def [] (key)
@@ -15,6 +15,12 @@ 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]
@@ -32,10 +32,6 @@ module Papapi
32
32
  request.set_fields(request_fields)
33
33
  response = request.send
34
34
  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
35
  end
40
36
 
41
37
  def remove_affiliate(affiliate_id)
@@ -103,6 +99,21 @@ module Papapi
103
99
  affiliates
104
100
  end
105
101
 
102
+ def affiliate_by_username(username)
103
+ request = Papapi::GridRequest.new("Pap_Merchants_User_AffiliatesGridSimple", "getRows", @session)
104
+ request.add_filter('username', Papapi::Filter::EQUALS, username)
105
+
106
+ response = request.send
107
+ if response.count > 0
108
+ user = response[0]
109
+ affiliate = Papapi::Affiliate.new(@session)
110
+ affiliate.id = user['userid']
111
+ affiliate.load
112
+ return affiliate
113
+ end
114
+
115
+ end
116
+
106
117
  def id
107
118
  @response ? @response[:authid] : nil
108
119
  end
@@ -1,3 +1,3 @@
1
1
  module Papapi
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -9,4 +9,14 @@ RSpec.describe Papapi::Affiliate::Commission do
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
+
12
22
  end
@@ -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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Nizovtsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler