Module: PagSeguro::Request

Extended by:
Forwardable, Request
Included in:
Request
Defined in:
lib/pagseguro/request.rb

Instance Method Summary collapse

Instance Method Details

#execute(request_method, path, api_version, data, headers) ⇒ Object

Perform the specified HTTP request. It will include the API credentials, api_version, encoding and additional headers.



81
82
83
84
85
86
87
88
# File 'lib/pagseguro/request.rb', line 81

def execute(request_method, path, api_version, data, headers) # :nodoc:
  request.public_send(
    request_method,
    PagSeguro.api_url("#{api_version}/#{path}"),
    extended_data(data),
    extended_headers(request_method, headers)
  )
end

#get(path, api_version, data = {}, headers = {}) ⇒ Object

Perform a GET request.

# path: the path that will be requested. Must be something like "transactions/code/739D69-79C052C05280-55542D9FBB33-CAB2B1". # api_version: the current PagSeguro API version of the requested service # data: the data that will be sent as query string. Must be a Hash. # headers: any additional header that will be sent through the request.



17
18
19
# File 'lib/pagseguro/request.rb', line 17

def get(path, api_version, data = {}, headers = {})
  execute :get, path, api_version, data, headers
end

#get_with_auth_on_url(path, api_version, credentials) ⇒ Object



21
22
23
24
25
26
# File 'lib/pagseguro/request.rb', line 21

def get_with_auth_on_url(path, api_version, credentials)
  request.public_send(
    :get,
    PagSeguro.api_url("#{api_version}/#{path}?#{credentials_to_params(credentials)}")
  )
end

#get_without_api_version(path, data = {}, headers = {}) ⇒ Object



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

def get_without_api_version(path, data={}, headers={})
  request.get(path, extended_data(data), headers)
end

#post(path, api_version, data = {}, headers = {}) ⇒ Object

Perform a POST request.

# path: the path that will be requested. Must be something like "checkout". # api_version: the current PagSeguro API version of the requested service # data: the data that will be sent as body data. Must be a Hash. # headers: any additional header that will be sent through the request.



39
40
41
# File 'lib/pagseguro/request.rb', line 39

def post(path, api_version, data = {}, headers = {})
  execute :post, path, api_version, data, headers
end

#post_xml(path, api_version, credentials, data = '', options = {}) ⇒ Object

Perform a POST request, sending XML data.

# path: the path that will be requested. Must be something like "checkout". # api_version: the current PagSeguro API version of the requested service # credentials: the credentials like ApplicationCredentials or AccountCredentials. # data: the data that will be sent as body data. Must be a XML.



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

def post_xml(path, api_version, credentials, data = '', options={})
  credentials_params = credentials_to_params(credentials)
  url_path = [api_version, path].reject(&:nil?).join('/')

  request.post do
    url PagSeguro.api_url("#{url_path}?#{credentials_params}")
    headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}"
    headers.merge!(options[:headers]) if options[:headers]
    body data
  end
end

#put_xml(path, credentials, data) ⇒ Object

Perform a PUT request, sending XML data.

# path: the path that will be requested. Must be something like "checkout". # credentials: the credentials like ApplicationCredentials or AccountCredentials. # data: the data that will be sent as body data. Must be a XML.



68
69
70
71
72
73
74
75
76
77
# File 'lib/pagseguro/request.rb', line 68

def put_xml(path, credentials, data)
  full_url = PagSeguro.api_url("#{path}?#{credentials_to_params(credentials)}")

  request.put do
    url full_url
    headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}",
            "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1"
    body data
  end
end