rujira 0.1.0 → 0.1.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: 254e17d007505ee838a425fd3c804b4e15fd87558a8d4dccd1f2c52083182148
4
- data.tar.gz: 855cd2b7fdd61750151cbce3a073e6dbb12d46d93065d923cf91ffae33aead2d
3
+ metadata.gz: b30eacffd8fe9cd8ffa883aba1c85fb7d825222205b456dcf8c1f3dc301e0c50
4
+ data.tar.gz: e4805fe425b509c840c9b71f6816399197022ef115598fc1bfd27324b635cff3
5
5
  SHA512:
6
- metadata.gz: 713b9cdc54f4ddd9e9975fdf309fd79f057c1cbee551859c33a4538a4b3de0cfe35f54c836b78b22425edd3ce990e333c8ebb4b52747603a4098cd610c8585ca
7
- data.tar.gz: 8f7619b9767b6da6b4b7c856de730d5a69208a78e785bc9af88717ef700548bd305c9b1fd31e4e10eb8c0dd36dea03a6f7086244f35aad275423b82492f1af0a
6
+ metadata.gz: 77b4be2293066b682f87a6150471dff71cd4849d85e93f189f26ec3ee3c7f7773f15c827fd79307982fe4c13ec8f519f3e143f8a2105fd0eebbb89f1eabdf54b
7
+ data.tar.gz: c3bb572c07824626af1524c741a0d9fc227ab629da8fe088e71e0298d7b38ed53cb3e737f196ffd8d9529935668333ce9603040537c1f8c925b39a09c40a35ef
data/README.md CHANGED
@@ -7,7 +7,6 @@
7
7
  ## Usage in the code
8
8
 
9
9
  Rujira::Api::Project.get 'ITMG'
10
- Rujira::Api::Issue.get 'ITMG-1'
11
10
  Rujira::Api::Issue.create fields: {
12
11
  project: { key: 'ITMG' },
13
12
  assignee: { name: 'wilful' },
@@ -16,10 +15,12 @@
16
15
  issuetype: { name: 'Task' },
17
16
  labels: ['bot']
18
17
  }
18
+ Rujira::Api::Issue.get 'ITMG-1'
19
19
  Rujira::Api::Search.get jql: 'project = ITMG and status IN ("To Do", "In Progress") ORDER BY issuekey',
20
20
  maxResults: 10,
21
21
  startAt: 0,
22
22
  fields: ['id', 'key']
23
+ Rujira::Api::Issue.del 'ITMG-1'
23
24
 
24
25
  ## Testing
25
26
 
@@ -3,18 +3,30 @@
3
3
  module Rujira
4
4
  module Api
5
5
  # TODO
6
- class Issue
7
- def self.get(id)
8
- Entity.build do
9
- path "rest/api/2/issue/#{id}"
10
- end.get.body
6
+ # https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/issue
7
+ class Issue < Item
8
+ def self.get(id_or_key)
9
+ entity = Entity.build do
10
+ path "rest/api/2/issue/#{id_or_key}"
11
+ end
12
+ new(entity.commit)
13
+ end
14
+
15
+ def self.del(id_or_key)
16
+ entity = Entity.build do
17
+ path "rest/api/2/issue/#{id_or_key}"
18
+ method :DELETE
19
+ end
20
+ entity.commit
11
21
  end
12
22
 
13
23
  def self.create(**data)
14
- Entity.build do
24
+ entity = Entity.build do
15
25
  path 'rest/api/2/issue'
16
- data data
17
- end.post.body
26
+ method :POST
27
+ data data if data
28
+ end
29
+ new(entity.commit)
18
30
  end
19
31
  end
20
32
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rujira
4
+ module Api
5
+ # TODO
6
+ class Item
7
+ attr_accessor :data
8
+
9
+ def initialize(data = nil)
10
+ @data = data
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,11 +3,13 @@
3
3
  module Rujira
4
4
  module Api
5
5
  # TODO
6
- class Project
7
- def self.get(id)
8
- Entity.build do
9
- path "rest/api/2/project/#{id}"
10
- end.get.body
6
+ # https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/project
7
+ class Project < Item
8
+ def self.get(id_or_key)
9
+ entity = Entity.build do
10
+ path "rest/api/2/project/#{id_or_key}"
11
+ end
12
+ new(entity.commit)
11
13
  end
12
14
  end
13
15
  end
@@ -3,12 +3,17 @@
3
3
  module Rujira
4
4
  module Api
5
5
  # TODO
6
- class Search
6
+ # https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/search
7
+ class Search < Item
7
8
  def self.get(**data)
8
- Entity.build do
9
+ entity = Entity.build do
9
10
  path 'rest/api/2/search'
10
11
  data data
11
- end.post.body
12
+ method :POST
13
+ end
14
+ entity.commit['issues'].map do |issue|
15
+ Issue.new(issue)
16
+ end
12
17
  end
13
18
  end
14
19
  end
@@ -3,21 +3,21 @@
3
3
  module Rujira
4
4
  # TODO
5
5
  class Connection
6
- def self.new
7
- url = Configuration.url
8
- Faraday.new(url: url) do |builder|
9
- builder.request :authorization, 'Bearer', -> { token }
6
+ def initialize
7
+ @token = Configuration.token
8
+ @options = {
9
+ url: Configuration.url
10
+ }
11
+ end
12
+
13
+ def run
14
+ Faraday.new(@options) do |builder|
15
+ builder.request :authorization, 'Bearer', -> { @token }
10
16
  builder.request :json
11
17
  builder.response :json
12
18
  builder.response :raise_error
13
19
  builder.response :logger if Configuration.debug
14
20
  end
15
21
  end
16
-
17
- private
18
-
19
- def self.token
20
- Configuration.token
21
- end
22
22
  end
23
23
  end
data/lib/rujira/entity.rb CHANGED
@@ -3,6 +3,10 @@
3
3
  module Rujira
4
4
  # TODO
5
5
  class Entity
6
+ def initialize
7
+ @method = :GET
8
+ end
9
+
6
10
  def self.build(&block)
7
11
  entity = new
8
12
  return entity unless block_given?
@@ -12,6 +16,10 @@ module Rujira
12
16
  entity
13
17
  end
14
18
 
19
+ def method(method)
20
+ @method = method
21
+ end
22
+
15
23
  def path(path = nil)
16
24
  @path ||= path
17
25
 
@@ -28,20 +36,48 @@ module Rujira
28
36
  raise ArgumentError, "No argument to 'data' was given."
29
37
  end
30
38
 
39
+ def commit
40
+ case @method
41
+ when :GET
42
+ get.body
43
+ when :POST
44
+ post.body
45
+ when :DELETE
46
+ delete.body
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def request
53
+ yield
54
+ rescue Faraday::Error => e
55
+ raise "Status #{e.response[:status]}: #{e.response[:body]}"
56
+ end
57
+
31
58
  def get
32
- client.get path
59
+ request do
60
+ client.get path
61
+ end
33
62
  end
34
63
 
35
- def post
36
- client.post path do |req|
37
- req.body = data.to_json
64
+ def delete
65
+ request do
66
+ client.delete path
38
67
  end
39
68
  end
40
69
 
41
- private
70
+ def post
71
+ request do
72
+ client.post path do |req|
73
+ req.body = data.to_json
74
+ end
75
+ end
76
+ end
42
77
 
43
78
  def client
44
- Rujira::Connection.new
79
+ conn = Rujira::Connection.new
80
+ conn.run
45
81
  end
46
82
  end
47
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rujira
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/rujira.rb CHANGED
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # https://tomdebruijn.com/posts/ruby-write-your-own-domain-specific-language/
4
- # https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/
5
-
6
3
  require 'faraday'
7
4
  require 'json'
8
5
  require_relative 'rujira/version'
9
6
  require_relative 'rujira/connection'
10
7
  require_relative 'rujira/configuration'
11
8
  require_relative 'rujira/entity'
9
+ require_relative 'rujira/api/item'
12
10
  require_relative 'rujira/api/search'
13
11
  require_relative 'rujira/api/issue'
14
12
  require_relative 'rujira/api/project'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rujira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Semenov
@@ -26,6 +26,7 @@ files:
26
26
  - compose.yaml
27
27
  - lib/rujira.rb
28
28
  - lib/rujira/api/issue.rb
29
+ - lib/rujira/api/item.rb
29
30
  - lib/rujira/api/project.rb
30
31
  - lib/rujira/api/search.rb
31
32
  - lib/rujira/configuration.rb