backlog_jp 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: d127e6f10a8f49a928418bb5ffc563ce2dccd246
4
- data.tar.gz: 50a121f489af8b417318478fa4e9aea4c8b6e370
3
+ metadata.gz: 9677d8922a4959d4d0dd47f5fa51be789922ca2f
4
+ data.tar.gz: a9ab169d6b6ebf872b3e42c232b96a06db344113
5
5
  SHA512:
6
- metadata.gz: eff4d3dba77ea51d3fd453f98b2c53a12e08d01c3b7124ada274c9d59d7afe3f6eb4f772a1b73c2c4e1e0292fa45cf08bd1c6728d3a1d469fbd907c3ba58b7f7
7
- data.tar.gz: 20914d56059c701946bdddb7611cbd7a28f0e1bb7e18ca2f8ef336d911b4d240acc054326f672d98f854846bf68bc3af816e77ae59bc04bf1e0f4daf59ddff95
6
+ metadata.gz: 211de2a5f77b5a87233e6cc7641b26482695a8f0252b5075c9a669c9d1fbafcea7849a5bcbf6fcf6ef92c4abffd1ae16d5c5166cc8fc924f4433ab91d546776c
7
+ data.tar.gz: ce1826b406f995d84825df3dda881dbaff5ad430c9b2505fbe6d32cf534380287041767142ba2d24de8f22adc2e3bf7fbccc6c69aecb9fcbfde3dd1fa67fc13d
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # BacklogJp
2
2
 
3
+ **!!!WORK IN PROGRESS!!!**
4
+
3
5
  A Rubyish interface for Backlog.
4
6
 
5
7
  ## Requirements
@@ -26,6 +28,7 @@ TODO: Write more usage instructions here
26
28
 
27
29
  require "backlog_jp"
28
30
 
31
+ # Configure space/user infomation with a block.
29
32
  BacklogJp.configure do |config|
30
33
  config.space = ENV["BACKLOG_SPACE"]
31
34
  config.username = ENV["BACKLOG_USERNAME"]
@@ -33,9 +36,17 @@ TODO: Write more usage instructions here
33
36
  end
34
37
 
35
38
  all_projects = BacklogJp::Project.all # Array of all projects.
39
+
36
40
  project = all_projects.first # A Project object.
37
41
  project.issue_types # Array of project's issue types.
38
42
 
43
+ project.name #=> "some project" # Get project's name.
44
+ project.name = "greatest project" # Set new project name.
45
+ project.save # Save changed attribute
46
+
47
+ client = Backlog.client # Client object.
48
+ client.get_projects # Call `getProjects` API directly.
49
+
39
50
  # etc...
40
51
  # work in progress
41
52
 
data/backlog_jp.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'backlog_jp/_version'
4
+ require 'backlog_jp/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "backlog_jp"
8
8
  spec.version = BacklogJp::VERSION
9
9
  spec.authors = ["y13i"]
10
10
  spec.email = ["email@y13i.com"]
11
- spec.summary = %q{A Rubyish interface for Backlog.}
12
- spec.description = %q{A Rubyish, object-oriented interface for project management service Backlog's XML-RPC API.}
11
+ spec.summary = %q{A Ruby interface for Backlog.jp.}
12
+ spec.description = %q{A Ruby interface for project management service Backlog.jp API V2.}
13
13
  spec.homepage = "http://github.com/y13i/backlog_jp"
14
14
  spec.license = "MIT"
15
15
 
@@ -20,4 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake", "~> 0"
23
+
24
+ spec.add_dependency "faraday"
25
+
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-coolline"
28
+ spec.add_development_dependency "awesome_print"
23
29
  end
@@ -1,32 +1,55 @@
1
- require "xmlrpc/client"
2
- require_relative "configuration"
3
-
4
- module BacklogJp
5
- # Wrapping class of Backlog's XMLRPC API.
6
- #
7
- # eg. XMLRPC method "backlog.createIssue" can be called as...
8
- #
9
- # +BacklogJp.client.create_issue summery: "Issue title", description: "Issue body"+
10
- class Client < ::XMLRPC::Client
11
- private
12
- def method_missing method, *args
13
- send :call, "backlog.#{camelize method.to_s}", *args
1
+ require "faraday"
2
+ require "json"
3
+
4
+ class BacklogJp::Client
5
+ AuthenticationException = Class.new Exception
6
+ APIException = Class.new Exception
7
+
8
+ def initialize config
9
+ unless config.key?(:space) && config.key?(:api_key)
10
+ fail AuthenticationException, "`:space` and `:api_key` are required for authentication."
14
11
  end
15
12
 
16
- def camelize string
17
- string.sub(/\Aadmin_/, "admin.").gsub(/_[a-z]/){|match| match.chars.last.upcase}
13
+ @space = config[:space]
14
+ @api_key = config[:api_key]
15
+ end
16
+
17
+ [:get, :post, :patch, :delete].each do |method|
18
+ define_method method do |*args|
19
+ api_path, params = *args
20
+ params ||= {}
21
+
22
+ response = connection.send(method, "/api/v2/#{api_path}?apiKey=#{@api_key}", build_params(params))
23
+
24
+ unless response.status.to_s.start_with? "2"
25
+ fail APIException, JSON.parse(response.body, symbolize_names: true)
26
+ end
27
+
28
+ JSON.parse(response.body, symbolize_names: true)
18
29
  end
19
30
  end
20
31
 
21
- # Returns a Client with configuration.
22
- def self.client
23
- @client ||= Client.new_from_hash(
24
- host: "#{configuration.space}.backlog.jp",
25
- path: "/XML-RPC",
26
- port: 443,
27
- use_ssl: true,
28
- user: configuration.username,
29
- password: configuration.password,
30
- )
32
+ private
33
+
34
+ def connection
35
+ @connection ||= Faraday.new host
36
+ end
37
+
38
+ def host
39
+ @host ||= "https://#{@space}.backlog.jp"
40
+ end
41
+
42
+ def camelize string
43
+ string.gsub(/_[a-z]/){|match| match.chars.last.upcase}
44
+ end
45
+
46
+ def build_params params
47
+ hash = {}
48
+
49
+ params.each do |key, value|
50
+ hash.update camelize(key.to_s).intern => value
51
+ end
52
+
53
+ hash
31
54
  end
32
55
  end
@@ -1,3 +1,3 @@
1
1
  module BacklogJp
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/backlog_jp.rb CHANGED
@@ -1,3 +1,2 @@
1
- %w[_version client interface].each do |file|
2
- require_relative "backlog_jp/#{file}"
3
- end
1
+ require "backlog_jp/version"
2
+ require "backlog_jp/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backlog_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - y13i
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,8 +38,63 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: A Rubyish, object-oriented interface for project management service Backlog's
42
- XML-RPC API.
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-coolline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Ruby interface for project management service Backlog.jp API V2.
43
98
  email:
44
99
  - email@y13i.com
45
100
  executables: []
@@ -51,21 +106,10 @@ files:
51
106
  - LICENSE.txt
52
107
  - README.md
53
108
  - Rakefile
54
- - TODO.md
55
109
  - backlog_jp.gemspec
56
110
  - lib/backlog_jp.rb
57
- - lib/backlog_jp/_version.rb
58
111
  - lib/backlog_jp/client.rb
59
- - lib/backlog_jp/common.rb
60
- - lib/backlog_jp/configuration.rb
61
- - lib/backlog_jp/interface.rb
62
- - lib/backlog_jp/project.rb
63
- - lib/backlog_jp/project/common.rb
64
- - lib/backlog_jp/project/component.rb
65
- - lib/backlog_jp/project/issue.rb
66
- - lib/backlog_jp/project/issue_type.rb
67
- - lib/backlog_jp/project/version.rb
68
- - lib/backlog_jp/user.rb
112
+ - lib/backlog_jp/version.rb
69
113
  homepage: http://github.com/y13i/backlog_jp
70
114
  licenses:
71
115
  - MIT
@@ -86,8 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
130
  version: '0'
87
131
  requirements: []
88
132
  rubyforge_project:
89
- rubygems_version: 2.2.2
133
+ rubygems_version: 2.4.5
90
134
  signing_key:
91
135
  specification_version: 4
92
- summary: A Rubyish interface for Backlog.
136
+ summary: A Ruby interface for Backlog.jp.
93
137
  test_files: []
data/TODO.md DELETED
@@ -1,38 +0,0 @@
1
- # TODO
2
-
3
- とりあえず作る
4
-
5
- ## まだ実装してないBacklog XMLRPC API一覧
6
-
7
- * backlog.getUsers
8
- * backlog.getIssue
9
- * backlog.getIssue
10
- * backlog.getComments
11
- * backlog.countIssue
12
- * backlog.findIssue
13
- * backlog.createIssue
14
- * backlog.updateIssue
15
- * backlog.switchStatus
16
- * backlog.addComment
17
- * backlog.getTimeline
18
- * backlog.getProjectSummary
19
- * backlog.getProjectSummaries
20
- * backlog.getUser
21
- * backlog.getUserIcon
22
- * backlog.getActivityTypes
23
- * backlog.getStatuses
24
- * backlog.getResolutions
25
- * backlog.getPriorities
26
- * backlog.getCustomFields
27
- * backlog.getChildIssues
28
- * backlog.admin.getUsers
29
- * backlog.admin.addUser
30
- * backlog.admin.updateUser
31
- * backlog.admin.deleteUser
32
- * backlog.admin.getProjectUsers
33
- * backlog.admin.addProjectUser
34
- * backlog.admin.updateProjectUsers
35
- * backlog.admin.deleteProjectUser
36
- * backlog.admin.addCustomField
37
- * backlog.admin.updateCustomField
38
- * backlog.admin.deleteCustomField
@@ -1,101 +0,0 @@
1
- require "date"
2
-
3
- module BacklogJp::Common
4
- def self.included klass
5
- klass.class_eval do
6
- class << self
7
- private
8
-
9
- def find_by_seed method, attributes = {}
10
- array_response = BacklogJp.client.send method
11
-
12
- array_response.map do |item|
13
- array.push new_from_response item
14
- end
15
- end
16
-
17
- def cud_seed method, required_attributes, attributes = {}
18
- require_attribute attributes, *required_attributes
19
- new_from_response BacklogJp.client.send(method, attributes)
20
- end
21
-
22
- def new_from_response response
23
- attributes = @attr_r + @attr_a
24
- new *attributes.map{|attribute| response[attribute.to_s]}
25
- end
26
-
27
- def require_attribute attributes, *keys
28
- fail ArgumentError, "#{keys.join ", "} is required." if keys.map{|key| attributes[key].nil?}.any?
29
- end
30
-
31
- def date_to_s attributes
32
- attributes.each do |key, value|
33
- attributes[key] = value.strftime "%Y%m%d" if value.is_a? Date
34
- end
35
- end
36
- end
37
- end
38
- end
39
-
40
- def == other
41
- eql? other
42
- end
43
-
44
- def eql? other
45
- return false unless self.class == other.class
46
-
47
- (attr_a + attr_r).all? do |attribute|
48
- send(attribute) == other.send(attribute)
49
- end
50
- end
51
-
52
- def changed? *attributes
53
- attributes = attr_a if attributes.empty?
54
-
55
- attributes.any? do |attribute|
56
- attribute_changed? attribute
57
- end
58
- end
59
-
60
- def changed_attributes
61
- attr_a.inject Hash.new do |hash, attribute|
62
- if changed? attribute
63
- hash.merge attribute => send(attribute)
64
- else
65
- hash
66
- end
67
- end
68
- end
69
-
70
- def save
71
- if changed?
72
- saved = self.class.update attributes_to_save
73
- @unsaved = nil
74
- saved
75
- else
76
- fail "Attributes not changed."
77
- end
78
- end
79
-
80
- private
81
-
82
- def attributes_to_save
83
- changed_attributes.reject {|key, value| value.nil?}.merge id: id
84
- end
85
-
86
- def unsaved
87
- @unsaved ||= self.class.find_by id: id
88
- end
89
-
90
- def attribute_changed? attribute
91
- send(attribute) != unsaved.send(attribute)
92
- end
93
-
94
- def attr_r
95
- self.class.instance_variable_get :@attr_r
96
- end
97
-
98
- def attr_a
99
- self.class.instance_variable_get :@attr_a
100
- end
101
- end
@@ -1,16 +0,0 @@
1
- module BacklogJp
2
- class Configuration
3
- attr_accessor :space, :username, :password
4
- end
5
-
6
- class << self
7
- attr_accessor :configuration
8
-
9
- # Sets configuration with a block.
10
- def configure &block
11
- self.configuration ||= Configuration.new
12
- yield configuration
13
- configuration
14
- end
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- require_relative "common"
2
-
3
- %w[project user].each do |resource|
4
- require_relative resource
5
-
6
- Dir.glob "#{__dir__}/#{resource}/*.rb" do |file|
7
- require file
8
- end
9
- end
@@ -1,49 +0,0 @@
1
- module BacklogJp::Project::Common
2
- def self.included klass
3
- klass.class_eval do
4
- class << self
5
- private
6
-
7
- def find_by_seed method, attributes = {}
8
- require_attribute attributes, :project_id
9
- array_response = BacklogJp.client.send method, attributes[:project_id]
10
-
11
- array_response.map do |item|
12
- new_from_response item.merge "project_id" => attributes[:project_id]
13
- end
14
- end
15
-
16
- def cud_seed method, required_attributes, attributes = {}
17
- require_attribute attributes, *required_attributes
18
- new_from_response BacklogJp.client.send(method, attributes).merge "project_id" => attributes[:project_id]
19
- end
20
-
21
- def new_from_response response
22
- attributes = @attr_r + @attr_a << :project_id
23
- new *attributes.map{|attribute| response[attribute.to_s]}
24
- end
25
- end
26
- end
27
- end
28
-
29
- def destroy attributes = {}
30
- attributes[:id] = id
31
- attributes[:project_id] = @project_id
32
- self.class.delete attributes
33
- end
34
-
35
- def issues
36
- attributes = {project_id: @project_id}.merge self.class.to_s.gsub(/[A-Z]/) {|match| "_#{match.downcase}"}[1..-1].intern => id
37
- BacklogJp::Project::Issue.find_by attributes
38
- end
39
-
40
- private
41
-
42
- def attributes_to_save
43
- changed_attributes.merge id: id, project_id: @project_id
44
- end
45
-
46
- def unsaved
47
- @unsaved ||= self.class.find_by(project_id: @project_id).find {|item| id == item.id}
48
- end
49
- end
@@ -1,32 +0,0 @@
1
- class BacklogJp::Project::Component
2
- include BacklogJp::Common
3
- include BacklogJp::Project::Common
4
-
5
- attr_reader *@attr_r = %i[id]
6
- attr_accessor *@attr_a = %i[name]
7
-
8
- def initialize id, name, project_id
9
- @id = id
10
- @name = name
11
- @project_id = project_id
12
- end
13
-
14
- class << self
15
- def find_by attributes = {}
16
- find_by_seed :get_components, attributes
17
- end
18
-
19
- def create attributes = {}
20
- cud_seed :add_component, %i[project_id name], attributes
21
- end
22
-
23
- def update attributes = {}
24
- cud_seed :update_component, %i[project_id id], attributes
25
- end
26
-
27
- def delete attributes = {}
28
- require_attribute attributes, :project_id, :id
29
- new_from_response BacklogJp.client.delete_component(attributes[:id]).merge "project_id" => attributes[:project_id]
30
- end
31
- end
32
- end
@@ -1,105 +0,0 @@
1
- class BacklogJp::Project::Issue
2
- include BacklogJp::Common
3
- include BacklogJp::Project::Common
4
-
5
- attr_reader *@attr_r = %i[id key url created_user_id created_on updated_on]
6
- attr_accessor *@attr_a = %i[summery parent_issue_id description due_date start_date estimated_hours actual_hours issue_type priority resolution status components versions milestones assigner_id]
7
-
8
- def initialize id, key, url, created_user_id, created_on, updated_on, summery, parent_issue_id, description, due_date, start_date, estimated_hours, actual_hours, issue_type, priority, resolution, status, components, versions, milestones, assigner_id
9
- @id = id
10
- @key = key
11
- @url = url
12
- @created_user_id = created_user_id
13
- @created_on = created_on
14
- @updated_on = updated_on
15
- @summery = summery
16
- @parent_issue_id = parent_issue_id
17
- @description = description
18
- @due_date = due_date
19
- @start_date = start_date
20
- @estimated_hours = estimated_hours
21
- @actual_hours = actual_hours
22
- @issue_type = issue_type
23
- @priority = priority
24
- @resolution = resolution
25
- @status = status
26
- @components = components
27
- @versions = versions
28
- @milestones = milestones
29
- @assigner_id = assigner_id
30
- end
31
-
32
- class << self
33
- def find_by attributes = {}
34
- case attributes.keys
35
- when ->(k){k.include? :id}
36
- BacklogJp.client.get_issue attributes[:id]
37
- when ->(k){k.include? :key}
38
- BacklogJp.client.get_issue attributes[:key]
39
- when ->(k){k.include? :project_id}
40
- BacklogJp.client.find_issue find_issue_conditions attributes
41
- else
42
- raise "under construction"
43
- end
44
- end
45
-
46
- def create attributes = {}
47
- cud_seed :add_issue_type, %i[project_id name color], attributes
48
- end
49
-
50
- def update attributes = {}
51
- cud_seed :update_issue_type, %i[project_id id], attributes
52
- end
53
-
54
- private
55
-
56
- def find_issue_conditions attributes = {}
57
- attributes.inject Hash.new do |hash, (key, value)|
58
- hash.merge case key.intern
59
- when :project_id, :issue_type_id, :version_id, :status_id, :priority_id, :assigner_id, :created_user_id, :resolution_id
60
- find_by_key_camelize key, value
61
- when :parent_child_issue
62
- find_by_parent_child_issue_seed key, value
63
- when :created_on_min, :created_on_max, :updated_on_min, :updated_on_max, :start_date_min, :start_date_max, :due_date_min, :due_date_max
64
- find_by_value_date_to_s key, value
65
- when :sort
66
- {sort: value.to_s.upcase}
67
- when :order
68
- find_by_order_seed key, value
69
- else
70
- {key => value}
71
- end
72
- end
73
- end
74
-
75
- def find_by_key_camelize key, value
76
- {key.to_s.gsub(/_[a-z]/){|match| match.chars.last.upcase}.intern => value}
77
- end
78
-
79
- def find_by_parent_child_issue_seed key, value
80
- {
81
- parent_child_issue: case value
82
- when :except_child then 1
83
- when :child then 2
84
- when :not_related then 3
85
- when :parent then 4
86
- when 1..4 then value
87
- else fail ArgumentError
88
- end
89
- }
90
- end
91
-
92
- def find_by_value_date_to_s key, value
93
- {key => value.strftime("%Y%m%d")}
94
- end
95
-
96
- def find_by_order_seed key, value
97
- {
98
- order: case value
99
- when 1, :asc, :ascend then 1
100
- when 2, :desc, :descend then 2
101
- end
102
- }
103
- end
104
- end
105
- end
@@ -1,32 +0,0 @@
1
- class BacklogJp::Project::IssueType
2
- include BacklogJp::Common
3
- include BacklogJp::Project::Common
4
-
5
- attr_reader *@attr_r = %i[id]
6
- attr_accessor *@attr_a = %i[name color]
7
-
8
- def initialize id, name, color, project_id
9
- @id = id
10
- @name = name
11
- @color = color
12
- @project_id = project_id
13
- end
14
-
15
- class << self
16
- def find_by attributes = {}
17
- find_by_seed :get_issue_types, attributes
18
- end
19
-
20
- def create attributes = {}
21
- cud_seed :add_issue_type, %i[project_id name color], attributes
22
- end
23
-
24
- def update attributes = {}
25
- cud_seed :update_issue_type, %i[project_id id], attributes
26
- end
27
-
28
- def delete attributes = {}
29
- cud_seed :delete_issue_type, %i[project_id id], attributes
30
- end
31
- end
32
- end
@@ -1,48 +0,0 @@
1
- class BacklogJp::Project::Version
2
- include BacklogJp::Common
3
- include BacklogJp::Project::Common
4
-
5
- attr_reader *@attr_r = %i[id]
6
- attr_accessor *@attr_a = %i[name start_date due_date archived]
7
-
8
- def initialize id, name, start_date, due_date, archived, project_id
9
- @id = id
10
- @name = name
11
- @start_date = Date.parse start_date if start_date and start_date != ""
12
- @due_date = Date.parse due_date if due_date and due_date != ""
13
- @archived = archived
14
- @project_id = project_id
15
- end
16
-
17
- class << self
18
- def find_by attributes = {}
19
- require_attribute attributes, :project_id
20
-
21
- # This API... why doesn't it return due_date and start_date?
22
- # http://www.backlog.jp/api/method2_1.html
23
- array_response = BacklogJp.client.get_versions attributes[:project_id]
24
-
25
- array_response.each do |version|
26
- version["due_date"] = version["date"]
27
- version.delete "date"
28
- end
29
-
30
- array_response.inject Array.new do |array, item|
31
- array.push new_from_response item.merge "project_id" => attributes[:project_id]
32
- end
33
- end
34
-
35
- def create attributes = {}
36
- cud_seed :add_version, %i[project_id name color], date_to_s(attributes)
37
- end
38
-
39
- def update attributes = {}
40
- cud_seed :update_version, %i[project_id id], date_to_s(attributes)
41
- end
42
-
43
- def delete attributes = {}
44
- require_attribute attributes, :project_id, :id
45
- new_from_response BacklogJp.client.delete_version(attributes[:id]).merge "project_id" => attributes[:project_id]
46
- end
47
- end
48
- end
@@ -1,130 +0,0 @@
1
- class BacklogJp::Project
2
- include BacklogJp::Common
3
-
4
- attr_reader *@attr_r = %i[id url created_on updated_on]
5
- attr_accessor *@attr_a = %i[name key use_parent_child_issue text_formatting_rule archived use_chart]
6
-
7
- def initialize id, url, created_on, updated_on, name, key, use_parent_child_issue, text_formatting_rule, archived, use_chart
8
- @id = id
9
- @url = url
10
- @created_on = DateTime.parse created_on if created_on
11
- @updated_on = DateTime.parse updated_on if updated_on
12
- @name = name
13
- @key = key
14
- @use_parent_child_issue = use_parent_child_issue
15
- @text_formatting_rule = text_formatting_rule
16
- @archived = archived
17
- @use_chart = use_chart
18
- end
19
-
20
- class << self
21
- # Returns all projects as a array.
22
- def all
23
- array_response = begin
24
- BacklogJp.client.admin_get_projects
25
- rescue
26
- BacklogJp.client.get_projects
27
- end
28
-
29
- array_response.map do |project|
30
- new_from_response project
31
- end
32
- end
33
-
34
- # Returns a array of specified attribute from all projects.
35
- def distinct *attributes
36
- fail ArgumentError, "Specify at least one attribute." if attributes.empty?
37
-
38
- all.map do |item|
39
- if attributes.size == 1
40
- item.send attributes.first
41
- else
42
- attributes.map do |attribute|
43
- item.send attribute
44
- end
45
- end
46
- end
47
- end
48
-
49
- def find_by attributes = {}
50
- new_from_response BacklogJp.client.get_project case attributes.keys
51
- when ->(k){k.include? :id}
52
- attributes[:id]
53
- when ->(k){k.include? :key}
54
- attributes[:key].to_s
55
- else
56
- fail ArgumentError, "Give a hash with :id (Integer) or :key (Symbol or String) as a key."
57
- end
58
- end
59
-
60
- def [] arg
61
- case arg
62
- when Integer then find_by id: arg
63
- when String, Symbol then find_by key: arg.to_s
64
- else fail ArgumentError, "Give a Integer (for id), String or Symbol (for key)."
65
- end
66
- end
67
-
68
- def create attributes = {}
69
- cud_seed :admin_add_project, %i[key name], attributes
70
- end
71
-
72
- def update attributes = {}
73
- cud_seed :admin_update_project, %i[id], attributes
74
- end
75
-
76
- def delete attributes = {}
77
- require_attribute attributes, :id
78
- new_from_response BacklogJp.client.admin_delete_project attributes[:id]
79
- end
80
- end
81
-
82
- alias_method :created_at, :created_on
83
- alias_method :updated_at, :updated_on
84
-
85
- def components
86
- self.class::Component.find_by project_id: id
87
- end
88
-
89
- alias_method :categories, :components
90
-
91
- def add_component attributes
92
- attributes[:project_id] = id
93
- self.class::Component.create attributes
94
- end
95
-
96
- alias_method :add_category, :add_component
97
- alias_method :create_component, :add_component
98
- alias_method :create_category, :add_component
99
-
100
- def versions
101
- self.class::Version.find_by project_id: id
102
- end
103
-
104
- alias_method :milestones, :versions
105
-
106
- def add_version attributes
107
- attributes[:project_id] = id
108
- self.class::Version.create attributes
109
- end
110
-
111
- alias_method :add_milestone, :add_version
112
- alias_method :create_version, :add_version
113
- alias_method :create_milestone, :add_version
114
-
115
- def issue_types
116
- self.class::IssueType.find_by project_id: id
117
- end
118
-
119
- def add_issue_type attributes
120
- attributes[:project_id] = id
121
- self.class::IssueType.create attributes
122
- end
123
-
124
- alias_method :create_issue_type, :add_issue_type
125
-
126
- def issues attributes = {}
127
- attributes.merge project_id: id
128
- self.class::Issue.find_by attributes
129
- end
130
- end
File without changes