Class: Raas::ItemModel

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

Overview

Represents an item

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(utid = nil, reward_name = nil, currency_code = nil, status = nil, value_type = nil, reward_type = nil, created_date = nil, last_update_date = nil, countries = nil, min_value = nil, max_value = nil, face_value = nil) ⇒ ItemModel

Returns a new instance of ItemModel.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/raas/models/item_model.rb', line 74

def initialize(utid = nil,
               reward_name = nil,
               currency_code = nil,
               status = nil,
               value_type = nil,
               reward_type = nil,
               created_date = nil,
               last_update_date = nil,
               countries = nil,
               min_value = nil,
               max_value = nil,
               face_value = nil)
  @utid = utid
  @reward_name = reward_name
  @currency_code = currency_code
  @status = status
  @value_type = value_type
  @reward_type = reward_type
  @created_date = created_date
  @last_update_date = last_update_date
  @countries = countries
  @min_value = min_value
  @max_value = max_value
  @face_value = face_value
end

Instance Attribute Details

#countriesList of String

The countries this item is valid in

Returns:



42
43
44
# File 'lib/raas/models/item_model.rb', line 42

def countries
  @countries
end

#created_dateDateTime

The date the item was created

Returns:

  • (DateTime)


34
35
36
# File 'lib/raas/models/item_model.rb', line 34

def created_date
  @created_date
end

#currency_codeString

The currency code

Returns:



18
19
20
# File 'lib/raas/models/item_model.rb', line 18

def currency_code
  @currency_code
end

#face_valueFloat

The face value of the gift card

Returns:

  • (Float)


54
55
56
# File 'lib/raas/models/item_model.rb', line 54

def face_value
  @face_value
end

#last_update_dateDateTime

The date the item was last updated

Returns:

  • (DateTime)


38
39
40
# File 'lib/raas/models/item_model.rb', line 38

def last_update_date
  @last_update_date
end

#max_valueFloat

The maximum orderable value (for variable value items)

Returns:

  • (Float)


50
51
52
# File 'lib/raas/models/item_model.rb', line 50

def max_value
  @max_value
end

#min_valueFloat

The minimum orderable value (for variable value items)

Returns:

  • (Float)


46
47
48
# File 'lib/raas/models/item_model.rb', line 46

def min_value
  @min_value
end

#reward_nameString

The reward name

Returns:



14
15
16
# File 'lib/raas/models/item_model.rb', line 14

def reward_name
  @reward_name
end

#reward_typeString

The reward type

Returns:



30
31
32
# File 'lib/raas/models/item_model.rb', line 30

def reward_type
  @reward_type
end

#statusString

The item’s status

Returns:



22
23
24
# File 'lib/raas/models/item_model.rb', line 22

def status
  @status
end

#utidString

The UTID

Returns:



10
11
12
# File 'lib/raas/models/item_model.rb', line 10

def utid
  @utid
end

#value_typeString

The item’s value type (VARIABLE_VALUE or FIXED_VALUE)

Returns:



26
27
28
# File 'lib/raas/models/item_model.rb', line 26

def value_type
  @value_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/raas/models/item_model.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  utid = hash['utid']
  reward_name = hash['rewardName']
  currency_code = hash['currencyCode']
  status = hash['status']
  value_type = hash['valueType']
  reward_type = hash['rewardType']
  created_date = APIHelper.rfc3339(hash['createdDate']) if
    hash['createdDate']
  last_update_date = APIHelper.rfc3339(hash['lastUpdateDate']) if
    hash['lastUpdateDate']
  countries = hash['countries']
  min_value = hash['minValue']
  max_value = hash['maxValue']
  face_value = hash['faceValue']

  # Create object from extracted values.

  ItemModel.new(utid,
                reward_name,
                currency_code,
                status,
                value_type,
                reward_type,
                created_date,
                last_update_date,
                countries,
                min_value,
                max_value,
                face_value)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/raas/models/item_model.rb', line 57

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['utid'] = 'utid'
  @_hash['reward_name'] = 'rewardName'
  @_hash['currency_code'] = 'currencyCode'
  @_hash['status'] = 'status'
  @_hash['value_type'] = 'valueType'
  @_hash['reward_type'] = 'rewardType'
  @_hash['created_date'] = 'createdDate'
  @_hash['last_update_date'] = 'lastUpdateDate'
  @_hash['countries'] = 'countries'
  @_hash['min_value'] = 'minValue'
  @_hash['max_value'] = 'maxValue'
  @_hash['face_value'] = 'faceValue'
  @_hash
end