Class: Giftrocket::Gift

Inherits:
Object
  • Object
show all
Includes:
HTTParty
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.



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

def initialize(attributes)
  attributes = attributes.with_indifferent_access
  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.recipient = Giftrocket::User.new(attributes[:recipient])
  self.events = attributes[:events]
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def amount
  @amount
end

#eventsObject

Returns the value of attribute events.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def events
  @events
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def id
  @id
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def message
  @message
end

#order_idObject

Returns the value of attribute order_id.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def order_id
  @order_id
end

#recipientObject

Returns the value of attribute recipient.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def recipient
  @recipient
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def status
  @status
end

#style_idObject

Returns the value of attribute style_id.



7
8
9
# File 'lib/giftrocket/gift.rb', line 7

def style_id
  @style_id
end

Class Method Details

.list(query = {}) ⇒ Object



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

def self.list(query={})
  query = query.merge(Giftrocket.default_options)
  response = get '/', query: query, format: 'json'
  if response.success?
    response_json = JSON.parse(response.body).with_indifferent_access
    response_json[:gifts].map do |gift_attributes|
      Giftrocket::Gift.new(gift_attributes)
    end
  else
    raise Giftrocket::Error.new(response)
  end
end

.retrieve(id) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/giftrocket/gift.rb', line 34

def self.retrieve(id)
  response = get "/#{id}", query: Giftrocket.default_options, format: 'json'
  if response.success?
    response_json = JSON.parse(response.body).with_indifferent_access
    Giftrocket::Gift.new(response_json[:gift])
  else
    raise Giftrocket::Error.new(response)
  end
end