Class: Centaman::Service
Overview
Defined Under Namespace
Classes: BookingTime, BookingType, Capacity, CouponCheck, CreateCustomer, Extra, GiftTicket, PurchaseTicket, TicketType
Constant Summary
collapse
- DEFAULT_TIMEOUT_TIME =
15
Constants inherited
from Wrapper
Wrapper::FIXIE
Instance Attribute Summary
Attributes inherited from Wrapper
#api_password, #api_token, #api_username
Instance Method Summary
collapse
Methods inherited from Wrapper
#generate_token, #headers, #initialize, #options, #options_hash
Instance Method Details
#after_init(args) ⇒ Object
8
9
10
|
# File 'lib/centaman/service.rb', line 8
def after_init(args)
end
|
#after_post(response) ⇒ Object
47
48
49
|
# File 'lib/centaman/service.rb', line 47
def after_post(response)
build_object(response)
end
|
#fetch_all ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/centaman/service.rb', line 25
def fetch_all
@get_request ||= begin
req = Proc.new do
self.class.get(endpoint, payload(:get))
end
resp = wrap_request_in_case_of_timeout(req, timeout_time: 20)
raise resp['Message'] if resp.is_a?(Hash)
resp
end
end
|
#payload(request_type = :get) ⇒ Object
51
52
53
54
|
# File 'lib/centaman/service.rb', line 51
def payload(request_type = :get)
hash = { payload_key(request_type) => options_hash }
hash.merge(headers: )
end
|
#payload_key(request_type) ⇒ Object
56
57
58
|
# File 'lib/centaman/service.rb', line 56
def payload_key(request_type)
request_type == :get ? :query : :body
end
|
37
38
39
40
41
42
43
44
45
|
# File 'lib/centaman/service.rb', line 37
def post
@post_request ||= begin
req = Proc.new do
self.class.post(endpoint, payload(:post))
end
resp = wrap_request_in_case_of_timeout(req)
self.respond_to?(:build_object) ? after_post(resp) : resp
end
end
|
#wrap_request_in_case_of_timeout(proc, options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/centaman/service.rb', line 12
def wrap_request_in_case_of_timeout(proc, options = {})
time = options.fetch(:timeout_time, DEFAULT_TIMEOUT_TIME)
resp = nil
begin
resp = Timeout.timeout(time) do
proc.call
end
rescue Timeout::Error
raise Exceptions::CentamanTimeout
end
resp
end
|