klaro-client 0.4.3 → 0.4.4

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: 6c99d22b17ba2b1fec0e6d5a431e62bedb02975235412664aab41e7b820e4568
4
- data.tar.gz: '08b2a568aa7a590fa5424399e02573c15af4809e64a71432c2b12283b0d8d0ad'
3
+ metadata.gz: '08aa3f977345513aca8d374ebe5e837d580bd95cf75da1bf555bd170858f3401'
4
+ data.tar.gz: 4ce2e6929c252660a35c13aa317ac8de7a4c715d4bf5b717119b61bb32a6929f
5
5
  SHA512:
6
- metadata.gz: 7c31ae21e22413d7f6109fcc18ddce898101a440c98c69cab705c021444647116025a336e108a1caf2b19b7bc8e181f8177749a5e63f7754f9ac1608794a01bc
7
- data.tar.gz: 48a49aa2448c7064696d79075b64e7a682caa33ea884287a957f4e5ed2a9f98b5506da9b3ff02063db71af6e2652d2c179270df1227c6d2d0fe5c501a9ad3770
6
+ metadata.gz: 01a6d53e1763a1b8e37b3777ab56bc2edd24cc28b4d6de447df8af75bc8c513bc45a9c7d9832e6fe942eff82d712b5aefad258a1035035b9f0d5e60a5e0f70cf
7
+ data.tar.gz: 27f1f1183ec289d2b2ae2b4ae6cfc0a1a14d7f42d1f31c7ee9a123291c4d320e11eee2c9d078019ddf1de65649636a180d3368695e8269c4ab5ebd9bd8925e92
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,16 @@ module Klaro
15
15
  end
16
16
  alias :details :specification
17
17
 
18
+ def attachments
19
+ @attachments || super.map{|a| Attachment.dress(a, @client) }
20
+ end
21
+
22
+ def cover_attachment(force = false)
23
+ got = (self.attachments || []).find{|a| a[:isCover] }
24
+ got = (self.attachments || []).first if got.nil? and force
25
+ got
26
+ end
27
+
18
28
  def to_url(with_identifier = true)
19
29
  I18n.config.available_locales = [:en, :fr]
20
30
  url = I18n.transliterate(title.to_s)
@@ -25,14 +35,14 @@ module Klaro
25
35
 
26
36
  def download_and_relocate_attachments(root_path, target_folder, client)
27
37
  as = self.attachments.map do |attachment|
28
- url = attachment["url"]
29
- url += "?n=" + URI.encode_www_form_component(attachment["filename"]) unless url =~ /\?n=/
38
+ url = attachment.url
39
+ url += "?n=" + URI.encode_www_form_component(attachment.filename) unless url =~ /\?n=/
30
40
  path = handle_image(url, root_path, target_folder, client)
31
- attachment.merge("url" => path)
41
+ attachment.merge(url => path)
32
42
  end
33
- self.class.new(self.to_h.merge(
43
+ self.class.dress(self.to_h.merge(
34
44
  attachments: as
35
- ))
45
+ ), @client)
36
46
  end
37
47
 
38
48
  def download_and_relocate_images(root_path, target_folder, client)
@@ -42,9 +52,9 @@ module Klaro
42
52
  image_relative_path = handle_image(url, root_path, target_folder, client)
43
53
  "![#{label}](#{image_relative_path})"
44
54
  end
45
- self.class.new(self.to_h.merge(
55
+ self.class.dress(self.to_h.merge(
46
56
  specification: spec
47
- ))
57
+ ), @client)
48
58
  end
49
59
 
50
60
  private
@@ -3,7 +3,7 @@ module Klaro
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 3
6
+ TINY = 4
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.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - enspirit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-04-15 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