Class: BuckyBox::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/buckybox/api.rb

Constant Summary collapse

ResponseError =
Class.new(Exception)

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ API

Returns a new instance of API.



14
15
16
# File 'lib/buckybox/api.rb', line 14

def initialize(headers)
  self.class.headers(headers)
end

Instance Method Details

#authenticate_customer(params = {}, options = {}) ⇒ Object



46
47
48
# File 'lib/buckybox/api.rb', line 46

def authenticate_customer(params = {}, options = {})
  query :post, "/customers/sign_in", params, options
end

#box(id, params = {embed: "extras,images,box_items"}, options = {}) ⇒ Object



22
23
24
# File 'lib/buckybox/api.rb', line 22

def box(id, params = {embed: "extras,images,box_items"}, options = {})
  query :get, "/boxes/#{id}", params, options, price: CrazyMoney
end

#boxes(params = {embed: "extras,images,box_items"}, options = {}) ⇒ Object



18
19
20
# File 'lib/buckybox/api.rb', line 18

def boxes(params = {embed: "extras,images,box_items"}, options = {})
  query :get, "/boxes", params, options, price: CrazyMoney
end

#create_or_update_customer(json_customer) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/buckybox/api.rb', line 50

def create_or_update_customer(json_customer)
  customer = JSON.parse(json_customer)

  if customer['id']
    query :put, "/customers/#{customer['id']}", json_customer # TODO: replace by :patch
  else
    query :post, "/customers", json_customer
  end
end

#create_order(json_order) ⇒ Object



60
61
62
# File 'lib/buckybox/api.rb', line 60

def create_order(json_order)
  query :post, "/orders", json_order
end

#customer(id, params = {}, options = {}) ⇒ Object



42
43
44
# File 'lib/buckybox/api.rb', line 42

def customer(id, params = {}, options = {})
  query :get, "/customers/#{id}", params, options, account_balance: CrazyMoney
end

#customers(params = {}, options = {}) ⇒ Object



38
39
40
# File 'lib/buckybox/api.rb', line 38

def customers(params = {}, options = {})
  query :get, "/customers", params, options, account_balance: CrazyMoney
end

#delivery_service(id, params = {}, options = {}) ⇒ Object



30
31
32
# File 'lib/buckybox/api.rb', line 30

def delivery_service(id, params = {}, options = {})
  query :get, "/delivery_services/#{id}", params, options, fee: CrazyMoney
end

#delivery_services(params = {}, options = {}) ⇒ Object



26
27
28
# File 'lib/buckybox/api.rb', line 26

def delivery_services(params = {}, options = {})
  query :get, "/delivery_services", params, options, fee: CrazyMoney
end

#webstoreObject



34
35
36
# File 'lib/buckybox/api.rb', line 34

def webstore
  query :get, "/webstore"
end