Class: ActiveForms::Request

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
# 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
end

Instance Attribute Details

#api_paramsObject (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_methodObject (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

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/active_forms/request.rb', line 9

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/active_forms/request.rb', line 9

def path
  @path
end

#uriObject (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

#performObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_forms/request.rb', line 49

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