klaro-client 0.7.0 → 0.8.0

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: 42126059ba59e044d7d25c44aa0a9d86769071ffcea570c564b7e9ddaa0b92c8
4
- data.tar.gz: 0af95727702d75a8a7830b920efcd36b43def5642461b46aed86419b9ca71e16
3
+ metadata.gz: 4ea12d80f3c5b01aa96ff999724aad9f4d597b852f694e60beeaea622fd208bd
4
+ data.tar.gz: '098ce985b929b20fef00b597ccb53739ab03f29070753610411674d8f0f599fd'
5
5
  SHA512:
6
- metadata.gz: a99dbe5bcfba816260d8e68a0174ab48f688b00fa28b98356060fb34ab32e96b97694c402477347b81cb01b56d10fa6f7df0efb2da3d470678fc49ca303ae4f5
7
- data.tar.gz: b360ded9145f755cca8249181ffd65eb5c5ee103b061b70ee439ee9703e79262c2f1cf58ae734487ee7e88b47c08c88cf9f914094eb29454bf6721450e528aa2
6
+ metadata.gz: 01624445eff8d2712316b2a5ce48ba1ed486ad7a674796534f7136c97289aeae4299bc59f5e75fc7ea2232f351430f403491881e099bb857872e586816ab9fd7
7
+ data.tar.gz: 6514a94419c89d1783b3a8a2a5b7002833b240728cfdaa09f114eb534db21284d33b6e1b522abe551028cb680803f957c0b32007fefb78f0328b92984c2c4a26
@@ -10,6 +10,7 @@ module Klaro
10
10
  @token = nil
11
11
  @subdomain = nil
12
12
  @workspace = nil
13
+ @caching_options = nil
13
14
  end
14
15
 
15
16
  def authenticated?
@@ -26,6 +27,11 @@ module Klaro
26
27
  self
27
28
  end
28
29
 
30
+ def with_cache(caching_options)
31
+ @caching_options = caching_options
32
+ self
33
+ end
34
+
29
35
  def authenticate(user, password, workspace = nil)
30
36
  @workspace = workspace
31
37
  @token = get_token(
@@ -40,12 +46,29 @@ module Klaro
40
46
  def get(endpoint, raw = false)
41
47
  url = "#{base_url}#{endpoint}"
42
48
  info("GET `#{url}`")
43
- response = http.get(url, ssl_context: http_ctx)
44
- raise Error::NoSuchBoardFound if response.status >= 300 || response.status <200
45
-
49
+ response = get_in_cache(url) do
50
+ res = http.get(url, ssl_context: http_ctx)
51
+ raise Error::NoSuchBoardFound unless res.status == 200
52
+ res.to_s
53
+ end
46
54
  raw ? response.to_s : JSON.parse(response.to_s)
47
55
  end
48
56
 
57
+ def get_in_cache(url, &bl)
58
+ return bl.call unless @caching_options
59
+
60
+ sha = Digest::SHA1.hexdigest(url)
61
+ file = @caching_options[:path]/sha
62
+ if file.file?
63
+ file.read
64
+ else
65
+ str = bl.call
66
+ file.parent.mkdir_p
67
+ file.write(str)
68
+ str
69
+ end
70
+ end
71
+
49
72
  def post(endpoint, body)
50
73
  url = "#{base_url}#{endpoint}"
51
74
  info("POST `#{url}`")
@@ -53,6 +76,7 @@ module Klaro
53
76
  end
54
77
 
55
78
  private
79
+
56
80
  def get_token(response)
57
81
  raise Error::AuthenticationFailed if response.status >= 300 || response.status <200
58
82
 
@@ -74,8 +98,8 @@ module Klaro
74
98
  OpenSSL::SSL::SSLContext.new
75
99
  end
76
100
 
77
- def http
78
- Http.headers(http_headers)
101
+ def http(headers = {})
102
+ Http.headers(http_headers.merge(headers))
79
103
  end
80
104
 
81
105
  def http_headers
@@ -2,7 +2,7 @@ module Klaro
2
2
  class Client
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 7
5
+ MINOR = 8
6
6
  TINY = 0
7
7
  end
8
8
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
data/lib/klaro/client.rb CHANGED
@@ -2,6 +2,7 @@ require 'http'
2
2
  require 'path'
3
3
  require 'commonmarker'
4
4
  require 'i18n'
5
+ require 'digest'
5
6
 
6
7
  module Klaro
7
8
  class Client
@@ -11,6 +12,11 @@ module Klaro
11
12
  @request = RequestHandler.new(base_url)
12
13
  end
13
14
 
15
+ def with_caching(options)
16
+ @request = request.with_cache(options)
17
+ self
18
+ end
19
+
14
20
  def absolute_url(url)
15
21
  request.base_url + url
16
22
  end
@@ -43,6 +49,13 @@ module Klaro
43
49
  Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"), self)
44
50
  end
45
51
 
52
+ def board_stories_full(location_or_id)
53
+ hs = { 'Accept': 'application/vnd+klaro.stories.full+json' }
54
+ Stories.dress(
55
+ request.get("/api/boards/#{location_or_id}/stories/", false, hs),
56
+ self)
57
+ end
58
+
46
59
  def story(id_or_identifier)
47
60
  Story.dress(request.get("/api/stories/#{id_or_identifier}"), self)
48
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaro-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enspirit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-08 00:00:00.000000000 Z
11
+ date: 2024-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv