Class: BlingApi::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/bling_api/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, nome:, sku:) ⇒ Product

Returns a new instance of Product.



12
13
14
15
16
# File 'lib/bling_api/product.rb', line 12

def initialize(id:, nome:, sku:)
  @id = id
  @nome = nome
  @sku = sku
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/bling_api/product.rb', line 11

def id
  @id
end

#nomeObject (readonly)

Returns the value of attribute nome.



11
12
13
# File 'lib/bling_api/product.rb', line 11

def nome
  @nome
end

#skuObject (readonly)

Returns the value of attribute sku.



11
12
13
# File 'lib/bling_api/product.rb', line 11

def sku
  @sku
end

Class Method Details

.build_hash(json_response) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/bling_api/product.rb', line 18

def self.build_hash json_response
  {
    id: json_response["id"],
    nome: json_response["nome"],
    sku: json_response["codigo"]
  }
end

.find_by_sku(sku) ⇒ Object



4
5
6
7
8
9
# File 'lib/bling_api/product.rb', line 4

def self.find_by_sku sku
  response_json = Client.new(BlingApi.configuration.access_token).find_product_by_sku(sku)
  if response_json
    new(**build_hash(response_json))
  end
end