Class: Agcod::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



3
4
5
6
7
8
9
# File 'lib/agcod/request.rb', line 3

def initialize(options = {})
  @request = ""
  @response = ""
  @status = ""
  @parameters = {}
  @options = options
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



32
33
34
# File 'lib/agcod/request.rb', line 32

def action
  @action
end

#errorsObject (readonly)

Returns the value of attribute errors.



32
33
34
# File 'lib/agcod/request.rb', line 32

def errors
  @errors
end

#parametersObject (readonly)

Returns the value of attribute parameters.



32
33
34
# File 'lib/agcod/request.rb', line 32

def parameters
  @parameters
end

#requestObject (readonly)

Returns the value of attribute request.



32
33
34
# File 'lib/agcod/request.rb', line 32

def request
  @request
end

#request_idObject (readonly)

Returns the value of attribute request_id.



32
33
34
# File 'lib/agcod/request.rb', line 32

def request_id
  @request_id
end

#responseObject (readonly)

Returns the value of attribute response.



32
33
34
# File 'lib/agcod/request.rb', line 32

def response
  @response
end

#sentObject (readonly)

Returns the value of attribute sent.



32
33
34
# File 'lib/agcod/request.rb', line 32

def sent
  @sent
end

#statusObject (readonly)

Returns the value of attribute status.



32
33
34
# File 'lib/agcod/request.rb', line 32

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



32
33
34
# File 'lib/agcod/request.rb', line 32

def timestamp
  @timestamp
end

#xml_responseObject (readonly)

Returns the value of attribute xml_response.



32
33
34
# File 'lib/agcod/request.rb', line 32

def xml_response
  @xml_response
end

Instance Method Details

#request_urlObject



50
51
52
# File 'lib/agcod/request.rb', line 50

def request_url
  "#{ Agcod::Configuration.uri }?#{ build_sorted_and_signed_request_string }"
end

#response_idObject



46
47
48
# File 'lib/agcod/request.rb', line 46

def response_id
  @response_id || @options["response_id"]
end

#sign_string(string_to_sign) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/agcod/request.rb', line 34

def sign_string(string_to_sign)
  digest = OpenSSL::Digest.new('sha256')
  sha256 = OpenSSL::HMAC.digest(digest, Agcod::Configuration.secret_key, string_to_sign)

  #Base64 encoding adds a linefeed to the end of the string so chop the last character!
  CGI.escape(Base64.encode64(sha256).chomp)
end

#submitObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/agcod/request.rb', line 11

def submit
  #action must be specified so raise an exception if it has not been populated
  if self.action.nil?
    raise "Action not specified"
  end

  #form the request GET parameter string
  @request = build_sorted_and_signed_request_string

  send_request

  if @response
    process_response
    log if Agcod::Configuration.logger
  end
end

#successful?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/agcod/request.rb', line 28

def successful?
  self.sent && self.errors.size == 0 && self.status == "SUCCESS"
end