Class: Segurofacil::REST::Request
- Inherits:
-
Object
- Object
- Segurofacil::REST::Request
- Defined in:
- lib/segurofacil/rest/request.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json', 'User-Agent' => "segurofacil-ruby/#{Segurofacil::VERSION}" }
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, method, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(path, method, options = {}) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 |
# File 'lib/segurofacil/rest/request.rb', line 16 def initialize(path, method, ={}) @path = path @method = method @parameters = .fetch(:params, Hash.new) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/segurofacil/rest/request.rb', line 8 def method @method end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
8 9 10 |
# File 'lib/segurofacil/rest/request.rb', line 8 def parameters @parameters end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/segurofacil/rest/request.rb', line 8 def path @path end |
Class Method Details
.post(path, options = {}) ⇒ Object
42 43 44 |
# File 'lib/segurofacil/rest/request.rb', line 42 def post(path, ={}) self.new path, 'POST', end |
Instance Method Details
#perform ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/segurofacil/rest/request.rb', line 22 def perform json_res = {} begin res = RestClient::Request.execute request_params json_res[:body] = MultiJson.load res.body json_res[:code] = res.code rescue RestClient::ExceptionWithResponse => e parsed_error = MultiJson.load e.http_body json_res[:error] = true json_res[:body] = parsed_error json_res[:code] = e.response.code end json_res end |