Class: PagarMe::Request
Constant Summary collapse
- SSL_CA_FILEPATH =
File.join File.dirname(__FILE__), '..', '..', 'certs', 'cabundle.pem'
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/json; charset=utf8', 'Accept' => 'application/json', 'User-Agent' => "pagarme-ruby/#{PagarMe::VERSION}", 'X-PagarMe-User-Agent' => "pagarme-ruby/#{PagarMe::VERSION}" }
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query ⇒ Object
Returns the value of attribute query.
Class Method Summary collapse
- .delete(url, options = {}) ⇒ Object
- .get(url, options = {}) ⇒ Object
- .post(url, options = {}) ⇒ Object
- .put(url, options = {}) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path, method, options = {}) ⇒ Request
constructor
A new instance of Request.
- #run ⇒ Object
Constructor Details
#initialize(path, method, options = {}) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 22 23 24 25 |
# File 'lib/pagarme/request.rb', line 17 def initialize(path, method, ={}) raise PagarMe::RequestError, 'You need to configure a API key before performing requests.' unless PagarMe.api_key @path = path @method = method @parameters = [:params] || Hash.new @query = [:query] || Hash.new @headers = [:headers] || Hash.new end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/pagarme/request.rb', line 7 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'lib/pagarme/request.rb', line 7 def method @method end |
#parameters ⇒ Object
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/pagarme/request.rb', line 7 def parameters @parameters end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/pagarme/request.rb', line 7 def path @path end |
#query ⇒ Object
Returns the value of attribute query.
7 8 9 |
# File 'lib/pagarme/request.rb', line 7 def query @query end |
Class Method Details
.delete(url, options = {}) ⇒ Object
74 75 76 |
# File 'lib/pagarme/request.rb', line 74 def self.delete(url, ={}) self.new url, 'DELETE', end |
.get(url, options = {}) ⇒ Object
62 63 64 |
# File 'lib/pagarme/request.rb', line 62 def self.get(url, ={}) self.new url, 'GET', end |
.post(url, options = {}) ⇒ Object
66 67 68 |
# File 'lib/pagarme/request.rb', line 66 def self.post(url, ={}) self.new url, 'POST', end |
.put(url, options = {}) ⇒ Object
70 71 72 |
# File 'lib/pagarme/request.rb', line 70 def self.put(url, ={}) self.new url, 'PUT', end |
Instance Method Details
#call ⇒ Object
58 59 60 |
# File 'lib/pagarme/request.rb', line 58 def call PagarMeObject.convert run end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pagarme/request.rb', line 27 def run response = RestClient::Request.execute request_params MultiJson.decode response.body rescue RestClient::Exception => error begin parsed_error = MultiJson.decode error.http_body if error.is_a? RestClient::ResourceNotFound if parsed_error['errors'] raise PagarMe::NotFound.new(parsed_error, request_params, error) else raise PagarMe::NotFound.new(nil, request_params, error) end else if parsed_error['errors'] raise PagarMe::ValidationError.new parsed_error else raise PagarMe::ResponseError.new(request_params, error) end end rescue MultiJson::ParseError raise PagarMe::ResponseError.new(request_params, error) end rescue MultiJson::ParseError raise PagarMe::ResponseError.new(request_params, response) rescue SocketError raise PagarMe::ConnectionError.new $! rescue RestClient::ServerBrokeConnection raise PagarMe::ConnectionError.new $! end |