Class: RollbarApi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rollbar-api/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, path:, params:) ⇒ Request

Returns a new instance of Request.



4
5
6
7
8
9
# File 'lib/rollbar-api/request.rb', line 4

def initialize(method:, path:, params:)
  @method = method
  path = "/#{path}" unless path.start_with?("/")
  @path = path
  @params = params
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/rollbar-api/request.rb', line 3

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/rollbar-api/request.rb', line 3

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/rollbar-api/request.rb', line 3

def path
  @path
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rollbar-api/request.rb', line 11

def execute
  connection.send(method) do |request|
    if method == :get
      request.url("#{path}?#{params.to_param}")
    else
      request.url(path)
      request.body = body_to_json(params) if params.present?
    end

    request.headers.merge!({
      "Accept" => "application/json",
      "Content-Type" => "application/json",
    })
    request
  end
end