faraday_ln_paywall 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/example.rb +5 -3
- data/lib/faraday_ln_paywall/middleware.rb +19 -4
- data/lib/faraday_ln_paywall/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4b36c056ecb79191ceb42493b4672204e987df6
|
4
|
+
data.tar.gz: 239fcea1e9093d674879cad9ff9280e41ed21431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6d7c79810f155208ca721122449d9a2be992ecba5297036a4c5be26c162f2044449472aec862abf567eaed063031ade574946a14e8606c41bd3549daf968f1
|
7
|
+
data.tar.gz: a83bbe7be6d258fcd0931b55afb3383ab99056b32a123b9433a86461020360c66e0cdc073d2eda74104a704222997eb90abbd461ab428de25180155ae42e629f
|
data/example.rb
CHANGED
@@ -2,11 +2,13 @@ require "bundler/setup"
|
|
2
2
|
require "faraday_ln_paywall"
|
3
3
|
require "faraday"
|
4
4
|
|
5
|
-
conn = Faraday.new(:url => 'https://
|
5
|
+
conn = Faraday.new(:url => 'https://lightning-2pdf.herokuapp.com/') do |faraday|
|
6
|
+
#conn = Faraday.new(:url => 'https://fourohtwo.herokuapp.com') do |faraday|
|
6
7
|
faraday.use FaradayLnPaywall::Middleware, {
|
7
|
-
max_amount:
|
8
|
+
max_amount: 100,
|
8
9
|
timeout: 300
|
9
10
|
}
|
10
11
|
faraday.adapter Faraday.default_adapter
|
11
12
|
end
|
12
|
-
puts conn.
|
13
|
+
puts conn.post("/html", "# hallo").body
|
14
|
+
# puts conn.get("/402").body
|
@@ -26,7 +26,7 @@ module FaradayLnPaywall
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def validate_invoice!(invoice)
|
29
|
-
if !@options[:max_amount].nil? && @options[:max_amount] < invoice
|
29
|
+
if !@options[:max_amount].nil? && @options[:max_amount] < invoice_amount_in_satoshi(invoice)
|
30
30
|
raise PaymentError, "invoice amount greater than expected maximum of #{@options[:max_amount]}"
|
31
31
|
end
|
32
32
|
if !invoice.expiry.nil? && Time.now.to_i > invoice.timestamp + invoice.expiry.to_i
|
@@ -47,20 +47,35 @@ module FaradayLnPaywall
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def call(request_env)
|
50
|
-
|
50
|
+
original_call = request_env.dup
|
51
|
+
response = @app.call(request_env)
|
52
|
+
response.on_complete do |response_env|
|
51
53
|
if payment_requested?(response_env)
|
52
54
|
payment = pay(response_env)
|
53
55
|
if payment && payment.payment_error == ""
|
54
56
|
preimage = payment.payment_preimage.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
|
55
|
-
|
56
|
-
@app.call(
|
57
|
+
original_call[:request_headers].merge!('X-Preimage' => preimage)
|
58
|
+
response = @app.call(original_call)
|
57
59
|
else
|
58
60
|
raise PaymentError, payment.payment_error
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
64
|
+
response
|
62
65
|
end
|
63
66
|
|
67
|
+
# todo move to Lightning/invoice gem
|
68
|
+
def invoice_amount_in_satoshi(invoice)
|
69
|
+
return if invoice.amount.nil?
|
70
|
+
multi = {
|
71
|
+
'm' => 0.001,
|
72
|
+
'u' => 0.000001,
|
73
|
+
'n' => 0.000000001,
|
74
|
+
'p' => 0.000000000001
|
75
|
+
}[invoice.multiplier]
|
76
|
+
|
77
|
+
(invoice.amount * multi * 100000000).to_i # amount in bitcoin * 100000000
|
78
|
+
end
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_ln_paywall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bumi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|