leanweb 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/contrib/lib/hawese.rb +43 -13
- data/contrib/lib/rack/session/json_file.rb +1 -1
- data/lib/leanweb/version.rb +1 -1
- data/lib/leanweb.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b3993343fb571b11c2bdf16e2874103e79b5994dee7218c94fd7175a5458a57
|
4
|
+
data.tar.gz: c9cdaff0f1ae2cb6af897b644f3ffa39829bd590c5c2f6aecf81329485f96495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5abde684aa9f4f542c0256a3af664298797c424541db46540d77862098c7e8509cb00ff81e7d1a7d4032025727e4cb2610d3ee75bcc51be0cd7b10f54c704f5
|
7
|
+
data.tar.gz: c4a154a07332e20bcd5f60d830516a6a937f3e507cd010e9df5266c51b14fa9740d32cc03594b2b362f215780aad68f833f1939c7eba63df201fb6c616de5d6f
|
data/contrib/lib/hawese.rb
CHANGED
@@ -10,7 +10,6 @@
|
|
10
10
|
require 'json'
|
11
11
|
require 'net/http'
|
12
12
|
require 'openssl'
|
13
|
-
require 'tilt'
|
14
13
|
require 'uri'
|
15
14
|
|
16
15
|
# Hawese client.
|
@@ -22,6 +21,13 @@ require 'uri'
|
|
22
21
|
# - HAWESE_ORIGIN
|
23
22
|
# - HAWESE_AUTH_TOKEN
|
24
23
|
class Hawese
|
24
|
+
# Error to display when a response is unexpected.
|
25
|
+
class UnexpectedResponseError < RuntimeError
|
26
|
+
def initialize(message = 'Unexpected response')
|
27
|
+
super(message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
class << self
|
26
32
|
ENDPOINT = ENV.fetch('HAWESE_ENDPOINT')
|
27
33
|
RETURN_URL = ENV.fetch('HAWESE_RETURN_URL') do
|
@@ -44,15 +50,31 @@ class Hawese
|
|
44
50
|
JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
|
45
51
|
end
|
46
52
|
|
47
|
-
def
|
48
|
-
uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}
|
49
|
-
uri.query = URI.encode_www_form(return_url: RETURN_URL)
|
53
|
+
def do_action(gateway, schema, fields)
|
54
|
+
uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/#{schema}")
|
55
|
+
uri.query = URI.encode_www_form(return_url: RETURN_URL) if
|
56
|
+
schema == 'purchase'
|
50
57
|
response = Net::HTTP.post(
|
51
58
|
uri,
|
52
59
|
fields.to_json,
|
53
|
-
|
60
|
+
{
|
61
|
+
'Authorization' => "Bearer #{ENV.fetch('HAWESE_AUTH_TOKEN')}",
|
62
|
+
'Content-Type' => 'application/json'
|
63
|
+
}
|
54
64
|
)
|
55
|
-
|
65
|
+
process_response(response)
|
66
|
+
end
|
67
|
+
|
68
|
+
def purchase(gateway, fields)
|
69
|
+
do_action(gateway, 'purchase', fields)
|
70
|
+
end
|
71
|
+
|
72
|
+
def link(gateway, fields)
|
73
|
+
do_action(gateway, 'link', fields)
|
74
|
+
end
|
75
|
+
|
76
|
+
def charge(gateway, fields)
|
77
|
+
do_action(gateway, 'charge', fields)
|
56
78
|
end
|
57
79
|
|
58
80
|
def receipt(gateway, payment_uuid, fields = {})
|
@@ -66,7 +88,7 @@ class Hawese
|
|
66
88
|
})
|
67
89
|
req.body = fields.to_json
|
68
90
|
response = http.request(req)
|
69
|
-
|
91
|
+
process_response(response)
|
70
92
|
end
|
71
93
|
end
|
72
94
|
|
@@ -98,14 +120,22 @@ class Hawese
|
|
98
120
|
fields
|
99
121
|
end
|
100
122
|
|
101
|
-
def
|
123
|
+
def process_response(response)
|
102
124
|
response_body = JSON.parse(response.body, symbolize_names: true)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
125
|
+
unless response.code.to_i.between?(200, 299)
|
126
|
+
raise(
|
127
|
+
UnexpectedResponseError,
|
128
|
+
if response_body.instance_of?(String)
|
129
|
+
response_body
|
130
|
+
else
|
131
|
+
response_body.[](:error)&.[](:message)
|
132
|
+
end
|
133
|
+
)
|
108
134
|
end
|
135
|
+
|
136
|
+
response_body
|
137
|
+
rescue JSON::ParserError
|
138
|
+
raise(response.body)
|
109
139
|
end
|
110
140
|
end
|
111
141
|
end
|
data/lib/leanweb/version.rb
CHANGED
data/lib/leanweb.rb
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
|
10
10
|
# LeanWeb is a minimal hybrid static / dynamic web framework.
|
11
11
|
module LeanWeb
|
12
|
-
require_relative 'leanweb/version'
|
13
12
|
|
14
13
|
ROOT_PATH = ENV.fetch('LEANWEB_ROOT_PATH', Dir.pwd)
|
15
14
|
CONTROLLER_PATH = "#{ROOT_PATH}/src/controllers"
|
@@ -31,6 +30,7 @@ module LeanWeb
|
|
31
30
|
autoload :Route, 'leanweb/route.rb'
|
32
31
|
autoload :Controller, 'leanweb/controller.rb'
|
33
32
|
autoload :App, 'leanweb/app.rb'
|
34
|
-
end
|
35
33
|
|
36
|
-
require_relative 'leanweb/
|
34
|
+
require_relative 'leanweb/version'
|
35
|
+
require_relative 'leanweb/helpers'
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leanweb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Freeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06
|
11
|
+
date: 2023-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|