glib-web 4.34.1 → 4.34.2
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/lib/glib/json_crawler/http.rb +12 -11
- data/lib/glib/json_crawler/router.rb +21 -21
- data/lib/glib/test_helpers.rb +24 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb968a7bdcca5cd93fba46a281cbd210464b6bd5be04372769f7b5952e7cfcf8
|
4
|
+
data.tar.gz: 63a29dfa8bcf152baaf619811c303955a2e092d872633fc62ed7e931cfecd8b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c433305962fc28761eea800c4cf6d278bbcb73dd3a644fd041d651519005cd1febd6b099e5d9e08d64c35cc1fe36fbe83f0c4477cb1785f937000203e5a258
|
7
|
+
data.tar.gz: 6f75947877922db21c797a56dfcbc665baed3bc6e028a0a696e58b5d9d56e52e4de05faa8ce2432ce558b6e00a5134e9c38f8244a0c8f49271920709da8fa8f2
|
@@ -11,33 +11,34 @@ module Glib
|
|
11
11
|
403, ## FORBIDDEN Should be used for logged-in but not allowed to access
|
12
12
|
].flatten
|
13
13
|
|
14
|
-
def initialize(context, user, router)
|
14
|
+
def initialize(context, user, router, inspect_result: true)
|
15
15
|
@context = context
|
16
16
|
@history = []
|
17
17
|
@content_history = []
|
18
18
|
@response_times = []
|
19
19
|
@user = user
|
20
20
|
@router = router
|
21
|
+
@inspect_result = inspect_result
|
21
22
|
end
|
22
23
|
|
23
|
-
def get(url, action, params = {}
|
24
|
-
fetch(:get, url, action, params, inspect_result)
|
24
|
+
def get(url, action, params = {})
|
25
|
+
fetch(:get, url, action, params, @inspect_result)
|
25
26
|
end
|
26
27
|
|
27
|
-
def post(url, action, params
|
28
|
-
fetch(:post, url, action, params)
|
28
|
+
def post(url, action, params)
|
29
|
+
fetch(:post, url, action, params, @inspect_result)
|
29
30
|
end
|
30
31
|
|
31
|
-
def patch(url, action, params
|
32
|
-
fetch(:patch, url, action, params)
|
32
|
+
def patch(url, action, params)
|
33
|
+
fetch(:patch, url, action, params, @inspect_result)
|
33
34
|
end
|
34
35
|
|
35
|
-
def put(url, action, params
|
36
|
-
fetch(:put, url, action, params)
|
36
|
+
def put(url, action, params)
|
37
|
+
fetch(:put, url, action, params, @inspect_result)
|
37
38
|
end
|
38
39
|
|
39
|
-
def delete(url, action, params = {}
|
40
|
-
fetch(:delete, url, action, {})
|
40
|
+
def delete(url, action, params = {})
|
41
|
+
fetch(:delete, url, action, {}, @inspect_result)
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
@@ -137,22 +137,22 @@ module Glib
|
|
137
137
|
end
|
138
138
|
|
139
139
|
# deprecated
|
140
|
-
def follow(http, target_routers)
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
140
|
+
# def follow(http, target_routers)
|
141
|
+
# if !target_routers.is_a?(Array)
|
142
|
+
# target_routers = [target_routers]
|
143
|
+
# end
|
144
|
+
|
145
|
+
# target_actions = Set.new
|
146
|
+
# target_routers.each do |router|
|
147
|
+
# target_actions += router.read_only_actions
|
148
|
+
# end
|
149
|
+
|
150
|
+
# @depth += 1
|
151
|
+
# target_actions.each do |crawler_action|
|
152
|
+
# action, url = crawler_action
|
153
|
+
# http.get(url, action, {})
|
154
|
+
# end
|
155
|
+
# end
|
156
156
|
|
157
157
|
def follow_v2(http, crawler_actions)
|
158
158
|
@depth += 1
|
@@ -164,15 +164,15 @@ module Glib
|
|
164
164
|
|
165
165
|
case action.to_s.downcase
|
166
166
|
when 'http/post-v1', 'forms/post'
|
167
|
-
http.post(url, action, params
|
167
|
+
http.post(url, action, params)
|
168
168
|
when 'http/patch-v1', 'forms/patch'
|
169
|
-
http.patch(url, action, params
|
169
|
+
http.patch(url, action, params)
|
170
170
|
when 'http/put-v1', 'forms/put'
|
171
|
-
http.put(url, action, params
|
171
|
+
http.put(url, action, params)
|
172
172
|
when 'http/delete-v1'
|
173
|
-
http.delete(url, action, params
|
173
|
+
http.delete(url, action, params)
|
174
174
|
else
|
175
|
-
http.get(url, action, params
|
175
|
+
http.get(url, action, params)
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
data/lib/glib/test_helpers.rb
CHANGED
@@ -7,10 +7,10 @@ module Glib
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def define_crawler_test(user, crawled_at, &on_after_crawl)
|
10
|
+
def define_crawler_test(user, crawled_at, dump_path:, &on_after_crawl)
|
11
11
|
test "crawl api for #{user[:email]} #{user[:device]} #{user[:version] || 'current'}" do
|
12
12
|
Timecop.freeze(crawled_at || user[:crawled_at]) do
|
13
|
-
router = crawl_json_pages(user)
|
13
|
+
router = crawl_json_pages(user, dump_actions: dump_path.present?, dump_path: dump_path)
|
14
14
|
on_after_crawl&.call(router)
|
15
15
|
end
|
16
16
|
|
@@ -36,8 +36,8 @@ module Glib
|
|
36
36
|
assert_equal JSON.parse(expected), JSON.parse(result), "Result mismatch! #{__git_is_available? ? `git diff #{__controller_log_dir}/#{__controller_log_file}` : ''}"
|
37
37
|
end
|
38
38
|
|
39
|
-
def crawl_json_pages(user,
|
40
|
-
__execute_crawler(user,
|
39
|
+
def crawl_json_pages(user, log_file: nil, dump_actions: false, dump_path: nil, &block)
|
40
|
+
__execute_crawler(user, inspect_http: true) do |router, http|
|
41
41
|
path = user[:path] ? "#{user[:path]}?format=json" : '/users/me?format=json&redirect=default'
|
42
42
|
router.host = HOST
|
43
43
|
router.step(
|
@@ -53,16 +53,23 @@ module Glib
|
|
53
53
|
action, url, params = row
|
54
54
|
[action, url, JSON.generate(params)].to_csv
|
55
55
|
end.join
|
56
|
-
|
57
|
-
filepath =
|
56
|
+
|
57
|
+
filepath = crawler_output_file(user, file_dir: dump_path)
|
58
58
|
File.write(filepath, csv_string)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
63
|
+
def crawler_output_file(user, file_dir: nil)
|
64
|
+
filename = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].csv"
|
65
|
+
File.join(file_dir || __crawler_log_dir, filename)
|
66
|
+
end
|
67
|
+
|
68
|
+
def retrace_json_pages(user, past_actions:)
|
69
|
+
__execute_crawler(user, inspect_http: false) do |router, http|
|
70
|
+
# router.follow(http, guiding_routers)
|
71
|
+
# router.follow_v2(Glib::JsonCrawler::Http.new(self, user, router), actions)
|
72
|
+
router.follow_v2(http, past_actions)
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
@@ -76,25 +83,23 @@ module Glib
|
|
76
83
|
end
|
77
84
|
|
78
85
|
private
|
79
|
-
def __execute_crawler(user,
|
86
|
+
def __execute_crawler(user, inspect_http:, log_file: nil, &block)
|
80
87
|
auth_token = login user
|
81
88
|
user[:token] = auth_token
|
82
89
|
|
83
90
|
router = Glib::JsonCrawler::Router.new
|
84
|
-
http = Glib::JsonCrawler::Http.new(self, user, router)
|
91
|
+
http = Glib::JsonCrawler::Http.new(self, user, router, inspect_result: inspect_http)
|
85
92
|
block.call(router, http)
|
86
93
|
|
87
94
|
logout
|
88
95
|
|
89
|
-
if
|
90
|
-
log_file = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].txt" if log_file.nil?
|
96
|
+
log_file = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].txt" if log_file.nil?
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
+
file_path = File.join(__crawler_log_dir, log_file)
|
99
|
+
expected = File.exist?(file_path) ? File.read(file_path) : ''
|
100
|
+
result = router.logger
|
101
|
+
File.write(file_path, result)
|
102
|
+
assert_equal expected, result, "Result mismatch! #{log_file.sub(/\.txt$/, '')}"
|
98
103
|
|
99
104
|
router
|
100
105
|
end
|