Class: Giftrocket::Gift

Inherits:
Object
  • Object
show all
Defined in:
lib/giftrocket/gift.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Gift

Returns a new instance of Gift.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/giftrocket/gift.rb', line 6

def initialize(attributes)
  attributes = attributes.with_indifferent_access
  self.raw = attributes
  self.id = attributes[:id]
  self.order_id = attributes[:order_id]
  self.amount = attributes[:amount]
  self.message = attributes[:message]
  self.style_id = attributes[:style_id]
  self.status = attributes[:status]
  self.sender = attributes[:sender]
  self.recipient = Giftrocket::User.new(attributes[:recipient])
  self.events = attributes[:events]
  self.catalog = attributes[:catalog]
  self.redemption_methods = attributes[:redemption_methods]
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def amount
  @amount
end

#catalogObject

Returns the value of attribute catalog.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def catalog
  @catalog
end

#eventsObject

Returns the value of attribute events.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def events
  @events
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def id
  @id
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def message
  @message
end

#order_idObject

Returns the value of attribute order_id.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def order_id
  @order_id
end

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def raw
  @raw
end

#recipientObject

Returns the value of attribute recipient.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def recipient
  @recipient
end

#redemption_methodsObject

Returns the value of attribute redemption_methods.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def redemption_methods
  @redemption_methods
end

#senderObject

Returns the value of attribute sender.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def sender
  @sender
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def status
  @status
end

#style_idObject

Returns the value of attribute style_id.



4
5
6
# File 'lib/giftrocket/gift.rb', line 4

def style_id
  @style_id
end

Class Method Details

.list(filters = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/giftrocket/gift.rb', line 22

def self.list(filters={})
  response = Giftrocket::Request.get(
    'gifts',
    query: filters.merge(Giftrocket.default_options),
    format: 'json'
  )[:gifts].map do |gift_attributes|
    Giftrocket::Gift.new(gift_attributes)
  end
end

.retrieve(id) ⇒ Object



32
33
34
35
36
37
# File 'lib/giftrocket/gift.rb', line 32

def self.retrieve(id)
  response = Giftrocket::Request.get "gifts/#{id}",
                                     query: Giftrocket.default_options,
                                     format: 'json'
  Giftrocket::Gift.new(response[:gift])
end