Class: ActiveForms::Request
- Inherits:
-
Object
- Object
- ActiveForms::Request
- Defined in:
- lib/active_forms/request.rb
Instance Attribute Summary collapse
-
#api_params ⇒ Object
readonly
Returns the value of attribute api_params.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
- .delete(path, all_params = {}) ⇒ Object
- .get(path, all_params = {}) ⇒ Object
- .post(path, all_params = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(http_method, path, all_params = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(http_method, path, all_params = {}) ⇒ Request
Returns a new instance of Request.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_forms/request.rb', line 25 def initialize(http_method, path, all_params = {}) all_params.stringify_keys! @http_method = http_method.to_s.upcase @path = path.to_s @api_params = {} @params = {} all_params.each do |k, v| if k.starts_with?("api") @api_params[k] = v else @params[k] = v end end @api_params["apiKey"] = ActiveForms.configuration.api_key @api_params["apiVersion"] = "3.0" @api_params["apiTimestamp"] ||= Time.now.strftime('%Y-%m-%dT%H:%M:%S.000 %z') @api_params["apiSig"] = api_sig @uri = build_uri @options = end |
Instance Attribute Details
#api_params ⇒ Object (readonly)
Returns the value of attribute api_params.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def api_params @api_params end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def http_method @http_method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def path @path end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/active_forms/request.rb', line 9 def uri @uri end |
Class Method Details
.delete(path, all_params = {}) ⇒ Object
20 21 22 |
# File 'lib/active_forms/request.rb', line 20 def delete(path, all_params = {}) new(:delete, path, all_params).perform end |
.get(path, all_params = {}) ⇒ Object
12 13 14 |
# File 'lib/active_forms/request.rb', line 12 def get(path, all_params = {}) new(:get, path, all_params).perform end |
.post(path, all_params = {}) ⇒ Object
16 17 18 |
# File 'lib/active_forms/request.rb', line 16 def post(path, all_params = {}) new(:post, path, all_params).perform end |
Instance Method Details
#perform ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_forms/request.rb', line 50 def perform ActiveForms.log("[ActiveForms] Request: #{http_method.upcase} #{uri}") begin response = HTTParty.send(http_method.downcase, uri, ) verify_response(response) rescue response = HTTParty.send(http_method.downcase, uri, ) verify_response(response) end response end |