add lightning node support (pending tests)
This commit is contained in:
parent
c293181b36
commit
6622789819
|
@ -8,6 +8,7 @@ module BtcPay
|
|||
class Base < Client::Service
|
||||
require_relative './api_keys'
|
||||
require_relative './health'
|
||||
require_relative './lightning_node'
|
||||
require_relative './users'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module BtcPay
|
||||
module Client
|
||||
module Api
|
||||
class LightningNode < Base
|
||||
PATH = '/server/lightning/'
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Lightning-(Internal-Node)
|
||||
def info(crypto_code, **opts)
|
||||
client.get(path(crypto_code, 'info'), options: opts)
|
||||
end
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_ConnectToNode
|
||||
def connect(crypto_code, payload, **opts)
|
||||
client.post(path(crypto_code, 'connect'), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetChannels
|
||||
def channels(crypto_code, **opts)
|
||||
client.get(path(crypto_code, 'channels'), options: opts)
|
||||
end
|
||||
|
||||
alias get_channels channels
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_OpenChannel
|
||||
def open(crypto_code, payload, **opts)
|
||||
client.post(path(crypto_code, 'channels'), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
alias open_channels open
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetDepositAddress
|
||||
def deposit_address(crypto_code, payload, **opts)
|
||||
client.post(path(crypto_code, 'address'), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
alias address deposit_address
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetInvoice
|
||||
def invoice(crypto_code, invoice_id, **opts)
|
||||
client.get(path(crypto_code, 'invoices', invoice_id), options: opts)
|
||||
end
|
||||
|
||||
alias get_invoice invoice
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_PayInvoice
|
||||
def pay(crypto_code, payload, **opts)
|
||||
client.post(path(crypto_code, 'invoices', 'pay'), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
alias pay_invoice pay
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_CreateInvoice
|
||||
def create_invoice(crypto_code, payload, **opts)
|
||||
client.post(path(crypto_code, 'invoices'), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -75,6 +75,10 @@ module BtcPay
|
|||
@health ||= Api::Health.new(client: self)
|
||||
end
|
||||
|
||||
def lightning
|
||||
@lightning ||= OpenStruct.new(node: Api::LightningNode.new(client: self))
|
||||
end
|
||||
|
||||
def users
|
||||
@users ||= Api::Users.new(client: self)
|
||||
end
|
||||
|
|
|
@ -10,9 +10,7 @@ module BtcPay
|
|||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
nil
|
||||
end
|
||||
def base_path; end
|
||||
|
||||
class Authorize
|
||||
PATH = '/api-keys/authorize'
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe BtcPay::Client::Api::LightningNode, :vcr do
|
||||
let(:crypto_code) { 'TODO' }
|
||||
let(:client) { build(:client) }
|
||||
subject { described_class.new(client: client) }
|
||||
|
||||
before { pending('need to set up lightning network') }
|
||||
|
||||
describe 'GET #info' do
|
||||
let(:response) { subject.info(crypto_code) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #connect' do
|
||||
let(:payload) { 'TODO' }
|
||||
let(:response) { subject.connect(crypto_code, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'GET #channels' do
|
||||
let(:response) { subject.channels(crypto_code) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #open' do
|
||||
let(:payload) { 'TODO' }
|
||||
let(:response) { subject.open(crypto_code, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #deposit_address' do
|
||||
let(:payload) { 'TODO' }
|
||||
let(:response) { subject.deposit_address(crypto_code, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'GET #invoice' do
|
||||
let(:invoice_id) { 'TODO' }
|
||||
let(:response) { subject.invoice(crypto_code, invoice_id) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #pay' do
|
||||
let(:payload) { 'TODO' }
|
||||
let(:response) { subject.pay(crypto_code, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #create_invoice' do
|
||||
let(:payload) { 'TODO' }
|
||||
let(:response) { subject.create_invoice(crypto_code, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
end
|
|
@ -7,6 +7,10 @@ RSpec.describe BtcPay::Client::Base do
|
|||
let(:subject) { described_class.new(config: config) }
|
||||
|
||||
describe 'resources' do
|
||||
it { expect(subject.api_keys).to be_a(BtcPay::Client::Api::ApiKeys) }
|
||||
it { expect(subject.api_keys_helper).to be_a(BtcPay::Client::Helpers::ApiKeys) }
|
||||
it { expect(subject.health).to be_a(BtcPay::Client::Api::Health) }
|
||||
it { expect(subject.lightning.node).to be_a(BtcPay::Client::Api::LightningNode) }
|
||||
it { expect(subject.users).to be_a(BtcPay::Client::Api::Users) }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue