klaro-client 0.3.0 → 0.4.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: 9612e0a404f699dce37fa9d937c7c5b79758834f058aa125074107f9b5a70468
4
- data.tar.gz: cb0fe33f9ecf1a43839d162738b5d29e36072179e03c1cf05c44185de85d353d
3
+ metadata.gz: 1a258ae74415243864b134896b5dbd98ec2d73220cac4a8199089614db5f66d8
4
+ data.tar.gz: a2bc070c56903aeffedc957e82806e9fe41224b736766448211b27b0574aa886
5
5
  SHA512:
6
- metadata.gz: fedd2867b05272d285640f822b26cd45b732fa75665525699b51abd5e1da04b2c8f644b177d3547e4e39ca37b1d4d42e626d87193504631f3b8731e01881e830
7
- data.tar.gz: 046d46ade148f02cac554f74df9cdb45d80f74172941720eec79af395e62fbd357a5969a6c69c71c3224ff45601cbf5767c9b5903dee3e279081d24ec846c809
6
+ metadata.gz: 4f244ffb939719fe8ead74b056cb953885a919bd0fe31d36d45d5ea14b71dd3e922aa9850a49dd8f41a196cf7b72530bc3dcdaa8277de8d711e642b69ea40952
7
+ data.tar.gz: e833371db1db694bd8b8c5987c332c088356235334f1556583137cca0f745707547586e102631bd77bed15af2786d702add4752dff32e448afdeba34bb0e39f4
@@ -1,5 +1,6 @@
1
1
  require 'http'
2
2
  require 'path'
3
+ require 'redcarpet'
3
4
 
4
5
  module Klaro
5
6
  class Client
@@ -9,20 +10,32 @@ module Klaro
9
10
  @request = RequestHandler.new(base_url)
10
11
  end
11
12
 
12
- def login(user, password)
13
- request.authenticate(user, password)
13
+ def with_token(*args, &bl)
14
+ request.with_token(*args, &bl)
14
15
  end
15
16
 
16
- def stories(board)
17
- stories_list = request.get("/api/boards/#{board}/stories/")
18
- stories_list.map do |s|
19
- Story.new(request.get("/api/stories/#{s['id']}"))
20
- end
17
+ def login(*args, &bl)
18
+ request.authenticate(*args, &bl)
21
19
  end
22
20
 
23
- def dimensions(code: nil)
24
- return request.get('/api/dimensions') unless code
25
- request.get("/api/dimensions/#{code}")
21
+ def dimension(code_or_id)
22
+ Dimension.dress(request.get("/api/dimensions/#{code_or_id}"))
23
+ end
24
+
25
+ def dimensions
26
+ Dimensions.dress(request.get('/api/dimensions'))
27
+ end
28
+
29
+ def board(location_or_id)
30
+ Board.dress(request.get("/api/boards/#{location_or_id}"))
31
+ end
32
+
33
+ def board_stories(location_or_id)
34
+ Stories.dress(request.get("/api/boards/#{location_or_id}/stories/"))
35
+ end
36
+
37
+ def story(id_or_identifier)
38
+ Story.dress(request.get("/api/stories/#{id_or_identifier}"))
26
39
  end
27
40
 
28
41
  def upload_image(image_path)
@@ -36,6 +49,8 @@ module Klaro
36
49
  end
37
50
  end
38
51
  end
52
+ require_relative 'client/version'
39
53
  require_relative 'client/errors'
54
+ require_relative 'client/support/md_text'
40
55
  require_relative 'client/request_handler'
41
56
  require_relative 'client/resource'
@@ -1,11 +1,22 @@
1
1
  module Klaro
2
2
  class Client
3
3
  class RequestHandler
4
+ Http = HTTP
4
5
 
5
6
  attr_reader :base_url, :token
6
7
 
7
8
  def initialize(url)
8
9
  @base_url = url
10
+ @token = nil
11
+ end
12
+
13
+ def authenticated?
14
+ not(@token.nil?)
15
+ end
16
+
17
+ def with_token(token_type, access_token)
18
+ @token = "#{token_type} #{access_token}"
19
+ self
9
20
  end
10
21
 
11
22
  def authenticate(user, password)
@@ -56,7 +67,8 @@ module Klaro
56
67
  def http
57
68
  Http.headers(
58
69
  {
59
- Authorization: @token
70
+ "Authorization" => @token,
71
+ "Content-Type" => "application/json"
60
72
  }
61
73
  )
62
74
  end
@@ -1,7 +1,41 @@
1
1
  module Klaro
2
2
  class Client
3
3
  class Resource < OpenStruct
4
+
5
+ class << self
6
+ alias :dress :new
7
+ end
8
+
4
9
  end # class Resource
10
+ class Collection
11
+ include Enumerable
12
+
13
+ def initialize(items)
14
+ @items = items.map{|i| self.class.dress_one(i) }
15
+ end
16
+
17
+ def each(*args, &bl)
18
+ @items.each(*args, &bl)
19
+ end
20
+
21
+ class << self
22
+ alias :dress :new
23
+
24
+ def item(clazz)
25
+ @item_class = clazz
26
+ end
27
+
28
+ def dress_one(item)
29
+ @item_class.dress(item)
30
+ end
31
+ end
32
+
33
+ end
5
34
  end # class Client
6
35
  end # module Klaro
7
36
  require_relative 'resource/story'
37
+ require_relative 'resource/stories'
38
+ require_relative 'resource/dimension'
39
+ require_relative 'resource/dimension_value'
40
+ require_relative 'resource/dimensions'
41
+ require_relative 'resource/board'
@@ -0,0 +1,6 @@
1
+ module Klaro
2
+ class Client
3
+ class Board < Resource
4
+ end # class Dimension
5
+ end # class Client
6
+ end # module Klaro
@@ -0,0 +1,13 @@
1
+ module Klaro
2
+ class Client
3
+ class Dimension < Resource
4
+
5
+ def values
6
+ @values ||= super
7
+ .map{|v| DimensionValue.dress(v) }
8
+ .sort{|v1,v2| v1.ordering <=> v2.ordering }
9
+ end
10
+
11
+ end # class Dimension
12
+ end # class Client
13
+ end # module Klaro
@@ -0,0 +1,6 @@
1
+ module Klaro
2
+ class Client
3
+ class DimensionValue < Resource
4
+ end # class Dimension
5
+ end # class Client
6
+ end # module Klaro
@@ -0,0 +1,7 @@
1
+ module Klaro
2
+ class Client
3
+ class Dimensions < Collection
4
+ item(Dimension)
5
+ end # class Dimensions
6
+ end # class Client
7
+ end # module Klaro
@@ -0,0 +1,7 @@
1
+ module Klaro
2
+ class Client
3
+ class Stories < Collection
4
+ item(Story)
5
+ end # class Stories
6
+ end # class Client
7
+ end # module Klaro
@@ -2,6 +2,14 @@ module Klaro
2
2
  class Client
3
3
  class Story < Resource
4
4
 
5
+ def title
6
+ @title ||= MdText.new(self.description.split("\n").first)
7
+ end
8
+
9
+ def summary
10
+ @summary ||= MdText.new(self.description.split("\n")[1..-1].join("\n"))
11
+ end
12
+
5
13
  def download_and_relocate_attachments(root_path, target_folder, client)
6
14
  as = self.attachments.map do |attachment|
7
15
  url = attachment["url"]
@@ -12,10 +20,6 @@ module Klaro
12
20
  self.class.new(self.to_h.merge(
13
21
  attachments: as
14
22
  ))
15
- rescue => ex
16
- puts ex.message
17
- puts ex.backtrace.join("\n")
18
- raise
19
23
  end
20
24
 
21
25
  def download_and_relocate_images(root_path, target_folder, client)
@@ -0,0 +1,30 @@
1
+ module Klaro
2
+ class Client
3
+ class MdText
4
+
5
+ RENDERER = Redcarpet::Render::HTML.new({
6
+ filter_html: true,
7
+ hard_wrap: true,
8
+ no_links: false,
9
+ no_styles: true,
10
+ safe_links_only: true,
11
+ with_toc_data: false
12
+ })
13
+
14
+ MARKDOWN = Redcarpet::Markdown.new(RENDERER)
15
+
16
+ def initialize(src)
17
+ @src = src
18
+ end
19
+
20
+ def to_s
21
+ @src
22
+ end
23
+
24
+ def to_html
25
+ MARKDOWN.render(to_s).strip
26
+ end
27
+
28
+ end # class MdText
29
+ end # class Client
30
+ end # module Klaro
@@ -0,0 +1,10 @@
1
+ module Klaro
2
+ class Client
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 4
6
+ TINY = 0
7
+ end
8
+ VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
9
+ end # class Client
10
+ end # module Klaro
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enspirit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-06 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -30,14 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.1'
33
+ version: '4.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.1'
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '3.4'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '3.4'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: path
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +113,14 @@ files:
93
113
  - lib/klaro/client/errors.rb
94
114
  - lib/klaro/client/request_handler.rb
95
115
  - lib/klaro/client/resource.rb
116
+ - lib/klaro/client/resource/board.rb
117
+ - lib/klaro/client/resource/dimension.rb
118
+ - lib/klaro/client/resource/dimension_value.rb
119
+ - lib/klaro/client/resource/dimensions.rb
120
+ - lib/klaro/client/resource/stories.rb
96
121
  - lib/klaro/client/resource/story.rb
122
+ - lib/klaro/client/support/md_text.rb
123
+ - lib/klaro/client/version.rb
97
124
  homepage:
98
125
  licenses:
99
126
  - MIT