Class: AuthorizeNet::Request

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

Overview

This class represents a request to the Authorize.Net API

Add any logic that applies to ALL requests here

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, data, uri) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
# File 'lib/authorize_net/request.rb', line 13

def initialize(type, data, uri)
  @xml_data = data
  @request_type = type
  @uri = URI(uri)
  @response = nil
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



11
12
13
# File 'lib/authorize_net/request.rb', line 11

def response
  @response
end

Instance Method Details

#getRequestObject

Uses the given data to make a GET request



36
37
38
39
40
41
# File 'lib/authorize_net/request.rb', line 36

def getRequest
  assertRequestType
  req = Net::HTTP::Get.new(@uri.request_uri)
  req.add_field('Content-Type', 'text/xml')
  req.body = buildXmlRequest
end

#postRequestObject

Uses the given data to make a POST request



23
24
25
26
27
28
29
30
31
# File 'lib/authorize_net/request.rb', line 23

def postRequest
  assertRequestData
  assertRequestType
  req = Net::HTTP::Post.new(@uri.request_uri)
  req.add_field('Content-Type', 'text/xml')
  req.body = buildXmlRequest
  @response = sendRequest(req)
  return @response
end

#toLog(log_body) ⇒ Object

Make a log string for this request



46
47
48
49
50
51
52
53
54
# File 'lib/authorize_net/request.rb', line 46

def toLog(log_body)
  log = "[AuthorizeNet] HTTP Request type=#{@request_type} uri=#{@uri}"

  if log_body
    log += " body=\"#{buildXmlRequest}\""
  end

  return log
end