Module: Netki
- Defined in:
- lib/netki.rb
Class Method Summary collapse
-
.process_request(uri) ⇒ Object
Request Utility Functionality.
-
.wallet_lookup(uri, currency, api_url = 'https://api.netki.com') ⇒ Object
Query the Netki Open API for an address.
Class Method Details
.process_request(uri) ⇒ Object
Request Utility Functionality
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/netki.rb', line 9 def self.process_request(uri) # Setup Headers headers = {} headers["Content-Type"] = "application/json" # Setup Request Options opts = {} opts[:header] = headers method = 'GET' client = HTTPClient.new _uri = URI.parse(uri) response = client.request(method, _uri, opts) # We should have response content at this point raise "Empty Response Received" if response.content.nil? || response.content.empty? # Verify we have the correct content type raise "Non-JSON Content Type" if response.headers['Content-Type'] != 'application/json' # Make Sure We Can Decode JSON Response begin ret_data = JSON.parse(response.content) rescue JSON::ParserError => e raise "Invalid JSON Response Received" end return ret_data end |
.wallet_lookup(uri, currency, api_url = 'https://api.netki.com') ⇒ Object
Query the Netki Open API for an address
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/netki.rb', line 39 def self.wallet_lookup(uri, currency, api_url='https://api.netki.com') wallet_name = URI.parse(uri).host || uri.to_s response = process_request("#{api_url}/api/wallet_lookup/#{wallet_name}/#{currency.downcase}") netki_address = response['wallet_address'] unless netki_address.nil? || netki_address == 0 return netki_address else return false, "No Address Found" end end |