Class: Remitano::Client::Net
- Inherits:
-
Object
- Object
- Remitano::Client::Net
- Defined in:
- lib/remitano/client/net.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(config:) ⇒ Net
constructor
A new instance of Net.
- #new_request(method, path, params = {}) ⇒ Object
- #patch(path, params = {}) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #sign_request(req) ⇒ Object
Constructor Details
#initialize(config:) ⇒ Net
Returns a new instance of Net.
25 26 27 |
# File 'lib/remitano/client/net.rb', line 25 def initialize(config:) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/remitano/client/net.rb', line 23 def config @config end |
Class Method Details
.public_get(path, params = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/remitano/client/net.rb', line 37 def self.public_get(path, params = {}) = { :url => self.to_uri(path), :method => :get, :timeout => 20, :headers => { :params => params, :lang => "vi" } } req = RestClient::Request.new() req.headers['Content-Type'] = 'application/json' Remitano::Client::Request.new(req) end |
.server ⇒ Object
33 34 35 |
# File 'lib/remitano/client/net.rb', line 33 def self.server @server ||= (ENV['REMITANO_SERVER'] || "https://api.remitano.com") end |
.to_uri(path) ⇒ Object
29 30 31 |
# File 'lib/remitano/client/net.rb', line 29 def self.to_uri(path) return "#{server}/api/v1#{path}" end |
Instance Method Details
#delete(path, params = {}) ⇒ Object
67 68 69 70 |
# File 'lib/remitano/client/net.rb', line 67 def delete(path, params={}) request = new_request(:delete, path, params) sign_request(request) end |
#get(path, params = {}) ⇒ Object
52 53 54 55 |
# File 'lib/remitano/client/net.rb', line 52 def get(path, params={}) request = new_request(:get, path, params) sign_request(request) end |
#new_request(method, path, params = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/remitano/client/net.rb', line 72 def new_request(method, path, params={}) p [:new_request, method, path] if config.verbose = { :method => method, :timeout => 20 } usec = Time.now.usec if method == :get path += (path.include?("?") ? "&" : "?") path += "usec=#{usec}" else params[:usec] = usec [:payload] = params.to_json end [:url] = self.class.to_uri(path) RestClient::Request.new() end |
#patch(path, params = {}) ⇒ Object
62 63 64 65 |
# File 'lib/remitano/client/net.rb', line 62 def patch(path, params={}) request = new_request(:put, path, params) sign_request(request) end |
#post(path, params = {}) ⇒ Object
57 58 59 60 |
# File 'lib/remitano/client/net.rb', line 57 def post(path, params={}) request = new_request(:post, path, params) sign_request(request) end |