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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a897a2657114bf12b52da917ad8857e4b7e1070bc99eefe7e4cc49c519508bdb
4
- data.tar.gz: 2bf662a93d9a308f5eec89dc7d3562b4ddc7462886f0ec0a239bd64dd81c75d0
3
+ metadata.gz: fb968a7bdcca5cd93fba46a281cbd210464b6bd5be04372769f7b5952e7cfcf8
4
+ data.tar.gz: 63a29dfa8bcf152baaf619811c303955a2e092d872633fc62ed7e931cfecd8b9
5
5
  SHA512:
6
- metadata.gz: c8a8915e195ed0e6e5f9e39789fdb886887cdb264e7fbc873f3833906be02b44308ca9a7488a9ad30170720ab0e9761ef46dbdf7e230edaac81f3da764c5fe63
7
- data.tar.gz: 4e8d8a377ccf28259fcde1ce4d265cddf4d67096a391e96aabecd48a77742d1ace91775b322614879a355fb1b2d0728144461eb3ff4677983a4013d4bd20bf76
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 = {}, inspect_result = true)
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, inspect_result = true)
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, inspect_result = true)
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, inspect_result = true)
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 = {}, inspect_result = true)
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
- 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, {}, false)
154
- end
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, false)
167
+ http.post(url, action, params)
168
168
  when 'http/patch-v1', 'forms/patch'
169
- http.patch(url, action, params, false)
169
+ http.patch(url, action, params)
170
170
  when 'http/put-v1', 'forms/put'
171
- http.put(url, action, params, false)
171
+ http.put(url, action, params)
172
172
  when 'http/delete-v1'
173
- http.delete(url, action, params, false)
173
+ http.delete(url, action, params)
174
174
  else
175
- http.get(url, action, params, false)
175
+ http.get(url, action, params)
176
176
  end
177
177
  end
178
178
  end
@@ -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, check_result: true, log_file: nil, dump_actions: false, &block)
40
- __execute_crawler(user, check_result: true) do |router, http|
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
- filename = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].csv"
57
- filepath = File.join(__crawler_log_dir, filename)
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 retrace_json_pages(user, guiding_routers:)
64
- __execute_crawler(user, check_result: true) do |router, http|
65
- router.follow(http, guiding_routers)
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, check_result: true, log_file: nil, &block)
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 check_result
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
- file_path = File.join(__crawler_log_dir, log_file)
93
- expected = File.exist?(file_path) ? File.read(file_path) : ''
94
- result = router.logger
95
- File.write(file_path, result)
96
- assert_equal expected, result, "Result mismatch! #{log_file.sub(/\.txt$/, '')}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.34.1
4
+ version: 4.34.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''