Class: BuckyBox::API

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

Defined Under Namespace

Classes: CachedResponse

Constant Summary collapse

ResponseError =

generic error

Class.new(Exception)
NotFoundError =
Class.new(Exception)

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ API

Returns a new instance of API.



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

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

Instance Method Details

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



63
64
65
# File 'lib/buckybox/api.rb', line 63

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

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



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

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

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



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

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

#create_or_update_customer(json_customer) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/buckybox/api.rb', line 67

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



77
78
79
# File 'lib/buckybox/api.rb', line 77

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

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



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

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

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



55
56
57
# File 'lib/buckybox/api.rb', line 55

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

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



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

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

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



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

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

#flush_cache!Object



81
82
83
# File 'lib/buckybox/api.rb', line 81

def flush_cache!
  @cache = nil
end

#webstoreObject



51
52
53
# File 'lib/buckybox/api.rb', line 51

def webstore
  query :get, "/webstore"
end