Class: InternetBS::Client
- Inherits:
-
Object
- Object
- InternetBS::Client
- Defined in:
- lib/internetbs/client.rb
Class Method Summary collapse
Class Method Details
.get(endpoint, params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/internetbs/client.rb', line 17 def self.get(endpoint, params = {}) begin uri = URI.parse([InternetBS.api_uri, endpoint].join) @params.merge!(params) if params.any? uri.query = 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::Get.new(uri, @headers) response = http.request(request) rescue StandardError => error puts "Request failed (#{error.})" end end |
.post(endpoint, params = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/internetbs/client.rb', line 32 def self.post(endpoint, params = {}) begin uri = URI.parse([InternetBS.api_uri, endpoint].join) uri.query = URI.encode_www_form(@params) 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 "Request failed (#{error.})" end end |