Class: Centaman::Service

Inherits:
Wrapper show all
Defined in:
lib/centaman/service.rb

Overview

:nodoc:

Defined Under Namespace

Classes: AddOn, AuthenticateMember, BookingTime, BookingType, Capacity, CostRate, CouponCheck, CreateCustomer, CreateMember, CreatePrimaryMember, CreateRetailCustomer, CreateSecondaryMembers, CreateUdf, Extra, GeneralAdmissionTicket, GiftTicket, HoldTicket, Member, MembershipType, PurchaseMembership, PurchaseTicket, TicketType, UpdateMember

Constant Summary

Constants inherited from Wrapper

Wrapper::DEFAULT_TIMEOUT_TIME

Instance Attribute Summary

Attributes inherited from Wrapper

#api_password, #api_token, #api_url, #api_username, #proxie_host, #proxie_password, #proxie_port, #proxie_user

Instance Method Summary collapse

Methods inherited from Wrapper

#generate_token, #headers, #initialize, #options, #options_hash, #payload, #payload_key, #proxy_hash, #wrap_request_in_case_of_timeout

Constructor Details

This class inherits a constructor from Centaman::Wrapper

Instance Method Details

#after_init(args) ⇒ Object



4
5
6
# File 'lib/centaman/service.rb', line 4

def after_init(args)
  # overwritten by subclasses
end

#after_post(response) ⇒ Object



41
42
43
# File 'lib/centaman/service.rb', line 41

def after_post(response)
  build_object(response)
end

#fetch_allObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/centaman/service.rb', line 8

def fetch_all
  @get_request ||= begin
    req = Proc.new do
      self.class.get("#{api_url}#{endpoint}", payload(:get))
    end
    resp = wrap_request_in_case_of_timeout(req, timeout_time: 20)

    raise resp['Message'] if resp && resp.is_a?(Hash)
    # raise Exceptions::CentamanError.new(resp) unless resp && resp.success?
    resp
  end
end

#postObject



21
22
23
24
25
26
27
28
29
# File 'lib/centaman/service.rb', line 21

def post
  @post_request ||= begin
    req = Proc.new do
      self.class.post("#{api_url}#{endpoint}", payload(:post))
    end
    resp = wrap_request_in_case_of_timeout(req)
    self.respond_to?(:build_object) ? after_post(resp) : resp
  end
end

#putObject



31
32
33
34
35
36
37
38
39
# File 'lib/centaman/service.rb', line 31

def put
  @put_request ||= begin
    req = Proc.new do
      self.class.put("#{api_url}#{endpoint}", payload(:put))
    end
    resp = wrap_request_in_case_of_timeout(req)
    self.respond_to?(:build_object) ? after_post(resp) : resp
  end
end