class Xolphin::Api::Http
Constants
- LIVE_URL
- TEST_URL
Public Class Methods
new(username, password, options = {})
click to toggle source
# File lib/xolphin/api/http.rb, line 12 def initialize(username, password, options = {}) @username = username @password = password @test = options[:test] end
Public Instance Methods
download(path, params = {})
click to toggle source
# File lib/xolphin/api/http.rb, line 46 def download(path, params = {}) uri = URI.parse(File.join(api_url, path)) uri.query = URI.encode_www_form(params) unless params.empty? request = Net::HTTP::Get.new(uri) request.basic_auth(@username, @password) response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end response.body end
get(path, params = {})
click to toggle source
# File lib/xolphin/api/http.rb, line 18 def get(path, params = {}) uri = URI.parse(File.join(api_url, path)) uri.query = URI.encode_www_form(params) unless params.empty? request = Net::HTTP::Get.new(uri) request.basic_auth(@username, @password) response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end JSON.parse(response.body) end
post(path, params = {})
click to toggle source
# File lib/xolphin/api/http.rb, line 32 def post(path, params = {}) uri = URI.parse(File.join(api_url, path)) request = Net::HTTP::Post.new(uri) request.basic_auth(@username, @password) request.set_form_data(params) response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end JSON.parse(response.body) end
Private Instance Methods
api_url()
click to toggle source
# File lib/xolphin/api/http.rb, line 62 def api_url @test ? TEST_URL : LIVE_URL end