Sha256: f9c1718b014486e3d045d38fd1c41515021e620b3af230e5b3313c7e2122acb1

Contents?: true

Size: 717 Bytes

Versions: 66

Compression:

Stored size: 717 Bytes

Contents

require "cobrato/request"
require "cobrato/response"

module Cobrato
  class Http
    attr_reader :token

    def initialize(token)
     @token = token
    end

    %w[get post delete put patch].each do |m|
      define_method(m) do |path, options = {}, &block|
        send_request(m.to_sym, path, options, &block)
      end
    end

    private

    def send_request(method, path, options, &block)
      request  = Request.new(options.merge!({
        method:     method,
        token:      token,
        url:        "#{Cobrato.configuration.url}#{path}",
        user_agent: Cobrato.configuration.user_agent
      }))
      response = Response.new(request.run)
      response.resolve!(&block)
    end

  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
cobrato-client-1.1.7 lib/cobrato/http.rb
cobrato-client-1.1.6 lib/cobrato/http.rb
cobrato-client-1.1.5 lib/cobrato/http.rb
cobrato-client-1.1.4 lib/cobrato/http.rb
cobrato-client-1.1.3 lib/cobrato/http.rb
cobrato-client-1.1.2 lib/cobrato/http.rb
cobrato-client-1.1.1 lib/cobrato/http.rb
cobrato-client-1.1.0 lib/cobrato/http.rb
cobrato-client-1.0.1 lib/cobrato/http.rb
cobrato-client-1.0.0 lib/cobrato/http.rb
cobrato-client-0.27.0 lib/cobrato/http.rb
cobrato-client-0.26.0 lib/cobrato/http.rb
cobrato-client-0.25.0 lib/cobrato/http.rb
cobrato-client-0.24.1 lib/cobrato/http.rb
cobrato-client-0.24.0 lib/cobrato/http.rb
cobrato-client-0.23.0 lib/cobrato/http.rb
cobrato-client-0.23.0.beta12 lib/cobrato/http.rb
cobrato-client-0.23.0.beta11 lib/cobrato/http.rb
cobrato-client-0.23.0.beta10 lib/cobrato/http.rb
cobrato-client-0.23.0.beta9 lib/cobrato/http.rb