Class: BtcPay::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/btcpay/client/base.rb

Constant Summary collapse

API_PATH =
'/api/v1'
DEFAULT_TIMEOUT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, logger: Logger.new(STDOUT), timeout: DEFAULT_TIMEOUT, **_kwargs) ⇒ Base

Returns a new instance of Base.

Parameters:

  • config (BtcPay::Client::Config)
  • logger (Logger) (defaults to: Logger.new(STDOUT))
  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    Defaults to DEFAULT_TIMEOUT



28
29
30
31
32
# File 'lib/btcpay/client/base.rb', line 28

def initialize(config:, logger: Logger.new(STDOUT), timeout: DEFAULT_TIMEOUT, **_kwargs)
  @config = config
  @logger = logger
  @timeout = timeout
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



23
24
25
# File 'lib/btcpay/client/base.rb', line 23

def logger
  @logger
end

Instance Method Details

#api_keysObject



78
79
80
# File 'lib/btcpay/client/base.rb', line 78

def api_keys
  @api_keys ||= Api::ApiKeys.new(client: self)
end

#api_keys_helperObject



82
83
84
# File 'lib/btcpay/client/base.rb', line 82

def api_keys_helper
  @api_keys_helper ||= Helpers::ApiKeys.new(client: self)
end

#delete(uri, options: {}, headers: {}) ⇒ Result

DELETE request

Parameters:

  • uri (String)
  • options (Hash) (defaults to: {})
  • headers (Hash) (defaults to: {})

Returns:



74
75
76
# File 'lib/btcpay/client/base.rb', line 74

def delete(uri, options: {}, headers: {})
  request(uri, method: :delete, options: options, headers: headers)
end

#get(uri, options: {}, headers: {}, **kwargs) ⇒ Result

GET request

Parameters:

  • uri (String)
  • options (Hash) (defaults to: {})
  • headers (Hash) (defaults to: {})

Returns:



40
41
42
# File 'lib/btcpay/client/base.rb', line 40

def get(uri, options: {}, headers: {}, **kwargs)
  request(uri, method: :get, options: options, headers: headers, **kwargs)
end

#healthObject



86
87
88
# File 'lib/btcpay/client/base.rb', line 86

def health
  @health ||= Api::Health.new(client: self)
end

#lightningObject



90
91
92
# File 'lib/btcpay/client/base.rb', line 90

def lightning
  @lightning ||= OpenStruct.new(node: Api::LightningNode.new(client: self))
end

#post(uri, payload: {}, options: {}, headers: {}) ⇒ Result

POST request

Parameters:

  • uri (String)
  • payload (Hash) (defaults to: {})
  • options (Hash) (defaults to: {})
  • headers (Hash) (defaults to: {})

Returns:



51
52
53
54
# File 'lib/btcpay/client/base.rb', line 51

def post(uri, payload: {}, options: {}, headers: {})
  data = payload.is_a?(Hash) ? payload.to_json : payload
  request(uri, method: :post, payload: data, options: options, headers: headers)
end

#pull_paymentsObject Also known as: payments



94
95
96
# File 'lib/btcpay/client/base.rb', line 94

def pull_payments
  @pull_payments ||= Api::PullPayments.new(client: self)
end

#put(uri, payload:, options: {}, headers: {}) ⇒ Result

PUT request

Parameters:

  • uri (String)
  • payload (Hash)
  • options (Hash) (defaults to: {})
  • headers (Hash) (defaults to: {})

Returns:



63
64
65
66
# File 'lib/btcpay/client/base.rb', line 63

def put(uri, payload:, options: {}, headers: {})
  data = payload.is_a?(Hash) ? payload.to_json : payload
  request(uri, method: :put, payload: data, options: options, headers: headers)
end

#serverObject



100
101
102
# File 'lib/btcpay/client/base.rb', line 100

def server
  @server ||= Api::Server.new(client: self)
end

#storeObject



104
105
106
# File 'lib/btcpay/client/base.rb', line 104

def store
  @store ||= Api::Store.new(client: self)
end

#usersObject



108
109
110
# File 'lib/btcpay/client/base.rb', line 108

def users
  @users ||= Api::Users.new(client: self)
end