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-0.10.0 lib/cobrato/http.rb
cobrato-client-0.9.1 lib/cobrato/http.rb
cobrato-client-0.9.0 lib/cobrato/http.rb
cobrato-client-0.8.0 lib/cobrato/http.rb
cobrato-client-0.7.0 lib/cobrato/http.rb
cobrato-client-0.6.0 lib/cobrato/http.rb
cobrato-client-0.5.0 lib/cobrato/http.rb
cobrato-client-0.4.2 lib/cobrato/http.rb
cobrato-client-0.4.1 lib/cobrato/http.rb
cobrato-client-0.4.0 lib/cobrato/http.rb
cobrato-client-0.4.0.rc1 lib/cobrato/http.rb
cobrato-client-0.3.0 lib/cobrato/http.rb
cobrato-client-0.3.0.rc1 lib/cobrato/http.rb
cobrato-client-0.2.11 lib/cobrato/http.rb
cobrato-client-0.2.10 lib/cobrato/http.rb
cobrato-client-0.2.9 lib/cobrato/http.rb
cobrato-client-0.2.8 lib/cobrato/http.rb
cobrato-client-0.2.7 lib/cobrato/http.rb
cobrato-client-0.2.6 lib/cobrato/http.rb
cobrato-client-0.2.5 lib/cobrato/http.rb