Class: Intis::Sdk::Gateway
- Inherits:
-
Object
- Object
- Intis::Sdk::Gateway
- Defined in:
- lib/intis/sdk/gateway.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Gateway
constructor
A new instance of Gateway.
- #request(path, params = {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ Gateway
Returns a new instance of Gateway.
9 10 11 |
# File 'lib/intis/sdk/gateway.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#request(path, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/intis/sdk/gateway.rb', line 13 def request(path, params = {}) url = URI.parse("https://#{@config[:api_host]}/external#{path}") http = Net::HTTP.new(url.host, url.port) http.read_timeout = 15 http.open_timeout = 15 http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE headers = {} params[:login] = @config[:login] params[:timestamp] = Time.now.to_i signature = Digest::MD5.hexdigest(params.sort.map{|k,v| v}.join + @config[:api_key]) params[:signature] = signature url_params = "" url_params += URI.encode_www_form(params) if params.any? req = Net::HTTP::Get.new(url.path + "?" + url_params, headers) response = http.start() {|http| http.request(req) } if response.kind_of?(Net::HTTPSuccess) return UrlHelper.parse_data(response) else raise response.inspect end end |