class Remitano::Client::Net
Constants
- REMITANO_PRODUCTION_SERVER
- REMITANO_SANDBOX_SERVER
Attributes
config[R]
Public Class Methods
new(config:)
click to toggle source
# File lib/remitano/client/net.rb, line 30 def initialize(config:) @config = config end
public_get(path, params = {})
click to toggle source
# File lib/remitano/client/net.rb, line 43 def self.public_get(path, params = {}) options = { :url => self.to_uri(path), :method => :get, :timeout => 20, :headers => { :params => params, :lang => "vi" } } req = RestClient::Request.new(options) req.headers['Content-Type'] = 'application/json' Remitano::Client::Request.new(req) end
server()
click to toggle source
# File lib/remitano/client/net.rb, line 38 def self.server ENV["REMITANO_SERVER"] || (ENV["REMITANO_SANDBOX"] == "true" ? REMITANO_SANDBOX_SERVER : REMITANO_PRODUCTION_SERVER) end
to_uri(path)
click to toggle source
# File lib/remitano/client/net.rb, line 34 def self.to_uri(path) "#{server}/api/v1#{path}" end
Public Instance Methods
delete(path, params={})
click to toggle source
# File lib/remitano/client/net.rb, line 73 def delete(path, params={}) request = new_request(:delete, path, params) sign_request(request) end
get(path, params={})
click to toggle source
# File lib/remitano/client/net.rb, line 58 def get(path, params={}) request = new_request(:get, path, params) sign_request(request) end
new_request(method, path, params={})
click to toggle source
# File lib/remitano/client/net.rb, line 78 def new_request(method, path, params={}) p [:new_request, method, path] if config.verbose options = { :method => method, :timeout => 20 } usec = Time.now.usec if method == :get uri = URI(path) request_params = URI.decode_www_form(uri.query || "") request_params.concat(params.to_a) request_params << ["usec", usec] uri.query = URI.encode_www_form(request_params) path = uri.to_s else params[:usec] = usec options[:payload] = params.to_json end options[:url] = self.class.to_uri(path) RestClient::Request.new(options) end
patch(path, params={})
click to toggle source
# File lib/remitano/client/net.rb, line 68 def patch(path, params={}) request = new_request(:put, path, params) sign_request(request) end
post(path, params={})
click to toggle source
# File lib/remitano/client/net.rb, line 63 def post(path, params={}) request = new_request(:post, path, params) sign_request(request) end
sign_request(req)
click to toggle source
# File lib/remitano/client/net.rb, line 104 def sign_request(req) req.headers['Content-Type'] = 'application/json' ApiAuth.sign!(req, config.key, config.secret) Remitano::Client::Request.new(req) end