Class: BlingApi::Order

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, numero: nil, id_contato:, items:, parcelas: nil, numero_loja:, data:, total_produtos:, total:, id_loja:, numero_pedido_compra: nil, observacoes:, observacoes_internas:, valor_desconto:, id_categoria:, transporte: nil, id_vendedor:) ⇒ Order

Returns a new instance of Order.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bling_api/order.rb', line 10

def initialize(id:nil, numero:nil, id_contato:, items:, parcelas:nil, numero_loja:, data:, total_produtos:, total:, id_loja:, numero_pedido_compra:nil, observacoes:, observacoes_internas:, valor_desconto:, id_categoria:, transporte:nil, id_vendedor:)
  @id = id
  @numero = numero
  @id_contato = id_contato
  @items = items
  @parcelas = parcelas
  @numero_loja = numero_loja
  @data = data
  @total_produtos = total_produtos
  @total = total
  @id_loja = id_loja
  @numero_pedido_compra = numero_pedido_compra
  @observacoes = observacoes
  @observacoes_internas = observacoes_internas
  @valor_desconto = valor_desconto
  @unidade_desconto = unidade_desconto
  @id_categoria = id_categoria
  @transporte = transporte
  @id_vendedor = id_vendedor
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def id
  @id
end

#id_categoriaObject (readonly)

Returns the value of attribute id_categoria.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def id_categoria
  @id_categoria
end

#id_contatoObject (readonly)

Returns the value of attribute id_contato.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def id_contato
  @id_contato
end

#id_lojaObject (readonly)

Returns the value of attribute id_loja.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def id_loja
  @id_loja
end

#id_vendedorObject (readonly)

Returns the value of attribute id_vendedor.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def id_vendedor
  @id_vendedor
end

#itemsObject (readonly)

Returns the value of attribute items.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def items
  @items
end

#numeroObject (readonly)

Returns the value of attribute numero.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def numero
  @numero
end

#numero_lojaObject (readonly)

Returns the value of attribute numero_loja.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def numero_loja
  @numero_loja
end

#numero_pedido_compraObject (readonly)

Returns the value of attribute numero_pedido_compra.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def numero_pedido_compra
  @numero_pedido_compra
end

#observacoesObject (readonly)

Returns the value of attribute observacoes.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def observacoes
  @observacoes
end

#observacoes_internasObject (readonly)

Returns the value of attribute observacoes_internas.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def observacoes_internas
  @observacoes_internas
end

#parcelasObject (readonly)

Returns the value of attribute parcelas.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def parcelas
  @parcelas
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def total
  @total
end

#total_produtosObject (readonly)

Returns the value of attribute total_produtos.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def total_produtos
  @total_produtos
end

#transporteObject (readonly)

Returns the value of attribute transporte.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def transporte
  @transporte
end

#unidade_descontoObject (readonly)

Returns the value of attribute unidade_desconto.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def unidade_desconto
  @unidade_desconto
end

#valor_descontoObject (readonly)

Returns the value of attribute valor_desconto.



9
10
11
# File 'lib/bling_api/order.rb', line 9

def valor_desconto
  @valor_desconto
end

Class Method Details

.find_by_id(id) ⇒ Object



4
5
6
7
# File 'lib/bling_api/order.rb', line 4

def self.find_by_id id
  response = Client.new(BlingApi.access_token).get_order(id)
  new(**build_hash(response))
end

Instance Method Details

#build_jsonObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bling_api/order.rb', line 31

def build_json
  {
    "numeroLoja": numero_loja,
    "data": data,
    "loja": {
      "id": id_loja
    },
    "contato": {
      "id": id_contato
    },
    "itens": items,
    "vendedor": {
      "id": id_vendedor
    },
    "transporte": transporte,
    "parcelas": parcelas,
    "desconto": {
      "valor": valor_desconto,
      "unidade": "REAL"
    },
    "totalProdutos": total_produtos,
    "total": total,
    "observacoes": observacoes,
    "observacoesInternas": observacoes_internas,
    "categoria": {
      "id": id_categoria
    }
  }
end

#createObject



61
62
63
64
# File 'lib/bling_api/order.rb', line 61

def create
  response = Client.new(BlingApi.access_token).create_order(JSON.dump(build_json))
  self.class.find_by_id(response["id"])
end