Class: WixAnswers::REST::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/wixanswers/rest/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options: {}, headers: {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/wixanswers/rest/request.rb', line 6

def initialize(client, request_method, path, options: {}, headers: {})
  @client = client

  @request_method = request_method.to_sym

  @uri = Addressable::URI.parse("#{client.base_url}/#{client.version}/#{path}")
  @path = @uri.path

  @options = options
  @headers = default_headers.merge(headers)
end

Instance Method Details

#default_headersObject



24
25
26
# File 'lib/wixanswers/rest/request.rb', line 24

def default_headers
  {'Content-Type' => 'application/json; charset=utf-8', 'Accept' => 'application/json'}
end

#performObject



18
19
20
21
22
# File 'lib/wixanswers/rest/request.rb', line 18

def perform
  response = self.send(@request_method, @uri.to_s, headers: @headers)

  response.body
end