Class: BuckyBox::API
- Inherits:
-
Object
show all
- Defined in:
- lib/buckybox/api.rb
Defined Under Namespace
Classes: CachedResponse, Response
Constant Summary
collapse
- ResponseError =
Class.new(Exception)
- NotFoundError =
Class.new(ResponseError)
- ENDPOINTS =
{
production: "https://api.buckybox.com/v1",
staging: "https://api-staging.buckybox.com/v1",
development: "http://api.buckybox.local:3000/v1",
test: "https://api.buckybox.com/v1",
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
-
#authenticate_customer(params = {}, options = {}) ⇒ Object
-
#box(id, params = { embed: "extras,images,box_items" }, options = {}) ⇒ Object
-
#boxes(params = { embed: "images" }, options = {}) ⇒ Object
-
#create_or_update_customer(json_customer) ⇒ Object
-
#create_order(json_order) ⇒ Object
-
#customer(id, params = {}, options = {}) ⇒ Object
-
#customers(params = {}, options = {}) ⇒ Object
-
#delivery_service(id, params = {}, options = {}) ⇒ Object
-
#delivery_services(params = {}, options = {}) ⇒ Object
-
#flush_cache! ⇒ Object
-
#initialize(headers) ⇒ API
constructor
-
#webstore ⇒ Object
Constructor Details
#initialize(headers) ⇒ API
Returns a new instance of API.
51
52
53
54
|
# File 'lib/buckybox/api.rb', line 51
def initialize()
@headers = .freeze
@endpoint = ENDPOINTS.fetch(ENV.fetch("RAILS_ENV", :production).to_sym)
end
|
Class Method Details
.fixtures_path ⇒ Object
47
48
49
|
# File 'lib/buckybox/api.rb', line 47
def self.fixtures_path
File.expand_path("../../../fixtures", __FILE__)
end
|
Instance Method Details
#authenticate_customer(params = {}, options = {}) ⇒ Object
84
85
86
|
# File 'lib/buckybox/api.rb', line 84
def authenticate_customer(params = {}, options = {})
query :post, "/customers/sign_in", params, options
end
|
#box(id, params = { embed: "extras,images,box_items" }, options = {}) ⇒ Object
60
61
62
|
# File 'lib/buckybox/api.rb', line 60
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
56
57
58
|
# File 'lib/buckybox/api.rb', line 56
def boxes(params = { embed: "images" }, options = {})
query :get, "/boxes", params, options, price: CrazyMoney
end
|
#create_or_update_customer(json_customer) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/buckybox/api.rb', line 88
def create_or_update_customer(json_customer)
customer = Oj.load(json_customer)
if customer["id"]
query :put, "/customers/#{customer['id']}", json_customer else
query :post, "/customers", json_customer
end
end
|
#create_order(json_order) ⇒ Object
98
99
100
|
# File 'lib/buckybox/api.rb', line 98
def create_order(json_order)
query :post, "/orders", json_order
end
|
#customer(id, params = {}, options = {}) ⇒ Object
80
81
82
|
# File 'lib/buckybox/api.rb', line 80
def customer(id, params = {}, options = {})
query :get, "/customers/#{id}", params, options, account_balance: CrazyMoney
end
|
#customers(params = {}, options = {}) ⇒ Object
76
77
78
|
# File 'lib/buckybox/api.rb', line 76
def customers(params = {}, options = {})
query :get, "/customers", params, options, account_balance: CrazyMoney
end
|
#delivery_service(id, params = {}, options = {}) ⇒ Object
68
69
70
|
# File 'lib/buckybox/api.rb', line 68
def delivery_service(id, params = {}, options = {})
query :get, "/delivery_services/#{id}", params, options, fee: CrazyMoney
end
|
#delivery_services(params = {}, options = {}) ⇒ Object
64
65
66
|
# File 'lib/buckybox/api.rb', line 64
def delivery_services(params = {}, options = {})
query :get, "/delivery_services", params, options, fee: CrazyMoney
end
|
#flush_cache! ⇒ Object
102
103
104
|
# File 'lib/buckybox/api.rb', line 102
def flush_cache!
@cache = nil
end
|
#webstore ⇒ Object
72
73
74
|
# File 'lib/buckybox/api.rb', line 72
def webstore
query :get, "/webstore"
end
|