Class: Trustpilot::Request
- Inherits:
-
Object
- Object
- Trustpilot::Request
- Defined in:
- lib/trustpilot/request.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(path, headers: {}, params: {}, verb: 'get') ⇒ Request
constructor
Initializes a new request to the API.
-
#to_http_request ⇒ Object
Returns the request as a Net::HTTPRequest.
-
#uri ⇒ Object
Returns the full URI for the request.
Constructor Details
#initialize(path, headers: {}, params: {}, verb: 'get') ⇒ Request
Initializes a new request to the API
args:
path: string
headers: { [key: string]: string }
params: { [key: string]: string }
verb: 'delete' | 'get' | 'patch' | 'post' | 'put'
16 17 18 19 20 21 |
# File 'lib/trustpilot/request.rb', line 16 def initialize path, headers: {}, params: {}, verb: 'get' @headers = headers @params = params @path = path @verb = verb end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/trustpilot/request.rb', line 7 def headers @headers end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/trustpilot/request.rb', line 7 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/trustpilot/request.rb', line 7 def path @path end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
7 8 9 |
# File 'lib/trustpilot/request.rb', line 7 def verb @verb end |
Instance Method Details
#to_http_request ⇒ Object
Returns the request as a Net::HTTPRequest
24 25 26 27 28 29 |
# File 'lib/trustpilot/request.rb', line 24 def to_http_request build_request.tap do |req| # Set headers headers.each { |h, v| req[ h ] = v } end end |
#uri ⇒ Object
Returns the full URI for the request
32 33 34 35 36 37 38 39 |
# File 'lib/trustpilot/request.rb', line 32 def uri @uri ||= if path.start_with? 'http' URI path else URI( Trustpilot.api_url + path ) end end |