klaro-client 0.4.2 → 0.5.1
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/klaro/client.rb +13 -5
- data/lib/klaro/client/request_handler.rb +17 -7
- data/lib/klaro/client/resource.rb +21 -4
- data/lib/klaro/client/resource/attachment.rb +15 -0
- data/lib/klaro/client/resource/dimension.rb +1 -1
- data/lib/klaro/client/resource/story.rb +24 -10
- data/lib/klaro/client/support/md_text.rb +17 -6
- data/lib/klaro/client/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aff7c0b9a6e72271bf8ee2cba3f1e26e7756ed2c8bf04281dd7e77543ab2dc69
|
4
|
+
data.tar.gz: e7465eb2440bfb672ea28e3b28a0230574645e340df369f52b5b312689ac5cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe36e8a3f91eefb31cb1024e2f7232f972d781d3127cba53e11c72b8b73638c27ad624506d24e49ae214c8167e981a595104b7b46b3ddb31f65d7570253b14c
|
7
|
+
data.tar.gz: 89383833c59d6923706040ec8641252beee2822bb7d7b1451b3d22497eb16e61562aee044d06ad08af40da24b0890d7b281d398a764b7e489b02712e11d99d01
|
data/lib/klaro/client.rb
CHANGED
@@ -11,32 +11,40 @@ module Klaro
|
|
11
11
|
@request = RequestHandler.new(base_url)
|
12
12
|
end
|
13
13
|
|
14
|
+
def absolute_url(url)
|
15
|
+
request.base_url + url
|
16
|
+
end
|
17
|
+
|
14
18
|
def with_token(*args, &bl)
|
15
19
|
request.with_token(*args, &bl)
|
16
20
|
end
|
17
21
|
|
22
|
+
def with_project(*args, &bl)
|
23
|
+
request.with_project(*args, &bl)
|
24
|
+
end
|
25
|
+
|
18
26
|
def login(*args, &bl)
|
19
27
|
request.authenticate(*args, &bl)
|
20
28
|
end
|
21
29
|
|
22
30
|
def dimension(code_or_id)
|
23
|
-
Dimension.dress(request.get("/api/dimensions/#{code_or_id}"))
|
31
|
+
Dimension.dress(request.get("/api/dimensions/#{code_or_id}"), self)
|
24
32
|
end
|
25
33
|
|
26
34
|
def dimensions
|
27
|
-
Dimensions.dress(request.get('/api/dimensions'))
|
35
|
+
Dimensions.dress(request.get('/api/dimensions'), self)
|
28
36
|
end
|
29
37
|
|
30
38
|
def board(location_or_id)
|
31
|
-
Board.dress(request.get("/api/boards/#{location_or_id}"))
|
39
|
+
Board.dress(request.get("/api/boards/#{location_or_id}"), self)
|
32
40
|
end
|
33
41
|
|
34
42
|
def board_stories(location_or_id)
|
35
|
-
Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"))
|
43
|
+
Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"), self)
|
36
44
|
end
|
37
45
|
|
38
46
|
def story(id_or_identifier)
|
39
|
-
Story.dress(request.get("/api/stories/#{id_or_identifier}"))
|
47
|
+
Story.dress(request.get("/api/stories/#{id_or_identifier}"), self)
|
40
48
|
end
|
41
49
|
|
42
50
|
def upload_image(image_path)
|
@@ -6,8 +6,9 @@ module Klaro
|
|
6
6
|
attr_reader :base_url, :token
|
7
7
|
|
8
8
|
def initialize(url)
|
9
|
-
@base_url = url
|
9
|
+
@base_url = url.gsub(/\/api\/?$/, "")
|
10
10
|
@token = nil
|
11
|
+
@subdomain = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def authenticated?
|
@@ -19,6 +20,11 @@ module Klaro
|
|
19
20
|
self
|
20
21
|
end
|
21
22
|
|
23
|
+
def with_project(subdomain)
|
24
|
+
@subdomain = subdomain
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
22
28
|
def authenticate(user, password)
|
23
29
|
@token = get_token Http
|
24
30
|
.headers({
|
@@ -65,12 +71,16 @@ module Klaro
|
|
65
71
|
end
|
66
72
|
|
67
73
|
def http
|
68
|
-
Http.headers(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
Http.headers(http_headers)
|
75
|
+
end
|
76
|
+
|
77
|
+
def http_headers
|
78
|
+
hs = {
|
79
|
+
"Authorization" => @token,
|
80
|
+
"Content-Type" => "application/json"
|
81
|
+
}
|
82
|
+
hs['Klaro-Project-Subdomain'] = @subdomain if @subdomain
|
83
|
+
hs
|
74
84
|
end
|
75
85
|
|
76
86
|
def info(msg)
|
@@ -2,16 +2,32 @@ module Klaro
|
|
2
2
|
class Client
|
3
3
|
class Resource < OpenStruct
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(data, client)
|
6
|
+
super(data)
|
7
|
+
@client = client
|
7
8
|
end
|
8
9
|
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def symbolize_keys(data)
|
13
|
+
Hash[data.each_pair.map{|k,v|
|
14
|
+
[k.to_sym, v]
|
15
|
+
}]
|
16
|
+
end
|
17
|
+
|
18
|
+
def dress(data, client)
|
19
|
+
new(symbolize_keys(data), client)
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class << self
|
23
|
+
|
9
24
|
end # class Resource
|
10
25
|
class Collection
|
11
26
|
include Enumerable
|
12
27
|
|
13
|
-
def initialize(items)
|
28
|
+
def initialize(items, client)
|
14
29
|
@items = items.map{|i| self.class.dress_one(i) }
|
30
|
+
@client = client
|
15
31
|
end
|
16
32
|
|
17
33
|
def each(*args, &bl)
|
@@ -26,7 +42,7 @@ module Klaro
|
|
26
42
|
end
|
27
43
|
|
28
44
|
def dress_one(item)
|
29
|
-
@item_class.dress(item)
|
45
|
+
@item_class.dress(item, @client)
|
30
46
|
end
|
31
47
|
end
|
32
48
|
|
@@ -34,6 +50,7 @@ module Klaro
|
|
34
50
|
end # class Client
|
35
51
|
end # module Klaro
|
36
52
|
require_relative 'resource/story'
|
53
|
+
require_relative 'resource/attachment'
|
37
54
|
require_relative 'resource/stories'
|
38
55
|
require_relative 'resource/dimension'
|
39
56
|
require_relative 'resource/dimension_value'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Klaro
|
2
|
+
class Client
|
3
|
+
class Attachment < Resource
|
4
|
+
|
5
|
+
def absUrl
|
6
|
+
@client.absolute_url(self.url)
|
7
|
+
end
|
8
|
+
|
9
|
+
def absThumbnailUrl
|
10
|
+
@client.absolute_url(self.thumbnailUrl)
|
11
|
+
end
|
12
|
+
|
13
|
+
end # class Attachment
|
14
|
+
end # class Client
|
15
|
+
end # module Klaro
|
@@ -3,18 +3,32 @@ module Klaro
|
|
3
3
|
class Story < Resource
|
4
4
|
|
5
5
|
def title
|
6
|
-
@title ||= MdText.new(self.description.split("\n").first)
|
6
|
+
@title ||= MdText.new(self.description.split("\n").first, :summary)
|
7
7
|
end
|
8
8
|
|
9
9
|
def summary
|
10
|
-
@summary ||= MdText.new(self.description.split("\n")[1..-1].join("\n"))
|
10
|
+
@summary ||= MdText.new(self.description.split("\n")[1..-1].join("\n"), :summary)
|
11
11
|
end
|
12
12
|
|
13
13
|
def specification
|
14
|
-
@specification ||= MdText.new(super)
|
14
|
+
@specification ||= MdText.new(super, :details)
|
15
15
|
end
|
16
16
|
alias :details :specification
|
17
17
|
|
18
|
+
def linked_cards
|
19
|
+
@linked_cards ||= (self.linked || []).map{|s| Story.dress(s, @client) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def attachments
|
23
|
+
@attachments || super.map{|a| Attachment.dress(a, @client) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def cover_attachment(force = false)
|
27
|
+
got = (self.attachments || []).find{|a| a[:isCover] }
|
28
|
+
got = (self.attachments || []).first if got.nil? and force
|
29
|
+
got
|
30
|
+
end
|
31
|
+
|
18
32
|
def to_url(with_identifier = true)
|
19
33
|
I18n.config.available_locales = [:en, :fr]
|
20
34
|
url = I18n.transliterate(title.to_s)
|
@@ -25,14 +39,14 @@ module Klaro
|
|
25
39
|
|
26
40
|
def download_and_relocate_attachments(root_path, target_folder, client)
|
27
41
|
as = self.attachments.map do |attachment|
|
28
|
-
url = attachment
|
29
|
-
url += "?n=" + URI.encode_www_form_component(attachment
|
42
|
+
url = attachment.url
|
43
|
+
url += "?n=" + URI.encode_www_form_component(attachment.filename) unless url =~ /\?n=/
|
30
44
|
path = handle_image(url, root_path, target_folder, client)
|
31
|
-
attachment.merge(
|
45
|
+
attachment.merge(url => path)
|
32
46
|
end
|
33
|
-
self.class.
|
47
|
+
self.class.dress(self.to_h.merge(
|
34
48
|
attachments: as
|
35
|
-
))
|
49
|
+
), @client)
|
36
50
|
end
|
37
51
|
|
38
52
|
def download_and_relocate_images(root_path, target_folder, client)
|
@@ -42,9 +56,9 @@ module Klaro
|
|
42
56
|
image_relative_path = handle_image(url, root_path, target_folder, client)
|
43
57
|
""
|
44
58
|
end
|
45
|
-
self.class.
|
59
|
+
self.class.dress(self.to_h.merge(
|
46
60
|
specification: spec
|
47
|
-
))
|
61
|
+
), @client)
|
48
62
|
end
|
49
63
|
|
50
64
|
private
|
@@ -2,19 +2,30 @@ module Klaro
|
|
2
2
|
class Client
|
3
3
|
class MdText
|
4
4
|
|
5
|
-
|
5
|
+
SHARED_OPTIONS = {
|
6
6
|
filter_html: true,
|
7
|
-
hard_wrap: true,
|
8
7
|
no_links: false,
|
9
8
|
no_styles: true,
|
10
9
|
safe_links_only: true,
|
11
10
|
with_toc_data: false
|
12
|
-
}
|
11
|
+
}
|
13
12
|
|
14
|
-
|
13
|
+
VARIANTS = {
|
14
|
+
:summary => Redcarpet::Markdown.new(
|
15
|
+
Redcarpet::Render::HTML.new(SHARED_OPTIONS.merge({
|
16
|
+
hard_wrap: true,
|
17
|
+
}))
|
18
|
+
),
|
19
|
+
:details => Redcarpet::Markdown.new(
|
20
|
+
Redcarpet::Render::HTML.new(SHARED_OPTIONS.merge({
|
21
|
+
hard_wrap: false,
|
22
|
+
}))
|
23
|
+
)
|
24
|
+
}
|
15
25
|
|
16
|
-
def initialize(src)
|
26
|
+
def initialize(src, variant)
|
17
27
|
@src = src
|
28
|
+
@renderer = VARIANTS[variant]
|
18
29
|
end
|
19
30
|
|
20
31
|
def to_s
|
@@ -22,7 +33,7 @@ module Klaro
|
|
22
33
|
end
|
23
34
|
|
24
35
|
def to_html
|
25
|
-
|
36
|
+
@renderer.render(to_s).strip.gsub(/<a href/, '<a target="_blank" href')
|
26
37
|
end
|
27
38
|
|
28
39
|
end # class MdText
|
data/lib/klaro/client/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enspirit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/klaro/client/errors.rb
|
128
128
|
- lib/klaro/client/request_handler.rb
|
129
129
|
- lib/klaro/client/resource.rb
|
130
|
+
- lib/klaro/client/resource/attachment.rb
|
130
131
|
- lib/klaro/client/resource/board.rb
|
131
132
|
- lib/klaro/client/resource/dimension.rb
|
132
133
|
- lib/klaro/client/resource/dimension_value.rb
|
@@ -154,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
|
158
|
-
rubygems_version: 2.7.6
|
158
|
+
rubygems_version: 3.1.2
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Klaro Client
|