klaro-client 0.4.3 → 0.5.2

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: 6c99d22b17ba2b1fec0e6d5a431e62bedb02975235412664aab41e7b820e4568
4
- data.tar.gz: '08b2a568aa7a590fa5424399e02573c15af4809e64a71432c2b12283b0d8d0ad'
3
+ metadata.gz: d0fcb893254b798095805751fdebcea7a0ed6ab481decf7fa687393ba7e012ab
4
+ data.tar.gz: eec1632171921bf81f2c97c6c10a352a957c615e968d76296e4dc54ed0e96562
5
5
  SHA512:
6
- metadata.gz: 7c31ae21e22413d7f6109fcc18ddce898101a440c98c69cab705c021444647116025a336e108a1caf2b19b7bc8e181f8177749a5e63f7754f9ac1608794a01bc
7
- data.tar.gz: 48a49aa2448c7064696d79075b64e7a682caa33ea884287a957f4e5ed2a9f98b5506da9b3ff02063db71af6e2652d2c179270df1227c6d2d0fe5c501a9ad3770
6
+ metadata.gz: 7ac3c1d551f1910aa193cc753fe036dc8fe360175963940f9a4c9d9b7281020b6a7e493b1bece4576bd7e974d04b4c07c75572f158d862566dd79616c80c7965
7
+ data.tar.gz: fdd82f48b35932038ab44ad0beccba73b710b1be2c3671af1e38088d501649a5e3124b4c01264af5cadc510bef6624c7cd06e81d8286e19d628ff20f30639e4a
data/lib/klaro/client.rb CHANGED
@@ -11,6 +11,10 @@ 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
@@ -20,23 +24,23 @@ module Klaro
20
24
  end
21
25
 
22
26
  def dimension(code_or_id)
23
- Dimension.dress(request.get("/api/dimensions/#{code_or_id}"))
27
+ Dimension.dress(request.get("/api/dimensions/#{code_or_id}"), self)
24
28
  end
25
29
 
26
30
  def dimensions
27
- Dimensions.dress(request.get('/api/dimensions'))
31
+ Dimensions.dress(request.get('/api/dimensions'), self)
28
32
  end
29
33
 
30
34
  def board(location_or_id)
31
- Board.dress(request.get("/api/boards/#{location_or_id}"))
35
+ Board.dress(request.get("/api/boards/#{location_or_id}"), self)
32
36
  end
33
37
 
34
38
  def board_stories(location_or_id)
35
- Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"))
39
+ Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"), self)
36
40
  end
37
41
 
38
42
  def story(id_or_identifier)
39
- Story.dress(request.get("/api/stories/#{id_or_identifier}"))
43
+ Story.dress(request.get("/api/stories/#{id_or_identifier}"), self)
40
44
  end
41
45
 
42
46
  def upload_image(image_path)
@@ -2,16 +2,32 @@ module Klaro
2
2
  class Client
3
3
  class Resource < OpenStruct
4
4
 
5
- class << self
6
- alias :dress :new
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
@@ -4,7 +4,7 @@ module Klaro
4
4
 
5
5
  def values
6
6
  @values ||= super
7
- .map{|v| DimensionValue.dress(v) }
7
+ .map{|v| DimensionValue.dress(v, @client) }
8
8
  .sort{|v1,v2| v1.ordering <=> v2.ordering }
9
9
  end
10
10
 
@@ -15,6 +15,20 @@ module Klaro
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,15 @@ 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["url"]
29
- url += "?n=" + URI.encode_www_form_component(attachment["filename"]) unless url =~ /\?n=/
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("url" => path)
45
+ attachment.url = path
46
+ attachment
32
47
  end
33
- self.class.new(self.to_h.merge(
48
+ self.class.dress(self.to_h.merge(
34
49
  attachments: as
35
- ))
50
+ ), @client)
36
51
  end
37
52
 
38
53
  def download_and_relocate_images(root_path, target_folder, client)
@@ -42,9 +57,9 @@ module Klaro
42
57
  image_relative_path = handle_image(url, root_path, target_folder, client)
43
58
  "![#{label}](#{image_relative_path})"
44
59
  end
45
- self.class.new(self.to_h.merge(
60
+ self.class.dress(self.to_h.merge(
46
61
  specification: spec
47
- ))
62
+ ), @client)
48
63
  end
49
64
 
50
65
  private
@@ -33,7 +33,7 @@ module Klaro
33
33
  end
34
34
 
35
35
  def to_html
36
- @renderer.render(to_s).strip
36
+ @renderer.render(to_s).strip.gsub(/<a href/, '<a target="_blank" href')
37
37
  end
38
38
 
39
39
  end # class MdText
@@ -2,8 +2,8 @@ module Klaro
2
2
  class Client
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 4
6
- TINY = 3
5
+ MINOR = 5
6
+ TINY = 2
7
7
  end
8
8
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
9
9
  end # class Client
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.3
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - enspirit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -44,20 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: '3.4'
47
+ version: 3.5.1
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: '3.0'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '3.4'
54
+ version: 3.5.1
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: i18n
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -114,19 +108,19 @@ dependencies:
114
108
  - - "~>"
115
109
  - !ruby/object:Gem::Version
116
110
  version: '3.7'
117
- description:
118
- email:
111
+ description:
112
+ email:
119
113
  executables: []
120
114
  extensions: []
121
115
  extra_rdoc_files: []
122
116
  files:
123
117
  - Gemfile
124
118
  - Rakefile
125
- - VERSION
126
119
  - lib/klaro/client.rb
127
120
  - lib/klaro/client/errors.rb
128
121
  - lib/klaro/client/request_handler.rb
129
122
  - lib/klaro/client/resource.rb
123
+ - lib/klaro/client/resource/attachment.rb
130
124
  - lib/klaro/client/resource/board.rb
131
125
  - lib/klaro/client/resource/dimension.rb
132
126
  - lib/klaro/client/resource/dimension_value.rb
@@ -135,11 +129,11 @@ files:
135
129
  - lib/klaro/client/resource/story.rb
136
130
  - lib/klaro/client/support/md_text.rb
137
131
  - lib/klaro/client/version.rb
138
- homepage:
132
+ homepage:
139
133
  licenses:
140
134
  - MIT
141
135
  metadata: {}
142
- post_install_message:
136
+ post_install_message:
143
137
  rdoc_options: []
144
138
  require_paths:
145
139
  - lib
@@ -154,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
148
  - !ruby/object:Gem::Version
155
149
  version: '0'
156
150
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.7.6
159
- signing_key:
151
+ rubygems_version: 3.2.1
152
+ signing_key:
160
153
  specification_version: 4
161
154
  summary: Klaro Client
162
155
  test_files: []
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0