Class: Regaliator::Request
- Inherits:
-
Object
- Object
- Regaliator::Request
- Defined in:
- lib/regaliator/request.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#http_request ⇒ Object
readonly
Returns the value of attribute http_request.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(config, endpoint, params = {}) ⇒ Request
constructor
A new instance of Request.
- #patch ⇒ Object
- #post ⇒ Object
- #send_request ⇒ Object
Constructor Details
#initialize(config, endpoint, params = {}) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 21 22 |
# File 'lib/regaliator/request.rb', line 15 def initialize(config, endpoint, params = {}) @config = config @timestamp = Time.now.utc.httpdate.to_s @endpoint = endpoint @params = params @uri = build_uri @http = build_http end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def config @config end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def endpoint @endpoint end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def http @http end |
#http_request ⇒ Object (readonly)
Returns the value of attribute http_request.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def http_request @http_request end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def params @params end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def @timestamp end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
13 14 15 |
# File 'lib/regaliator/request.rb', line 13 def uri @uri end |
Instance Method Details
#get ⇒ Object
31 32 33 34 35 36 |
# File 'lib/regaliator/request.rb', line 31 def get uri.query = URI.encode_www_form(params) if !params.empty? @http_request = Net::HTTP::Get.new(uri.request_uri) send_request end |
#patch ⇒ Object
38 39 40 41 42 43 |
# File 'lib/regaliator/request.rb', line 38 def patch @http_request = Net::HTTP::Patch.new(uri.request_uri) @http_request.body = params.to_json send_request end |
#post ⇒ Object
24 25 26 27 28 29 |
# File 'lib/regaliator/request.rb', line 24 def post @http_request = Net::HTTP::Post.new(uri.request_uri) @http_request.body = params.to_json send_request end |
#send_request ⇒ Object
45 46 47 48 49 50 |
# File 'lib/regaliator/request.rb', line 45 def send_request apply_headers response = http.request(http_request) Regaliator::Response.new(response) end |