Module: Cryptopay::Request
- Defined in:
- lib/cryptopay/net.rb
Class Method Summary collapse
- .get(path, options = {}) ⇒ Object
- .post(path, options = {}) ⇒ Object
- .request(verb, path, options = {}) ⇒ Object
- .to_uri(path) ⇒ Object
Class Method Details
.get(path, options = {}) ⇒ Object
29 30 31 |
# File 'lib/cryptopay/net.rb', line 29 def self.get(path, ={}) self.request(:GET, path, ) end |
.post(path, options = {}) ⇒ Object
33 34 35 |
# File 'lib/cryptopay/net.rb', line 33 def self.post(path, ={}) self.request(:POST, path, ) end |
.request(verb, path, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cryptopay/net.rb', line 7 def self.request(verb, path, ={}) verb = verb.upcase.to_sym [:api_key] = Cryptopay.key resource = RestClient::Resource.new to_uri(path), content_type: 'application/json' begin if verb == :GET response = RestClient.get "#{to_uri(path)}?".concat(.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')) elsif verb == :POST response = resource.post end return JSON.parse response rescue => e error = Cryptopay::Error.new "#{e.message} (#{e.class})" error.errors = JSON.parse(e.response) raise error end end |
.to_uri(path) ⇒ Object
3 4 5 |
# File 'lib/cryptopay/net.rb', line 3 def self.to_uri(path) "https://cryptopay.me/api/v1/#{path}" end |