itriagetestrail 1.0.30 → 1.0.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9c2598f1f48638196f167848fe54f68852fb6834a885ea248a6e4c954d052a6
4
- data.tar.gz: fcf15ba7fd2d2475865e9057c60febe4cef4713afb66dfcc1db2aae75a22c60b
3
+ metadata.gz: ddb1242abc0ff09697334bb9ad6e3470cf09ef0e294f5a3b2547a1a6720cb2d3
4
+ data.tar.gz: 99b08bd93f90d1b1f38cc8cee408fdcb301d5d4ff6f25cd3a53ed6792f304a7b
5
5
  SHA512:
6
- metadata.gz: e6385187bc0a55a7b1c4b12a3aa51515b7b19bb9f6b0d283466c6ebffa2436267937c68ab24ba2523732a369fe88105361b9b0b880ccdd94445181a307627cf8
7
- data.tar.gz: 870b45e4257f79456864ad553b7b9576f1d52f235dd13d6ed802a6b0b2d1e290888c0cb22dafafb4411bc254f66f8422982cfc160ad9b849dcb0cffe681386c3
6
+ metadata.gz: 21bbeeda1120f7154bbafd46c01c5215e1ea61d12ee80d4c0e85226d072f030ab57296bfc6b1d329ec979385646b8e7d7e125df86d3f5b6906c6df1252b77cd5
7
+ data.tar.gz: 2613c0fc5457c8d58bed52887dc3d1d4362c5d1540b900f52fb425f541447814345a14d6dc71dab2e8fe212a09ad321d37458a0b3dd9aab944b5fb668309fab8
@@ -45,7 +45,8 @@ module TestRail
45
45
  # (e.g. get_case/1)
46
46
  #
47
47
  def send_get(uri)
48
- _send_request('GET', uri, nil)
48
+ res = read_cache(uri)
49
+ res || _send_request('GET', uri, nil, true)
49
50
  end
50
51
 
51
52
  #
@@ -95,7 +96,7 @@ module TestRail
95
96
  response_code: response.code, error: error)
96
97
  end
97
98
 
98
- def _send_request(method, uri, data)
99
+ def _send_request(method, uri, data, write_cache = false)
99
100
  url = URI.parse(@url + uri)
100
101
  if method == 'POST'
101
102
  request = Net::HTTP::Post.new(url.path + '?' + url.query)
@@ -131,6 +132,10 @@ module TestRail
131
132
 
132
133
  _error_check(response, result)
133
134
 
135
+ if write_cache
136
+ cache_to_file(url, result)
137
+ end
138
+
134
139
  result
135
140
  end
136
141
 
@@ -143,6 +148,39 @@ module TestRail
143
148
  end
144
149
  end
145
150
 
151
+ def cache_to_file(url, content)
152
+ Dir.mkdir('./tmp') unless File.exist?('./tmp')
153
+ filename = sanitize_filename(url)
154
+ file = File.open("./tmp/#{filename}", 'w')
155
+ file.write(content)
156
+ file.close
157
+ end
158
+
159
+ def read_cache(url)
160
+ filename = sanitize_filename(url)
161
+ return unless File.exist?("./tmp/#{filename}")
162
+ file = File.open("./tmp/#{filename}", 'r')
163
+ content = JSON.parse(file.read, :symbolize_names => true)
164
+ file.close
165
+ content
166
+ end
167
+
168
+ def sanitize_filename(filename)
169
+ # Split the name when finding a period which is preceded by some
170
+ # character, and is followed by some character other than a period,
171
+ # if there is no following period that is followed by something
172
+ # other than a period (yeah, confusing, I know)
173
+ fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m
174
+
175
+ # We now have one or two parts (depending on whether we could find
176
+ # a suitable period). For each of these parts, replace any unwanted
177
+ # sequence of characters with an underscore
178
+ fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '_' }
179
+
180
+ # Finally, join the parts with a period and return the result
181
+ return fn.join '.'
182
+ end
183
+
146
184
  class APIError < StandardError
147
185
  end
148
186
  end
@@ -1,3 +1,3 @@
1
1
  module Itriagetestrail
2
- VERSION = '1.0.30'.freeze
2
+ VERSION = '1.0.31'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itriagetestrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.30
4
+ version: 1.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo