class CryptocoinPayable::Adapters::Base
Public Instance Methods
convert_main_to_subunit(main)
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 43 def convert_main_to_subunit(main) (main * self.class.subunit_in_main).to_i end
convert_subunit_to_main(subunit)
click to toggle source
Uses a predefined seed to generate HD addresses based on an index/id passed into the method. def self.create_address(id) end
# File lib/cryptocoin_payable/adapters/base.rb, line 39 def convert_subunit_to_main(subunit) subunit / self.class.subunit_in_main.to_f end
create_address(id)
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 62 def create_address(id) raise MissingMasterPublicKey, 'master_public_key is required' unless coin_config.master_public_key master = MoneyTree::Node.from_bip32(coin_config.master_public_key) master.node_for_path(coin_config.node_path + id.to_s) end
fetch_rate()
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 47 def fetch_rate currency = CryptocoinPayable.configuration.currency.to_s.upcase symbol = self.class.coin_symbol amount = begin response = get_request("https://api.coinbase.com/v2/prices/#{symbol}-#{currency}/spot") JSON.parse(response.body)['data']['amount'].to_f rescue StandardError response = get_request("https://api.gemini.com/v1/pubticker/#{symbol}#{currency}") JSON.parse(response.body)['last'].to_f end (amount * 100).to_i end
Protected Instance Methods
adapter_api_key()
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 75 def adapter_api_key @adapter_api_key ||= coin_config && coin_config.adapter_api_key end
coin_config()
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 71 def coin_config @coin_config ||= CryptocoinPayable.configuration.send(self.class.coin_symbol.downcase) end
parse_time(time)
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 83 def parse_time(time) time.nil? ? nil : Time.iso8601(time) end
parse_timestamp(timestamp)
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 79 def parse_timestamp(timestamp) timestamp.nil? ? nil : Time.strptime(timestamp.to_s, '%s') end
Private Instance Methods
get_request(url)
click to toggle source
# File lib/cryptocoin_payable/adapters/base.rb, line 89 def get_request(url) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' request = Net::HTTP::Get.new(uri.request_uri) result = http.request(request) request_delay = CryptocoinPayable.configuration.request_delay sleep request_delay if request_delay result end