Sha256: 423df18b2e606f49841c9938eb634ce918b5697fdac0660509b296b0579a278e

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

module MyMoip
  class Request
    include HTTParty

    attr_reader :id, :data, :response

    def initialize(id)
      @id = id
    end

    def api_call(params, opts = {})
      opts[:logger]   ||= MyMoip.logger
      opts[:username] ||= MyMoip.token
      opts[:password] ||= MyMoip.key

      opts[:logger].info "New #{self.class} being sent to MoIP."
      opts[:logger].debug "#{self.class} of ##{@id} with #{params.inspect}"

      url = MyMoip.api_url + params.delete(:path)
      params[:basic_auth] = { username: opts[:username], password: opts[:password] }

      @response = HTTParty.send params.delete(:http_method), url, params

      opts[:logger].debug "#{self.class} of ##{@id} to #{url} had response #{@response.inspect}"
    end
  end
end

requests = Dir[File.dirname(__FILE__) + "/requests/*.rb"]
requests.each { |f| require f }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mymoip-0.2.5 lib/mymoip/request.rb