Class: Zesty::Request

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_method, url, params, headers) ⇒ Request

Returns a new instance of Request.



28
29
30
31
32
33
# File 'lib/zesty/request.rb', line 28

def initialize(request_method, url, params, headers)
  @request_method = request_method
  @url = url
  @params = params
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/zesty/request.rb', line 6

def headers
  @headers
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/zesty/request.rb', line 6

def params
  @params
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



6
7
8
# File 'lib/zesty/request.rb', line 6

def request_method
  @request_method
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/zesty/request.rb', line 6

def url
  @url
end

Class Method Details

.delete(url, params: {}, headers: {}) ⇒ Object



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

def self.delete(url, params: {}, headers: {})
  Request.new(:delete, url, params, headers).perform
end

.get(url, params: nil, headers: {}) ⇒ Object



8
9
10
# File 'lib/zesty/request.rb', line 8

def self.get(url, params: nil, headers: {})
  Request.new(:get, url, params, headers).perform
end

.post(url, params: {}, headers: {}) ⇒ Object



16
17
18
# File 'lib/zesty/request.rb', line 16

def self.post(url, params: {}, headers: {})
  Request.new(:post, url, params, headers).perform
end

.post_form(url, params: {}, headers: {}) ⇒ Object



12
13
14
# File 'lib/zesty/request.rb', line 12

def self.post_form(url, params: {}, headers: {})
  Request.new(:post_form, url, params, headers).perform
end

.put(url, params: {}, headers: {}) ⇒ Object



20
21
22
# File 'lib/zesty/request.rb', line 20

def self.put(url, params: {}, headers: {})
  Request.new(:put, url, params, headers).perform
end

Instance Method Details

#performObject



35
36
37
38
# File 'lib/zesty/request.rb', line 35

def perform
  response = send(@request_method)
  process_response(response)
end