Sha256: 47a57f0a7d7e12658171ba914929a9554241d371da04c5039d5d69d968c60be3

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module Centaman
  #:nodoc:
  class Service < Wrapper
    def after_init(args)
      # overwritten by subclasses
    end

    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

    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

    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

    def after_post(response)
      build_object(response)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
centaman-8.0.0 lib/centaman/service.rb
centaman-7.0.5 lib/centaman/service.rb
centaman-7.0.4 lib/centaman/service.rb
centaman-7.0.3 lib/centaman/service.rb