Class: ElectricProfile::Reward
- Inherits:
-
Object
- Object
- ElectricProfile::Reward
- Defined in:
- lib/electric_profile_ruby/reward.rb
Constant Summary collapse
- TYPES =
['rewardlink', 'amazon', 'paypal', 'bitcoin', 'habitat']
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#autoClaim ⇒ Object
Returns the value of attribute autoClaim.
-
#autoDeliver ⇒ Object
Returns the value of attribute autoDeliver.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#customerId ⇒ Object
Returns the value of attribute customerId.
-
#delivered ⇒ Object
Returns the value of attribute delivered.
-
#deliveryErrors ⇒ Object
Returns the value of attribute deliveryErrors.
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#recipientEmail ⇒ Object
Returns the value of attribute recipientEmail.
-
#recipientId ⇒ Object
Returns the value of attribute recipientId.
-
#rewardProfileId ⇒ Object
Returns the value of attribute rewardProfileId.
-
#transactionId ⇒ Object
Returns the value of attribute transactionId.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(atts) ⇒ Reward
constructor
A new instance of Reward.
- #initialize_client ⇒ Object
- #queue_delivery ⇒ Object
- #save ⇒ Object
- #save_existing ⇒ Object
- #save_new ⇒ Object
Constructor Details
#initialize(atts) ⇒ Reward
Returns a new instance of Reward.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/electric_profile_ruby/reward.rb', line 7 def initialize(atts) atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo } @id = atts[:id] @customerId = atts[:customerId] @rewardProfileId = atts[:rewardProfileId] @amount = atts[:amount] @currency = atts[:currency] @type = atts[:type] @recipientEmail = atts[:recipientEmail] @recipientId = atts[:recipientId] @autoClaim = atts[:autoClaim] @autoDeliver = atts[:autoDeliver] @delivered = atts[:delivered] @deliveryErrors = atts[:deliveryErrors] @transactionId = atts[:transactionId] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def amount @amount end |
#autoClaim ⇒ Object
Returns the value of attribute autoClaim.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def autoClaim @autoClaim end |
#autoDeliver ⇒ Object
Returns the value of attribute autoDeliver.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def autoDeliver @autoDeliver end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def currency @currency end |
#customerId ⇒ Object
Returns the value of attribute customerId.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def customerId @customerId end |
#delivered ⇒ Object
Returns the value of attribute delivered.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def delivered @delivered end |
#deliveryErrors ⇒ Object
Returns the value of attribute deliveryErrors.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def deliveryErrors @deliveryErrors end |
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def error @error end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def id @id end |
#recipientEmail ⇒ Object
Returns the value of attribute recipientEmail.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def recipientEmail @recipientEmail end |
#recipientId ⇒ Object
Returns the value of attribute recipientId.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def recipientId @recipientId end |
#rewardProfileId ⇒ Object
Returns the value of attribute rewardProfileId.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def rewardProfileId @rewardProfileId end |
#transactionId ⇒ Object
Returns the value of attribute transactionId.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def transactionId @transactionId end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/electric_profile_ruby/reward.rb', line 4 def type @type end |
Class Method Details
Instance Method Details
#initialize_client ⇒ Object
108 109 110 |
# File 'lib/electric_profile_ruby/reward.rb', line 108 def initialize_client @client ||= Client.new end |
#queue_delivery ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/electric_profile_ruby/reward.rb', line 80 def queue_delivery initialize_client if @client.queue_reward_delivery(@id) true else @error = @client.error false end end |
#save ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/electric_profile_ruby/reward.rb', line 24 def save if @id save_existing else save_new end end |
#save_existing ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/electric_profile_ruby/reward.rb', line 55 def save_existing initialize_client attributes = { id: @id, customerId: @customerId, rewardProfileId: @rewardProfileId, amount: @amount, currency: @currency, type: @type, recipientEmail: @recipientEmail, recipientId: @recipientId, autoClaim: @autoClaim, autoDeliver: @autoDeliver, delivered: @delivered, deliveryErrors: @deliveryErrors } attributes[:transactionId] = @transactionId if @transactionId if @client.update_reward(attributes) true else @error = @client.error false end end |
#save_new ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/electric_profile_ruby/reward.rb', line 32 def save_new initialize_client attributes = { rewardProfileId: @rewardProfileId, amount: @amount, currency: @currency, type: @type, recipientEmail: @recipientEmail, recipientId: @recipientId, autoClaim: @autoClaim, autoDeliver: @autoDeliver } attributes = attributes.delete_if { |k, v| v.nil? } if @client.create_reward(attributes) @id = @client.data["data"]["id"] @customerId = @client.data["data"]["customerId"] true else @error = @client.error false end end |