Class: Cryptoprocessing::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, Accounts, Addresses, Callbacks, CoinbaseWallet, Trackers, Transactions, Configurable, Connection
Defined in:
lib/cryptoprocessing/client.rb,
lib/cryptoprocessing/client/accounts.rb,
lib/cryptoprocessing/client/trackers.rb,
lib/cryptoprocessing/client/addresses.rb,
lib/cryptoprocessing/client/callbacks.rb,
lib/cryptoprocessing/client/transactions.rb,
lib/cryptoprocessing/client/coinbase_wallet.rb

Overview

Cryptoprocessing API client masks default currency with BTC. But default currency can be simply overridden with blockchain_type property.

Defined Under Namespace

Modules: Accounts, Addresses, Callbacks, CoinbaseWallet, Trackers, Transactions

Constant Summary

Constants included from Transactions

Transactions::TRANSACTION_FEE_FASTEST, Transactions::TRANSACTION_FEE_HALF_HOUR, Transactions::TRANSACTION_FEE_HOUR, Transactions::TRANSACTION_SEND_TYPE, Transactions::TRANSACTION_SEND_TYPE_RAW

Instance Attribute Summary collapse

Attributes included from Configurable

#access_token, #api_endpoint, #api_namespace, #blockchain_type, #email, #password, #user_agent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CoinbaseWallet

#accounts, #address_transactions, #primary_account

Methods included from Transactions

#create_transaction, #send_raw_transaction, #transactions, #transactions_by_address

Methods included from Trackers

#create_tracker, #trackers

Methods included from Addresses

#address, #addresses, #create_address

Methods included from Callbacks

#callbacks, #create_callback

Methods included from Accounts

#account, #create_account

Methods included from Connection

#agent, #auth_headers, #delete, #endpoint, #get, #post, #put, #request, #reset_agent

Methods included from Configurable

#configure, keys, #netrc?, #reset!, #same_options?

Methods included from Authentication

#login, #login_from_netrc, #register, #token_authenticated?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



29
30
31
32
33
34
35
36
# File 'lib/cryptoprocessing/client.rb', line 29

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  Cryptoprocessing::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Cryptoprocessing.instance_variable_get(:"@#{key}"))
  end

  # login_from_netrc unless user_authenticated? || application_authenticated?
end

Instance Attribute Details

#loggerLogger

Returns The logger.

Returns:

  • (Logger)

    The logger.



56
57
58
# File 'lib/cryptoprocessing/client.rb', line 56

def self.logger
  @logger ||= rails_logger || default_logger
end

Class Method Details

.default_loggerLogger

Create and configure a logger

Returns:

  • (Logger)


62
63
64
65
66
# File 'lib/cryptoprocessing/client.rb', line 62

def self.default_logger
  logger = Logger.new($stdout)
  logger.level = Logger::WARN
  logger
end

.loggerLogger

Returns The logger.

Returns:

  • (Logger)

    The logger.



56
57
58
# File 'lib/cryptoprocessing/client.rb', line 56

def self.logger
  @logger ||= rails_logger || default_logger
end

.rails_loggerLogger

Check to see if client is being used in a Rails environment and get the logger if present. Setting the ENV variable 'GOOGLE_API_USE_RAILS_LOGGER' to false will force the client to use its own logger.

Returns:

  • (Logger)


73
74
75
76
77
78
79
80
81
82
# File 'lib/cryptoprocessing/client.rb', line 73

def self.rails_logger
  if 'true' == ENV.fetch('CRYPTOPROCESSING_USE_RAILS_LOGGER', 'true') &&
      defined?(::Rails) &&
      ::Rails.respond_to?(:logger) &&
      !::Rails.logger.nil?
    ::Rails.logger
  else
    nil
  end
end

Instance Method Details

#access_token=(value) ⇒ Object

Set access token for authentication

Parameters:

  • value (String)

    40 character Cryptoprocessing access token



103
104
105
106
# File 'lib/cryptoprocessing/client.rb', line 103

def access_token=(value)
  reset_agent
  @access_token = value
end

#email=(value) ⇒ Object

Set username for authentication

Parameters:

  • value (String)

    Cryptoprocessing username



87
88
89
90
# File 'lib/cryptoprocessing/client.rb', line 87

def email=(value)
  reset_agent
  @email = value
end

#inspectString

Text representation of the client, masking tokens and passwords

Returns:

  • (String)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cryptoprocessing/client.rb', line 41

def inspect
  inspected = super

  # mask password
  inspected = inspected.gsub! @password, "*******" if @password
  # Only show last 4 of token, secret
  if @access_token
    inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
  end

  inspected
end

#password=(value) ⇒ Object

Set password for authentication

Parameters:

  • value (String)

    Cryptoprocessing password



95
96
97
98
# File 'lib/cryptoprocessing/client.rb', line 95

def password=(value)
  reset_agent
  @password = value
end