Class: GlobeSSL::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/globessl/client.rb

Class Method Summary collapse

Class Method Details

.get(endpoint, params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/globessl/client.rb', line 12

def self.get(endpoint, params = {})
  begin
    uri = URI.parse([GlobeSSL.api_uri, endpoint].join)
    uri.query = URI.encode_www_form(params) if params.any?
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    request = Net::HTTP::Get.new(uri, @headers)
    response = http.request(request)
  rescue StandardError => error
    puts "HTTP Request failed (#{error.message})"
  end
end

.post(endpoint, params = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/globessl/client.rb', line 26

def self.post(endpoint, params = {})
  begin
    uri = URI.parse([GlobeSSL.api_uri, endpoint].join)
    body = URI.encode_www_form(params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    request = Net::HTTP::Post.new(uri, @headers)
    request.add_field "Content-Type", "application/x-www-form-urlencoded"
    request.body = body
    response = http.request(request)
  rescue StandardError => error
    puts "HTTP Request failed (#{error.message})"
  end
end