Class: Raas::RewardModel

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

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:



11
12
13
# File 'lib/raas/models/reward_model.rb', line 11

def credential_list
  @credential_list
end

#credentialsArray<String, String>

A map of reward credentials

Returns:



7
8
9
# File 'lib/raas/models/reward_model.rb', line 7

def credentials
  @credentials
end

#redemption_instructionsString

Reward redemption instructions

Returns:



15
16
17
# File 'lib/raas/models/reward_model.rb', line 15

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
# 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
  if hash['credentialList'] != nil
    credential_list = Array.new
    hash['credentialList'].each{|structure| credential_list << (RewardCredentialModel.from_hash(structure) if structure)}
  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



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

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