Class: MyMoip::Request
- Inherits:
-
Object
- Object
- MyMoip::Request
- Includes:
- HTTParty
- Defined in:
- lib/mymoip/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #api_call(params, opts = {}) ⇒ Object
-
#initialize(id) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(id) ⇒ Request
Returns a new instance of Request.
7 8 9 |
# File 'lib/mymoip/request.rb', line 7 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/mymoip/request.rb', line 5 def id @id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/mymoip/request.rb', line 5 def response @response end |
Instance Method Details
#api_call(params, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mymoip/request.rb', line 11 def api_call(params, opts = {}) opts[:logger] ||= MyMoip.logger opts[:username] ||= MyMoip.token opts[:password] ||= MyMoip.key unless opts[:username].present? && opts[:password].present? MyMoip.ensure_key_and_token_set! end 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 |