Class: Unit::Reward::CreateRewardRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/models/reward/create_reward_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiving_account_id, amount, description, tags = nil, idempotency_key = nil, funding_account_id = nil, rewarded_transaction_id = nil) ⇒ CreateRewardRequest

Returns a new instance of CreateRewardRequest.

Parameters:

  • receiving_account_id (String)
  • amount (Integer)
  • description (String)
  • tags (Hash) (defaults to: nil)
  • idempotency_key (String) (defaults to: nil)
  • funding_account_id (String) (defaults to: nil)
    • optional

  • rewarded_transaction_id (String) (defaults to: nil)
    • optional



17
18
19
20
21
22
23
24
25
# File 'lib/unit/models/reward/create_reward_request.rb', line 17

def initialize(, amount, description, tags = nil, idempotency_key = nil,  = nil, rewarded_transaction_id = nil)
  @receiving_account_id = 
  @amount = amount
  @description = description
  @tags = tags
  @idempotency_key = idempotency_key
  @funding_account_id = 
  @rewarded_transaction = rewarded_transaction_id
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def amount
  @amount
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def description
  @description
end

#funding_account_idObject (readonly)

Returns the value of attribute funding_account_id.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def 
  @funding_account_id
end

#idempotency_keyObject (readonly)

Returns the value of attribute idempotency_key.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def idempotency_key
  @idempotency_key
end

#receiving_account_idObject (readonly)

Returns the value of attribute receiving_account_id.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def 
  @receiving_account_id
end

#rewarded_transaction_idObject (readonly)

Returns the value of attribute rewarded_transaction_id.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def rewarded_transaction_id
  @rewarded_transaction_id
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/unit/models/reward/create_reward_request.rb', line 8

def tags
  @tags
end

Instance Method Details

#to_json_apiObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/unit/models/reward/create_reward_request.rb', line 27

def to_json_api
  payload = {
    data: {
      type: "reward",
      attributes: {
        amount: amount,
        description: description,
        tags: tags,
        idempotencyKey: idempotency_key
      },
      relationships: {
        receivingAccount: Unit::Types::Relationship.new("depositAccount", ).to_hash
      }
    }
  }
  payload[:data][:relationships][:funding_account] = Unit::Types::Relationship.new("fundingAccount", ).to_hash if 
  payload[:data][:relationships][:rewardedTransaction] = Unit::Types::Relationship.new("rewardedTransaction", rewarded_transaction).to_hash if rewarded_transaction_id
  payload[:data][:attributes].compact!
  payload.to_json
end