Sha256: 43cfb99d40286c97d972be630f247f974cae86cc6e1c8cea9201167d5ebaa3d8

Contents?: true

Size: 798 Bytes

Versions: 15

Compression:

Stored size: 798 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.new(request.run).resolve!(&block)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
myfinance-1.8.2 lib/myfinance/http.rb
myfinance-1.8.1 lib/myfinance/http.rb
myfinance-1.8.0 lib/myfinance/http.rb
myfinance-1.7.0 lib/myfinance/http.rb
myfinance-1.6.6 lib/myfinance/http.rb
myfinance-1.6.5 lib/myfinance/http.rb
myfinance-1.6.4 lib/myfinance/http.rb
myfinance-1.6.3 lib/myfinance/http.rb
myfinance-1.6.1 lib/myfinance/http.rb
myfinance-1.6.0 lib/myfinance/http.rb
myfinance-1.5.0 lib/myfinance/http.rb
myfinance-1.4.1 lib/myfinance/http.rb
myfinance-1.4.0 lib/myfinance/http.rb
myfinance-1.3.1 lib/myfinance/http.rb
myfinance-1.3.0 lib/myfinance/http.rb