Class: Giftrocket::Style

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/giftrocket/style.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Style



9
10
11
12
13
# File 'lib/giftrocket/style.rb', line 9

def initialize(attributes)
  attributes = attributes.with_indifferent_access
  self.id = attributes[:id]
  self.card = attributes[:card]
end

Instance Attribute Details

#cardObject

Returns the value of attribute card.



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

def card
  @card
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.listObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/giftrocket/style.rb', line 19

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

Instance Method Details

#urlObject



15
16
17
# File 'lib/giftrocket/style.rb', line 15

def url
  card && card[:url]
end