Sha256: b6f786d62f6034bc3baf0f09d489d0fc3656609960147e8dfbbf7f0c87dc6bef

Contents?: true

Size: 801 Bytes

Versions: 12

Compression:

Stored size: 801 Bytes

Contents

require "myfinance/request"
require "myfinance/response"

module Myfinance
  class Http
    attr_reader :token, :account_id

    def initialize(token, account_id = nil)
      @token = token
      @account_id = account_id
    end

    %w[get post delete put].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: "#{Myfinance.configuration.url}#{path}",
        user_agent: Myfinance.configuration.user_agent,
        account_id: account_id
      }))

      response = Response.new(request.run)

      response.resolve!(&block)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
myfinance-1.2.1 lib/myfinance/http.rb
myfinance-1.2.0 lib/myfinance/http.rb
myfinance-1.1.0 lib/myfinance/http.rb
myfinance-1.0.0 lib/myfinance/http.rb
myfinance-0.7.0 lib/myfinance/http.rb
myfinance-0.6.0 lib/myfinance/http.rb
myfinance-0.5.0 lib/myfinance/http.rb
myfinance-0.4.0 lib/myfinance/http.rb
myfinance-0.3.3 lib/myfinance/http.rb
myfinance-0.3.2 lib/myfinance/http.rb
myfinance-0.3.1 lib/myfinance/http.rb
myfinance-0.3.0 lib/myfinance/http.rb