Class: Raas::RewardModel

Inherits:
BaseModel show all
Defined in:
lib/raas/models/reward_model.rb

Overview

Represents a Reward

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(credentials = nil, credential_list = nil, redemption_instructions = nil) ⇒ RewardModel

Returns a new instance of RewardModel.



28
29
30
31
32
33
34
# File 'lib/raas/models/reward_model.rb', line 28

def initialize(credentials = nil,
               credential_list = nil,
               redemption_instructions = nil)
  @credentials = credentials
  @credential_list = credential_list
  @redemption_instructions = redemption_instructions
end

Instance Attribute Details

#credential_listList of RewardCredentialModel

An array of reward credentials

Returns:



13
14
15
# File 'lib/raas/models/reward_model.rb', line 13

def credential_list
  @credential_list
end

#credentialsArray<String, String>

A map of reward credentials

Returns:



9
10
11
# File 'lib/raas/models/reward_model.rb', line 9

def credentials
  @credentials
end

#redemption_instructionsString

Reward redemption instructions

Returns:



17
18
19
# File 'lib/raas/models/reward_model.rb', line 17

def redemption_instructions
  @redemption_instructions
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/raas/models/reward_model.rb', line 37

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  credentials = hash['credentials']
  # Parameter is an array, so we need to iterate through it
  credential_list = nil
  unless hash['credentialList'].nil?
    credential_list = []
    hash['credentialList'].each do |structure|
      credential_list << (RewardCredentialModel.from_hash(structure) if structure)
    end
  end
  redemption_instructions = hash['redemptionInstructions']

  # Create object from extracted values.
  RewardModel.new(credentials,
                  credential_list,
                  redemption_instructions)
end

.namesObject

A mapping from model property names to API property names.



20
21
22
23
24
25
26
# File 'lib/raas/models/reward_model.rb', line 20

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['credentials'] = 'credentials'
  @_hash['credential_list'] = 'credentialList'
  @_hash['redemption_instructions'] = 'redemptionInstructions'
  @_hash
end