Class: Spear::Request

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
HTTParty
Defined in:
lib/spear/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, endpoint, params = {}) ⇒ Request

params: => {, :query => {}}



18
19
20
21
22
23
24
25
# File 'lib/spear/request.rb', line 18

def initialize(method, endpoint, params={})
  @method = method
  @query = params[:query] || {}
  @body = params[:body] || {}
  @header = params[:header] || {}
  @api_options = params[:api_options] || {}
  @url = Spear.base_uri + endpoint
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



15
16
17
# File 'lib/spear/request.rb', line 15

def body
  @body
end

#methodObject

Returns the value of attribute method.



15
16
17
# File 'lib/spear/request.rb', line 15

def method
  @method
end

#queryObject

Returns the value of attribute query.



15
16
17
# File 'lib/spear/request.rb', line 15

def query
  @query
end

#urlObject

Returns the value of attribute url.



15
16
17
# File 'lib/spear/request.rb', line 15

def url
  @url
end

Instance Method Details

#executeObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/spear/request.rb', line 27

def execute
  run_callbacks(:execute) {
    response = exec
    begin
      self.api_response = response
    rescue NoMethodError => e  # if we don't use save api info plugin, it'll throw NoMethodError.
      response
    end
  }
end