Sha256: 26f24086c229549d974d5353e438212b058fe643e570cb0887d7961f7266286e

Contents?: true

Size: 947 Bytes

Versions: 10

Compression:

Stored size: 947 Bytes

Contents

module EZAPIClient
  class BaseRequest

    include Virtus.model
    attribute :username, String
    attribute :password, String
    attribute :eks_path, String
    attribute :prv_path, String
    attribute :host, String
    attribute :path, String, lazy: true, default: :default_path
    attribute :endpoint, String, lazy: true, default: :default_endpoint
    attribute :logger, Object
    attribute :log, Boolean

    def call
      HTTParty.post(endpoint, {
        headers: { 'Content-Type' => "application/json" },
        body: body.to_json,
      })
    end

    private

    def default_endpoint
      full_path = if path.nil?
                    nil
                  elsif path[0].eql?("/")
                    path
                  else
                    "/#{path}"
                  end

      uri = URI.parse(host)
      uri.path = full_path
      uri.to_s
    end

    def default_path
      fail "Override me"
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ezapi_client-1.2.1 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.1.2 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.1.1 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.1.0 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.0.3 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.0.2 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.0.1 lib/ezapi_client/requests/base_request.rb
ezapi_client-1.0.0 lib/ezapi_client/requests/base_request.rb
ezapi_client-0.5.0 lib/ezapi_client/requests/base_request.rb
ezapi_client-0.4.0 lib/ezapi_client/requests/base_request.rb