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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_forms/request.rb', line 23

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"]   = "1.0"
  @api_params["apiTimestamp"] ||= Time.now.utc.iso8601(3)
  @api_params["apiSig"]       = api_sig

  @uri = build_uri
end

Instance Attribute Details

#api_paramsObject (readonly)

Returns the value of attribute api_params.



7
8
9
# File 'lib/active_forms/request.rb', line 7

def api_params
  @api_params
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



7
8
9
# File 'lib/active_forms/request.rb', line 7

def http_method
  @http_method
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/active_forms/request.rb', line 7

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/active_forms/request.rb', line 7

def path
  @path
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/active_forms/request.rb', line 7

def uri
  @uri
end

Class Method Details

.delete(path, all_params = {}) ⇒ Object



18
19
20
# File 'lib/active_forms/request.rb', line 18

def delete(path, all_params = {})
  new(:delete, path, all_params).perform
end

.get(path, all_params = {}) ⇒ Object



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

def get(path, all_params = {})
  new(:get, path, all_params).perform
end

.post(path, all_params = {}) ⇒ Object



14
15
16
# File 'lib/active_forms/request.rb', line 14

def post(path, all_params = {})
  new(:post, path, all_params).perform
end

Instance Method Details

#performObject



47
48
49
50
51
# File 'lib/active_forms/request.rb', line 47

def perform
  response = HTTParty.send(http_method.downcase, uri)
  raise_error(response)
  response
end