Class: MercadoPago::RestClient
- Inherits:
-
Object
- Object
- MercadoPago::RestClient
- Defined in:
- lib/mercadopago.rb
Constant Summary collapse
- MIME_JSON =
'application/json'
- MIME_FORM =
'application/x-www-form-urlencoded'
- API_BASE_URL =
URI.parse('https://api.mercadopago.com')
Instance Method Summary collapse
- #delete(uri, content_type = MIME_JSON) ⇒ Object
- #exec(method, uri, data, content_type) ⇒ Object
- #get(uri, content_type = MIME_JSON) ⇒ Object
-
#initialize(debug_logger = nil) ⇒ RestClient
constructor
A new instance of RestClient.
- #post(uri, data = nil, content_type = MIME_JSON) ⇒ Object
- #put(uri, data = nil, content_type = MIME_JSON) ⇒ Object
- #set_debug_logger(debug_logger) ⇒ Object
Constructor Details
#initialize(debug_logger = nil) ⇒ RestClient
Returns a new instance of RestClient.
296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/mercadopago.rb', line 296 def initialize(debug_logger=nil) @http = Net::HTTP.new(API_BASE_URL.host, API_BASE_URL.port) if API_BASE_URL.scheme == "https" # enable SSL/TLS @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_PEER # explicitly tell OpenSSL not to use SSL3 nor TLS 1.0 @http. = OpenSSL::SSL::OP_NO_SSLv3 + OpenSSL::SSL::OP_NO_TLSv1 end @http.set_debug_output debug_logger if debug_logger end |
Instance Method Details
#delete(uri, content_type = MIME_JSON) ⇒ Object
345 346 347 |
# File 'lib/mercadopago.rb', line 345 def delete(uri, content_type=MIME_JSON) exec("DELETE", uri, nil, content_type) end |
#exec(method, uri, data, content_type) ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/mercadopago.rb', line 314 def exec(method, uri, data, content_type) if not data.nil? and content_type == MIME_JSON data = data.to_json end headers = { 'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION, 'Content-type' => content_type, 'Accept' => MIME_JSON } api_result = @http.send_request(method, uri, data, headers) { "status" => api_result.code, "response" => JSON.parse(api_result.body) } end |
#get(uri, content_type = MIME_JSON) ⇒ Object
333 334 335 |
# File 'lib/mercadopago.rb', line 333 def get(uri, content_type=MIME_JSON) exec("GET", uri, nil, content_type) end |
#post(uri, data = nil, content_type = MIME_JSON) ⇒ Object
337 338 339 |
# File 'lib/mercadopago.rb', line 337 def post(uri, data = nil, content_type=MIME_JSON) exec("POST", uri, data, content_type) end |
#put(uri, data = nil, content_type = MIME_JSON) ⇒ Object
341 342 343 |
# File 'lib/mercadopago.rb', line 341 def put(uri, data = nil, content_type=MIME_JSON) exec("PUT", uri, data, content_type) end |
#set_debug_logger(debug_logger) ⇒ Object
310 311 312 |
# File 'lib/mercadopago.rb', line 310 def set_debug_logger(debug_logger) @http.set_debug_output debug_logger end |