Class: BlockstreamSatellite::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/blockstream_satellite/client.rb', line 8

def initialize(options)
  self.lnd_client = options[:lnd_client]
  self.http_client = options[:http_client]
end

Instance Attribute Details

#http_clientObject

Returns the value of attribute http_client.



6
7
8
# File 'lib/blockstream_satellite/client.rb', line 6

def http_client
  @http_client
end

#lnd_clientObject

Returns the value of attribute lnd_client.



6
7
8
# File 'lib/blockstream_satellite/client.rb', line 6

def lnd_client
  @lnd_client
end

Instance Method Details

#get(path, params = nil, &block) ⇒ Object



13
14
15
# File 'lib/blockstream_satellite/client.rb', line 13

def get(path, params = nil, &block)
  request(:get, path, params, &block)
end

#pay(payreq) ⇒ Object



21
22
23
# File 'lib/blockstream_satellite/client.rb', line 21

def pay(payreq)
  self.lnd_client.send_payment_sync(payment_request: payreq)
end

#post(path, body = nil, &block) ⇒ Object



17
18
19
# File 'lib/blockstream_satellite/client.rb', line 17

def post(path, body = nil, &block)
  request(:post, path, nil, body, &block)
end

#request(http_method, path, params = nil, body = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/blockstream_satellite/client.rb', line 25

def request(http_method, path, params=nil, body=nil)
  response = http_client.send(http_method) do |req|
    req.url "/#{path}"
    req.params = params if params
    req.body = body if body
    yield req if block_given?
  end
  Response.new(response)
rescue Faraday::ClientError => error
  return Response.new(error)
end