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_corporation_id(corporation_id) ⇒ Object
- #set_debug_logger(debug_logger) ⇒ Object
- #set_integrator_id(integrator_id) ⇒ Object
- #set_platform_id(platform_id) ⇒ Object
Constructor Details
#initialize(debug_logger = nil) ⇒ RestClient
Returns a new instance of RestClient.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/mercadopago.rb', line 314 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 @platform_id = nil @integrator_id = nil @corporation_id = nil end |
Instance Method Details
#delete(uri, content_type = MIME_JSON) ⇒ Object
385 386 387 |
# File 'lib/mercadopago.rb', line 385 def delete(uri, content_type=MIME_JSON) exec("DELETE", uri, nil, content_type) end |
#exec(method, uri, data, content_type) ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/mercadopago.rb', line 348 def exec(method, uri, data, content_type) if not data.nil? and content_type == MIME_JSON data = data.to_json end headers = { 'x-product-id' => PRODUCT_ID, 'x-tracking-id' => "platform:"+RUBY_VERSION.split('.')[0]+"|"+RUBY_VERSION+",type:SDK"+MERCADO_PAGO_VERSION+",so;", 'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION, 'Content-type' => content_type, 'Accept' => MIME_JSON } headers['x-platform-id'] = @platform_id if @platform_id != nil headers['x-integrator-id'] = @integrator_id if @integrator_id != nil headers['x-corporation-id'] = @corporation_id if @corporation_id != nil 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
373 374 375 |
# File 'lib/mercadopago.rb', line 373 def get(uri, content_type=MIME_JSON) exec("GET", uri, nil, content_type) end |
#post(uri, data = nil, content_type = MIME_JSON) ⇒ Object
377 378 379 |
# File 'lib/mercadopago.rb', line 377 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
381 382 383 |
# File 'lib/mercadopago.rb', line 381 def put(uri, data = nil, content_type=MIME_JSON) exec("PUT", uri, data, content_type) end |
#set_corporation_id(corporation_id) ⇒ Object
344 345 346 |
# File 'lib/mercadopago.rb', line 344 def set_corporation_id(corporation_id) @corporation_id = corporation_id end |
#set_debug_logger(debug_logger) ⇒ Object
332 333 334 |
# File 'lib/mercadopago.rb', line 332 def set_debug_logger(debug_logger) @http.set_debug_output debug_logger end |
#set_integrator_id(integrator_id) ⇒ Object
340 341 342 |
# File 'lib/mercadopago.rb', line 340 def set_integrator_id(integrator_id) @integrator_id = integrator_id end |
#set_platform_id(platform_id) ⇒ Object
336 337 338 |
# File 'lib/mercadopago.rb', line 336 def set_platform_id(platform_id) @platform_id = platform_id end |