Class: CoinPayments::Api
- Inherits:
-
Object
- Object
- CoinPayments::Api
- Includes:
- HTTParty
- Defined in:
- lib/coin_payments/api.rb
Constant Summary collapse
- URL_ENDPOINT =
ENV.fetch("COIN_PAYMENTS_BASE_URL", "https://www.coinpayments.net/api.php")
- API_VERSION =
ENV.fetch("COIN_PAYMENTS_API_VERSION", "1")
Instance Method Summary collapse
-
#callback_addresses(options = {}) ⇒ Object
Callback Addresses CoinPayments::Api.new.callback_addresses.
-
#claim_tag ⇒ Object
Claim Tag CoinPayments::Api.new.claim_tag.
-
#conversion_limits ⇒ Object
Conversion Limits CoinPayments::Api.new.conversion_limits.
-
#convert_coins ⇒ Object
Convert Coins CoinPayments::Api.new.convert_coins.
-
#create_transaction(options = {}) ⇒ Object
Receiving Payments Create Transaction CoinPayments::Api.new.create_transaction amount: 10, currency1: “USD”, currency2: “BTC”, buyer_email: “[email protected]”, buyer_name: “John Doe”.
-
#create_transfer ⇒ Object
Withdrawals/Transfers Create Transfer CoinPayments::Api.new.create_transfer.
-
#create_withdrawal ⇒ Object
Create Withdrawal / Mass Withdrawal CoinPayments::Api.new.create_withdrawal.
-
#get_basic_account_info ⇒ Object
Get Basic Account Info CoinPayments::Api.new.get_basic_account_info.
-
#get_coin_balances(options = {}) ⇒ Object
Get Coin Balances CoinPayments::Api.new.get_coin_balances CoinPayments::Api.new.get_coin_balances all: true.
-
#get_conversion_info ⇒ Object
Get Conversion Info CoinPayments::Api.new.get_conversion_info.
-
#get_deposit_address(currency = "BTC") ⇒ Object
Get Deposit Address CoinPayments::Api.new.get_deposit_address.
-
#get_exchange_rates(options = {}) ⇒ Object
Get Exchange Rates / Supported Coins CoinPayments::Api.new.get_exchange_rates CoinPayments::Api.new.get_exchange_rates accepted: true CoinPayments::Api.new.get_exchange_rates accepted: true, accepted_only: true.
-
#get_profile_information ⇒ Object
PayByName Get Profile Information CoinPayments::Api.new.get_profile_information.
-
#get_tag_list ⇒ Object
Get Tag List CoinPayments::Api.new.get_tag_list.
-
#get_tx_info(*transaction_ids) ⇒ Object
Get TX Info CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM” CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM”, “CPCK5OLFDULWTYNDW7UQ0LYE2D” # Multiple lookup, don’t recommend as it returns funny & they don’t like more than 25.
-
#get_tx_list(options = {}) ⇒ Object
Get TX List CoinPayments::Api.new.get_tx_list CoinPayments::Api.new.get_tx_list limit: 5 CoinPayments::Api.new.get_tx_list limit: 5, start: 5 CoinPayments::Api.new.get_tx_list newer: (Time.now - 1800).to_i.
-
#get_withdrawal_history ⇒ Object
Get Withdrawal History CoinPayments::Api.new.get_withdrawal_history.
-
#get_withdrawal_info ⇒ Object
Get Withdrawal Info CoinPayments::Api.new.get_withdrawal_info.
- #post(body, openstruct: true) ⇒ Object
-
#update_tag_profile ⇒ Object
Update Tag Profile CoinPayments::Api.new.update_tag_profile.
Instance Method Details
#callback_addresses(options = {}) ⇒ Object
Callback Addresses CoinPayments::Api.new.callback_addresses
100 101 102 103 104 105 106 107 |
# File 'lib/coin_payments/api.rb', line 100 def callback_addresses( = {}) body = { cmd: "get_callback_address", currency: .fetch(:currency, "BTC") } body[:ipn_url] = [:ipn_url] if [:ipn_url] post body end |
#claim_tag ⇒ Object
Claim Tag CoinPayments::Api.new.claim_tag
208 209 210 |
# File 'lib/coin_payments/api.rb', line 208 def claim_tag end |
#conversion_limits ⇒ Object
Conversion Limits CoinPayments::Api.new.conversion_limits
164 165 166 |
# File 'lib/coin_payments/api.rb', line 164 def conversion_limits end |
#convert_coins ⇒ Object
Convert Coins CoinPayments::Api.new.convert_coins
158 159 160 |
# File 'lib/coin_payments/api.rb', line 158 def convert_coins end |
#create_transaction(options = {}) ⇒ Object
Receiving Payments Create Transaction CoinPayments::Api.new.create_transaction amount: 10, currency1: “USD”, currency2: “BTC”, buyer_email: “[email protected]”, buyer_name: “John Doe”
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/coin_payments/api.rb', line 76 def create_transaction( = {}) required_params = %i( amount currency1 currency2 buyer_email) required_params_present = required_params.all? { |e| .keys.include?(e) } raise "Required Argument Error. Must include #{required_params.join(', ')}" unless required_params_present body = { cmd: "create_transaction", amount: [:amount], currency1: [:currency1], currency2: [:currency2], buyer_email: [:buyer_email], } body[:buyer_name] = [:buyer_name] if [:buyer_name] body[:item_name] = [:item_name] if [:item_name] body[:item_number] = [:item_number] if [:item_number] body[:invoice] = [:invoice] if [:invoice] body[:custom] = [:custom] if [:custom] body[:address] = [:address] if [:address] body[:ipn_url] = [:ipn_url] if [:ipn_url] post body end |
#create_transfer ⇒ Object
Withdrawals/Transfers Create Transfer CoinPayments::Api.new.create_transfer
146 147 148 |
# File 'lib/coin_payments/api.rb', line 146 def create_transfer end |
#create_withdrawal ⇒ Object
Create Withdrawal / Mass Withdrawal CoinPayments::Api.new.create_withdrawal
152 153 154 |
# File 'lib/coin_payments/api.rb', line 152 def create_withdrawal end |
#get_basic_account_info ⇒ Object
Get Basic Account Info CoinPayments::Api.new.get_basic_account_info
26 27 28 29 |
# File 'lib/coin_payments/api.rb', line 26 def get_basic_account_info body = {cmd: "get_basic_info"} post body end |
#get_coin_balances(options = {}) ⇒ Object
Get Coin Balances CoinPayments::Api.new.get_coin_balances CoinPayments::Api.new.get_coin_balances all: true
53 54 55 56 57 58 59 |
# File 'lib/coin_payments/api.rb', line 53 def get_coin_balances( = {}) body = { cmd: "balances" } body[:all] = 1 if [:all] post body end |
#get_conversion_info ⇒ Object
Get Conversion Info CoinPayments::Api.new.get_conversion_info
182 183 184 |
# File 'lib/coin_payments/api.rb', line 182 def get_conversion_info end |
#get_deposit_address(currency = "BTC") ⇒ Object
Get Deposit Address CoinPayments::Api.new.get_deposit_address
63 64 65 66 67 68 69 |
# File 'lib/coin_payments/api.rb', line 63 def get_deposit_address(currency = "BTC") body = { cmd: "get_deposit_address", currency: currency } post body end |
#get_exchange_rates(options = {}) ⇒ Object
Get Exchange Rates / Supported Coins CoinPayments::Api.new.get_exchange_rates CoinPayments::Api.new.get_exchange_rates accepted: true CoinPayments::Api.new.get_exchange_rates accepted: true, accepted_only: true
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/coin_payments/api.rb', line 36 def get_exchange_rates( = {}) body = { cmd: "rates" } body[:short] = 1 if [:short] body[:accepted] = 1 if [:accepted] response = post body, openstruct: false if [:accepted_only] response.to_h.delete_if { |_k, v| v[:accepted] == 0 } else response.to_h end end |
#get_profile_information ⇒ Object
PayByName Get Profile Information CoinPayments::Api.new.get_profile_information
190 191 192 |
# File 'lib/coin_payments/api.rb', line 190 def get_profile_information end |
#get_tag_list ⇒ Object
Get Tag List CoinPayments::Api.new.get_tag_list
196 197 198 |
# File 'lib/coin_payments/api.rb', line 196 def get_tag_list end |
#get_tx_info(*transaction_ids) ⇒ Object
Get TX Info CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM” CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM”, “CPCK5OLFDULWTYNDW7UQ0LYE2D” # Multiple lookup, don’t recommend as it returns funny & they don’t like more than 25
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/coin_payments/api.rb', line 112 def get_tx_info(*transaction_ids) cmd = if transaction_ids.size > 1 "get_tx_info_multi" else "get_tx_info" end body = { cmd: cmd, txid: transaction_ids.join('|'), # full: 0 # I don't see any practical use for this } post body, openstruct: cmd != "get_tx_info_multi" end |
#get_tx_list(options = {}) ⇒ Object
Get TX List CoinPayments::Api.new.get_tx_list CoinPayments::Api.new.get_tx_list limit: 5 CoinPayments::Api.new.get_tx_list limit: 5, start: 5 CoinPayments::Api.new.get_tx_list newer: (Time.now - 1800).to_i
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/coin_payments/api.rb', line 131 def get_tx_list( = {}) body = { cmd: "get_tx_ids" } body[:limit] = [[:limit].to_i, 100].min if [:limit] # limit The maximum number of transaction IDs to return from 1-100. (default: 25) body[:start] = [:start] if [:start] # start What transaction # to start from (for iteration/pagination.) (default: 0, starts with your newest transactions.) body[:newer] = [:newer] if [:newer] # newer Return transactions started at the given Unix timestamp or later. (default: 0) body[:all] = [:all] if [:all] # By default we return an array of TX IDs where you are the seller for use with get_tx_info_multi or get_tx_info. If all is set to 1 returns an array with TX IDs and whether you are the seller or buyer for the transaction. post body end |
#get_withdrawal_history ⇒ Object
Get Withdrawal History CoinPayments::Api.new.get_withdrawal_history
170 171 172 |
# File 'lib/coin_payments/api.rb', line 170 def get_withdrawal_history end |
#get_withdrawal_info ⇒ Object
Get Withdrawal Info CoinPayments::Api.new.get_withdrawal_info
176 177 178 |
# File 'lib/coin_payments/api.rb', line 176 def get_withdrawal_info end |
#post(body, openstruct: true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/coin_payments/api.rb', line 8 def post(body, openstruct: true) response = self.class.post(URL_ENDPOINT, body: modify_body(body), timeout: 30, headers: modify_headers(body)) if response["error"] == "ok" if openstruct JSON::parse(response["result"].to_json, object_class: OpenStruct) else response end else OpenStruct.new response end end |
#update_tag_profile ⇒ Object
Update Tag Profile CoinPayments::Api.new.update_tag_profile
202 203 204 |
# File 'lib/coin_payments/api.rb', line 202 def update_tag_profile end |