Class: Papapi::Affiliate
- Inherits:
-
Object
- Object
- Papapi::Affiliate
- Defined in:
- lib/papapi/affiliate.rb
Defined Under Namespace
Classes: Commission
Constant Summary collapse
- A_ALLOWED_FIELDS =
[:username, :rpassword, :firstname, :lastname, :photo, :refid, :data1, :data2, :data3, :data4, :data5, :data6, :data7, :data8, :data9, :data10, :data11, :data12, :data13, :data14, :data15, :data16, :data17, :data18, :data19, :data20, :data21, :data22, :data23, :data24, :data25 ]
- M_ALLOWED_FIELDS =
[:parentuserid, :rstatus, :agreeWithTerms] | A_ALLOWED_FIELDS
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #getLoginKey ⇒ Object
- #id ⇒ Object
- #id=(user_id) ⇒ Object
-
#initialize(session, response = nil) ⇒ Affiliate
constructor
A new instance of Affiliate.
- #load ⇒ Object
- #save ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(session, response = nil) ⇒ Affiliate
Returns a new instance of Affiliate.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/papapi/affiliate.rb', line 16 def initialize(session, response = nil) @session = session if @session.is_affiliate? @load_class = 'Pap_Affiliates_Profile_PersonalDetailsForm' @save_class = 'Pap_Affiliates_Profile_PersonalDetailsForm' else @load_class = 'Pap_Signup_AffiliateForm' @save_class = 'Pap_Merchants_User_AffiliateForm' end @response = response @user_id = nil @update_fields = {} end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
14 15 16 |
# File 'lib/papapi/affiliate.rb', line 14 def response @response end |
Instance Method Details
#[](key) ⇒ Object
93 94 95 |
# File 'lib/papapi/affiliate.rb', line 93 def [] (key) @response ? @response[key.to_sym] : nil end |
#[]=(key, value) ⇒ Object
98 99 100 101 102 |
# File 'lib/papapi/affiliate.rb', line 98 def []= (key, value) raise "Field #{key} can not be modified" if (@session.is_affiliate? && ! A_ALLOWED_FIELDS.include?(key.to_sym)) || (@session.is_merchant? && ! M_ALLOWED_FIELDS.include?(key.to_sym)) @update_fields[key.to_sym] = value end |
#getLoginKey ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/papapi/affiliate.rb', line 77 def getLoginKey raise "Merchant session is required" if @session.is_affiliate? request = Papapi::FormRequest.new('Pap_Auth_LoginKeyService', 'getLoginKey', @session) request.set_param("userId", self.id) response = request.send return response[:LoginKey] end |
#id ⇒ Object
73 74 75 |
# File 'lib/papapi/affiliate.rb', line 73 def id @response ? @response[:userid] : @user_id end |
#id=(user_id) ⇒ Object
88 89 90 |
# File 'lib/papapi/affiliate.rb', line 88 def id=(user_id) @user_id = user_id end |
#load ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/papapi/affiliate.rb', line 31 def load request = Papapi::FormRequest.new(@load_class, 'load', @session) unless @user_id.nil? request.set_field("Id", @user_id) request.set_field("userid", @user_id) end @response = request.send self end |
#save ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/papapi/affiliate.rb', line 44 def save raise "Affiliate id is required" if @session.is_merchant? && ! self.id request = Papapi::FormRequest.new(@save_class, 'save', @session) if @response @response.fields.each do |key, value| request.set_field(key, value) if (@session.is_affiliate? && A_ALLOWED_FIELDS.include?(key.to_sym)) || (@session.is_merchant? && M_ALLOWED_FIELDS.include?(key.to_sym)) end end @update_fields.each do |key, value| request.set_field(key, value) if (@session.is_affiliate? && A_ALLOWED_FIELDS.include?(key.to_sym)) || (@session.is_merchant? && M_ALLOWED_FIELDS.include?(key.to_sym)) end if @session.is_affiliate? request.set_field("Id", "") else request.set_field("Id", self.id) end @response = request.send @update_fields = {} self end |
#to_h ⇒ Object
104 105 106 |
# File 'lib/papapi/affiliate.rb', line 104 def to_h response ? response.to_h : {} end |