jiralicious 0.3.0 → 0.4.0

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.
Files changed (43) hide show
  1. data/README.md +3 -0
  2. data/jiralicious.gemspec +0 -2
  3. data/lib/jiralicious.rb +4 -0
  4. data/lib/jiralicious/avatar.rb +101 -0
  5. data/lib/jiralicious/base.rb +53 -15
  6. data/lib/jiralicious/configuration.rb +30 -4
  7. data/lib/jiralicious/custom_field_option.rb +7 -3
  8. data/lib/jiralicious/errors.rb +10 -0
  9. data/lib/jiralicious/field.rb +23 -12
  10. data/lib/jiralicious/issue.rb +69 -11
  11. data/lib/jiralicious/issue/comment.rb +54 -12
  12. data/lib/jiralicious/issue/fields.rb +44 -3
  13. data/lib/jiralicious/issue/transitions.rb +42 -11
  14. data/lib/jiralicious/issue/watchers.rb +19 -2
  15. data/lib/jiralicious/parsers/field_parser.rb +12 -0
  16. data/lib/jiralicious/project.rb +7 -1
  17. data/lib/jiralicious/project/avatar.rb +126 -0
  18. data/lib/jiralicious/search.rb +9 -0
  19. data/lib/jiralicious/search_result.rb +15 -7
  20. data/lib/jiralicious/session.rb +5 -0
  21. data/lib/jiralicious/user.rb +154 -0
  22. data/lib/jiralicious/user/avatar.rb +130 -0
  23. data/lib/jiralicious/version.rb +1 -1
  24. data/spec/avatar_spec.rb +50 -0
  25. data/spec/basic_session_spec.rb +4 -0
  26. data/spec/comment_spec.rb +2 -2
  27. data/spec/fixtures/avatar.json +7 -0
  28. data/spec/fixtures/avatar_custom.json +16 -0
  29. data/spec/fixtures/avatar_list.json +16 -0
  30. data/spec/fixtures/avatar_temp.json +7 -0
  31. data/spec/fixtures/avatar_test.png +0 -0
  32. data/spec/fixtures/user.json +27 -0
  33. data/spec/fixtures/user_array.json +26 -0
  34. data/spec/fixtures/user_picker.json +18 -0
  35. data/spec/issue_spec.rb +10 -9
  36. data/spec/project_avatar_spec.rb +66 -0
  37. data/spec/project_spec.rb +2 -2
  38. data/spec/search_spec.rb +2 -1
  39. data/spec/support/http.rb +24 -0
  40. data/spec/user_avatar_spec.rb +66 -0
  41. data/spec/user_spec.rb +79 -0
  42. data/spec/watchers_spec.rb +2 -2
  43. metadata +30 -18
@@ -1,9 +1,10 @@
1
1
  # encoding: utf-8
2
2
  module Jiralicious
3
3
  ##
4
- # The Issue class rolls up all functionality of issues from jira. This class contains methods to manage
5
- # Issues from Ruby via the API. Several child classes are added in order to facilitate several different
6
- # aspects of managing the issues.
4
+ # The Issue class rolls up all functionality of issues from Jira.
5
+ # This class contains methods to manage Issues from Ruby via the
6
+ # API. Several child classes are added in order to facilitate
7
+ # several different aspects of managing the issues.
7
8
  #
8
9
  class Issue < Jiralicious::Base
9
10
 
@@ -30,8 +31,15 @@ module Jiralicious
30
31
  # Contains the editmeta
31
32
  attr_accessor :editmeta
32
33
 
34
+ ##
33
35
  # Initialization Method
34
- def initialize(decoded_json = nil, default = nil, &blk)
36
+ #
37
+ # [Arguments]
38
+ # :decoded_json (optional) rubyized json object
39
+ #
40
+ # :default (optional) set to not load subclasses
41
+ #
42
+ def initialize(decoded_json = nil, default = nil)
35
43
  @loaded = false
36
44
  if (!decoded_json.nil?)
37
45
  super(decoded_json)
@@ -53,8 +61,14 @@ module Jiralicious
53
61
  end
54
62
 
55
63
  ##
56
- # Imports all data from a decoded hash. This function is used when a blank
57
- # issue is created but needs to be loaded from a JSON string at a later time.
64
+ # Imports all data from a decoded hash. This function is used
65
+ # when a blank issue is created but needs to be loaded from a
66
+ # JSON string at a later time.
67
+ #
68
+ # [Arguments]
69
+ # :decoded_hash (optional) rubyized json object
70
+ #
71
+ # :default (optional) set to not load subclasses
58
72
  #
59
73
  def load(decoded_hash, default = nil)
60
74
  decoded_hash.each do |k,v|
@@ -83,6 +97,11 @@ module Jiralicious
83
97
  ##
84
98
  # Adds specified assignee to the Jira Issue.
85
99
  #
100
+ # [Arguments]
101
+ # :name (required) name of assignee
102
+ #
103
+ # :key (required) issue key
104
+ #
86
105
  def assignee(name, key)
87
106
  name = {"name" => name} if name.is_a? String
88
107
  fetch({:method => :put, :key => "#{key}/assignee", :body => name})
@@ -92,22 +111,39 @@ module Jiralicious
92
111
  # Creates a new issue. This method is not recommended
93
112
  # for direct access but is provided for advanced users.
94
113
  #
114
+ # [Arguments]
115
+ # :issue (required) issue fields in hash format
116
+ #
95
117
  def create(issue)
96
118
  fetch({:method => :post, :body => issue})
97
119
  end
98
120
 
99
121
  ##
100
- # Removes/Deletes the Issue from the Jira Project. It is not recommended to delete issues however the
101
- # functionality is provided. It is recommended to override this function to throw an error or warning
102
- # to maintain data integrity in systems that do not allow deleting from a remote location.
122
+ # Removes/Deletes the Issue from the Jira Project. It is not
123
+ # recommended to delete issues however the functionality is
124
+ # provided. It is recommended to override this function to
125
+ # throw an error or warning to maintain data integrity in
126
+ # systems that do not allow deleting from a remote location.
127
+ #
128
+ # [Arguments]
129
+ # :key (required) issue key
130
+ #
131
+ # :deleteSubtasks (optional) boolean flag to remove subtasks
132
+ #
103
133
  #
104
134
  def remove(key, options = {})
105
135
  fetch({:method => :delete, :body_to_params => true, :key => key, :body => options})
106
136
  end
107
137
 
108
138
  ##
109
- # Updates the specified issue based on the provided HASH. It is not recommended
110
- # to access this method directly but is provided for advanced users.
139
+ # Updates the specified issue based on the provided HASH. It
140
+ # is not recommended to access this method directly but is
141
+ # provided for advanced users.
142
+ #
143
+ # [Arguments]
144
+ # :issue (required) hash of fields to update
145
+ #
146
+ # :key (required) issue key to update
111
147
  #
112
148
  def update(issue, key)
113
149
  fetch({:method => :put, :key => key, :body => issue})
@@ -117,6 +153,11 @@ module Jiralicious
117
153
  # Retrieves the create meta for the Jira Project based on Issue Types.
118
154
  # Can be used to validate or filter create requests to minimize errors.
119
155
  #
156
+ # [Arguments]
157
+ # :projectkeys (required) project key to generate create meta
158
+ #
159
+ # :issuetypeids (opitonal) list of issues types for create meta
160
+ #
120
161
  def createmeta(projectkeys, issuetypeids = nil)
121
162
  response = fetch({:body_to_params => true, :key => "createmeta", :body => {:expand => "projects.issuetypes.fields.", :projectKeys => projectkeys, :issuetypeIds => issuetypeids}})
122
163
  return Field.new(response.parsed_response)
@@ -126,6 +167,9 @@ module Jiralicious
126
167
  # Retrieves the edit meta for the Jira Issue. Can be used
127
168
  # to validate or filter create requests to minimize errors.
128
169
  #
170
+ # [Arguments]
171
+ # :key (required) issue key
172
+ #
129
173
  def editmeta(key)
130
174
  response = fetch({:key => "#{key}/editmeta"})
131
175
  response.parsed_response["key"] = key
@@ -135,6 +179,9 @@ module Jiralicious
135
179
  ##
136
180
  # Legacy method to retrieve transitions manually.
137
181
  #
182
+ # [Arguments]
183
+ # :transitions_url (required) full URL
184
+ #
138
185
  def get_transitions(transitions_url)
139
186
  Jiralicious.session.request(:get, transitions_url, :handler => handler)
140
187
  end
@@ -142,6 +189,11 @@ module Jiralicious
142
189
  ##
143
190
  # Legacy method to process transitions manually.
144
191
  #
192
+ # [Arguments]
193
+ # :transitions_url (required) full URL and params to be processed
194
+ #
195
+ # :data (required) data for the transition
196
+ #
145
197
  def transition(transitions_url, data)
146
198
  Jiralicious.session.request(:post, transitions_url,
147
199
  :handler => handler,
@@ -152,6 +204,9 @@ module Jiralicious
152
204
  ##
153
205
  # Method to assign an assignee by name in a current issue.
154
206
  #
207
+ # [Arguments]
208
+ # :name (required) name of assignee
209
+ #
155
210
  def set_assignee(name)
156
211
  self.class.assignee(name, self.jira_key)
157
212
  end
@@ -159,6 +214,9 @@ module Jiralicious
159
214
  ##
160
215
  # Method to remove or delete the current issue.
161
216
  #
217
+ # [Arguments]
218
+ # :options (optional) passed on
219
+ #
162
220
  def remove(options = {})
163
221
  self.class.remove(self.jira_key, options)
164
222
  end
@@ -12,7 +12,10 @@ module Jiralicious
12
12
  ##
13
13
  # Initialization Method
14
14
  #
15
- def initialize(decoded_json = nil, default = nil, &blk)
15
+ # [Arguments]
16
+ # :decoded_json (optional) rubyized json object
17
+ #
18
+ def initialize(decoded_json = nil)
16
19
  if (decoded_json != nil)
17
20
  properties_from_hash(decoded_json)
18
21
  super(decoded_json)
@@ -33,7 +36,10 @@ module Jiralicious
33
36
  ##
34
37
  # Retrieves the Comments based on the Issue Key
35
38
  #
36
- def find_by_key(key, options = {})
39
+ # [Arguments]
40
+ # :key (required) issue key
41
+ #
42
+ def find_by_key(key)
37
43
  response = fetch({:parent => parent_name, :parent_key => key})
38
44
  a = new(response)
39
45
  a.jira_key = key
@@ -43,7 +49,12 @@ module Jiralicious
43
49
  ##
44
50
  # Retrieves the Comment based on the Issue Key and Comment ID
45
51
  #
46
- def find_by_key_and_id(key, id, options = {})
52
+ # [Arguments]
53
+ # :key (required) issue key
54
+ #
55
+ # :id (required) comment id
56
+ #
57
+ def find_by_key_and_id(key, id)
47
58
  response = fetch({:parent => parent_name, :parent_key => key, :key => id})
48
59
  a = new(response)
49
60
  a.jira_key = key
@@ -53,6 +64,11 @@ module Jiralicious
53
64
  ##
54
65
  # Adds a new Comment to the Issue
55
66
  #
67
+ # [Arguments]
68
+ # :comment (required) comment to post
69
+ #
70
+ # :key (required) issue key
71
+ #
56
72
  def add(comment, key)
57
73
  fetch({:method => :post, :body => comment, :parent => parent_name, :parent_key => key})
58
74
  end
@@ -60,32 +76,50 @@ module Jiralicious
60
76
  ##
61
77
  # Updates a Comment based on Issue Key and Comment ID
62
78
  #
79
+ # [Arguments]
80
+ # :comment (required) comment to post
81
+ #
82
+ # :key (required) issue key
83
+ #
84
+ # :id (required) comment id
85
+ #
63
86
  def edit(comment, key, id)
64
87
  fetch({:method => :put, :key => id, :body => comment, :parent => parent_name, :parent_key => key})
65
88
  end
66
89
 
67
90
  ##
68
- # Removes/Deletes the Comment from the Jira Issue. It is not recommended to delete comments however the functionality is provided.
69
- # it is recommended to override this function to throw an error or warning
70
- # to maintain data integrity in systems that do not allow deleting from a
71
- # remote location.
91
+ # Removes/Deletes the Comment from the Jira Issue. It is
92
+ # not recommended to delete comments however the functionality
93
+ # is provided. It is recommended to override this function
94
+ # to throw an error or warning to maintain data integrity
95
+ # in systems that do not allow deleting from a remote location.
96
+ #
97
+ # [Arguments]
98
+ # :key (required) issue key
99
+ #
100
+ # :id (required) comment id
72
101
  #
73
102
  def remove(key, id)
74
103
  fetch({:method => :delete, :body_to_params => true, :key => id, :parent => parent_name, :parent_key => key})
75
-
76
104
  end
77
105
  end
78
106
 
79
107
  ##
80
108
  # Retrieves the Comment based on the loaded Issue and Comment ID
81
109
  #
82
- def find_by_id(id, options = {})
110
+ # [Arguments]
111
+ # :id (required) comment id
112
+ #
113
+ def find_by_id(id)
83
114
  self.class.find_by_key_and_id(@jira_key, id)
84
115
  end
85
116
 
86
117
  ##
87
118
  # Adds a new Comment to the loaded Issue
88
119
  #
120
+ # [Arguments]
121
+ # :comment (required) comment text
122
+ #
89
123
  def add(comment)
90
124
  self.class.add(comment, @jira_key)
91
125
  end
@@ -93,14 +127,22 @@ module Jiralicious
93
127
  ##
94
128
  # Updates a Comment based on loaded Issue and Comment
95
129
  #
130
+ # [Arguments]
131
+ # :comment (required) comment text
132
+ #
96
133
  def edit(comment)
97
134
  self.class.edit(comment, @jira_key, self.id)
98
135
  end
99
136
 
100
137
  ##
101
- # Removes/Deletes the Comment from the Jira Issue. It is not recommended to delete comments;
102
- # However, the functionality is provided. It is recommended to override this function to throw an error or
103
- # warning to maintain data integrity in systems that do not allow deleting from a remote location.
138
+ # Removes/Deletes the Comment from the Jira Issue. It is
139
+ # not recommended to delete comments. However, the functionality
140
+ # is provided. It is recommended to override this function
141
+ # to throw an error or warning to maintain data integrity
142
+ # in systems that do not allow deleting from a remote location.
143
+ #
144
+ # [Arguments]
145
+ # :id (optional) comment id
104
146
  #
105
147
  def remove(id = self.id)
106
148
  self.class.remove(@jira_key, id)
@@ -2,9 +2,11 @@
2
2
  module Jiralicious
3
3
  class Issue
4
4
  ##
5
- # The Fields class provides functionality to the Issue class that allows it to easily
6
- # update or create issues. The class retains the original and the proposed information
7
- # which could be used for cross validation prior to posting an update.
5
+ # The Fields class provides functionality to the Issue
6
+ # class that allows it to easily update or create issues.
7
+ # The class retains the original and the proposed
8
+ # information which could be used for cross validation
9
+ # prior to posting an update.
8
10
  #
9
11
  class Fields
10
12
  # The fields that will be updated or created
@@ -15,6 +17,9 @@ module Jiralicious
15
17
  ##
16
18
  # Initialization Method
17
19
  #
20
+ # [Arguments]
21
+ # :fc (optional) fields to load
22
+ #
18
23
  def initialize(fc = nil)
19
24
  @fields_current = (fc == nil) ? Hash.new : fc
20
25
  @fields_update = Hash.new
@@ -37,6 +42,9 @@ module Jiralicious
37
42
  ##
38
43
  # Adds a comment to the field list
39
44
  #
45
+ # [Arguments]
46
+ # :comment (required) comment text
47
+ #
40
48
  def add_comment(comment)
41
49
  if !(@fields_update['comment'].is_a? Array)
42
50
  @fields_update['comment'] = Array.new
@@ -47,6 +55,11 @@ module Jiralicious
47
55
  ##
48
56
  # Appends the current String with the provided value
49
57
  #
58
+ # [Arguments]
59
+ # :field (required) field to update
60
+ #
61
+ # :value (required) value text
62
+ #
50
63
  def append_s(field, value)
51
64
  if (@fields_update[field] == nil)
52
65
  @fields_update[field] = @fields_current[field] unless @fields_current.nil?
@@ -58,6 +71,11 @@ module Jiralicious
58
71
  ##
59
72
  # Appends the current Array with the provided value
60
73
  #
74
+ # [Arguments]
75
+ # :field (required) field to update
76
+ #
77
+ # :value (required) value array
78
+ #
61
79
  def append_a(field, value)
62
80
  @fields_update[field] = @fields_current[field] if (@fields_update[field] == nil)
63
81
  @fields_update[field] = Array.new if !(@fields_update[field].is_a? Array)
@@ -71,6 +89,11 @@ module Jiralicious
71
89
  ##
72
90
  # Appends the current Hash with the provided value
73
91
  #
92
+ # [Arguments]
93
+ # :field (required) field to update
94
+ #
95
+ # :value (required) value hash
96
+ #
74
97
  def append_h(field, hash)
75
98
  @fields_update[field] = @fields_current[field] if (@fields_update[field] == nil)
76
99
  @fields_update[field] = Hash.new if !(@fields_update[field].is_a? Hash)
@@ -80,6 +103,11 @@ module Jiralicious
80
103
  ##
81
104
  # Sets the field key with the provided value.
82
105
  #
106
+ # [Arguments]
107
+ # :field (required) field to update
108
+ #
109
+ # :value (required) value to add
110
+ #
83
111
  def set(field, value)
84
112
  @fields_update[field] = value
85
113
  end
@@ -88,6 +116,11 @@ module Jiralicious
88
116
  # Sets the field with a name hash.
89
117
  # This is necessary for some objects in Jira.
90
118
  #
119
+ # [Arguments]
120
+ # :field (required) field to update
121
+ #
122
+ # :value (required) value text
123
+ #
91
124
  def set_name(field, value)
92
125
  @fields_update[field] = {"name" => value}
93
126
  end
@@ -96,12 +129,20 @@ module Jiralicious
96
129
  # Sets the field with a id hash.
97
130
  # This is necessary for some objects in Jira.
98
131
  #
132
+ # [Arguments]
133
+ # :field (required) field to update
134
+ #
135
+ # :value (required) value text/int
136
+ #
99
137
  def set_id(field, value)
100
138
  @fields_update[field] = {"id" => value}
101
139
  end
102
140
  ##
103
141
  # Fills the fields_current object with the provided Hash.
104
142
  #
143
+ # [Arguments]
144
+ # :fc (optional) fields to load
145
+ #
105
146
  def set_current(fc)
106
147
  @fields_current = fc if fc.type == Hash
107
148
  end
@@ -2,8 +2,9 @@
2
2
  module Jiralicious
3
3
  class Issue
4
4
  ##
5
- # The Transitions Class provides all of the functionality to retrieve,
6
- # and use a transition associated with an Issue.
5
+ # The Transitions Class provides all of the
6
+ # functionality to retrieve, and use a transition
7
+ # associated with an Issue.
7
8
  #
8
9
  class Transitions < Jiralicious::Base
9
10
 
@@ -13,7 +14,12 @@ module Jiralicious
13
14
  ##
14
15
  # Initialization Method
15
16
  #
16
- def initialize(decoded_json = nil, default = nil, &blk)
17
+ # [Arguments]
18
+ # :decoded_json (optional) rubyized json object
19
+ #
20
+ # :default (optional) default issue key
21
+ #
22
+ def initialize(decoded_json = nil, default = nil)
17
23
  @loaded = false
18
24
  @meta = nil
19
25
  if decoded_json.is_a? Array
@@ -45,30 +51,46 @@ module Jiralicious
45
51
  ##
46
52
  # Retrieves the associated Transitions based on the Issue Key
47
53
  #
48
- def find(key, options = {})
54
+ # [Arguments]
55
+ # :key (required) issue key
56
+ #
57
+ def find(key)
49
58
  response = fetch({:parent => parent_name, :parent_key => key})
50
59
  response.parsed_response['transitions'].each do |t|
51
60
  t['jira_key'] = key
52
61
  end
53
- a = new(response.parsed_response['transitions'], key)
54
- return a
62
+ return new(response.parsed_response['transitions'], key)
55
63
  end
56
64
 
57
65
  ##
58
66
  # Retrieves the Transition based on the Issue Key and Transition ID
59
67
  #
60
- def find_by_key_and_id(key, id, options = {})
68
+ # [Arguments]
69
+ # :key (required) issue key
70
+ #
71
+ # :id (required) transition id
72
+ #
73
+ def find_by_key_and_id(key, id)
61
74
  response = fetch({:parent => parent_name, :parent_key => key, :body => {"transitionId" => id}, :body_to_params => true })
62
75
  response.parsed_response['transitions'].each do |t|
63
76
  t['jira_key'] = key
64
77
  end
65
- a = new(response.parsed_response['transitions'])
66
- return a
78
+ return new(response.parsed_response['transitions'])
67
79
  end
68
80
 
69
81
  ##
70
82
  # Processes the Transition based on the provided options
71
83
  #
84
+ # [Arguments]
85
+ # :key (required) issue key
86
+ #
87
+ # :id (required) transaction id
88
+ #
89
+ # :comment (optional) comment to be added with transition
90
+ #
91
+ # :fields (mixed) the fields that are required or optional
92
+ # based on the individual transition
93
+ #
72
94
  def go(key, id, options = {})
73
95
  transition = {"transition" => {"id" => id}}
74
96
  if options[:comment].is_a? String
@@ -90,14 +112,20 @@ module Jiralicious
90
112
  # Retrieves the meta data for the Transition based on the
91
113
  # options, Issue Key and Transition ID provided.
92
114
  #
115
+ # [Arguments]
116
+ # :key (required) issue key
117
+ #
118
+ # :id (required) transaction id
119
+ #
120
+ # :return (optional) boolean flag to determine if an object or hash is returned
121
+ #
93
122
  def meta(key, id, options = {})
94
123
  response = fetch({:method => :get, :parent => parent_name, :parent_key => key, :body_to_params => true,
95
124
  :body => {"transitionId" => id, "expand" => "transitions.fields"}})
96
125
  response.parsed_response['transitions'].each do |t|
97
126
  t['jira_key'] = key
98
127
  end
99
- a = (options[:return].nil?) ? new(response.parsed_response['transitions'], key) : response
100
- return a
128
+ return (options[:return].nil?) ? new(response.parsed_response['transitions'], key) : response
101
129
  end
102
130
 
103
131
  alias :find_all :find
@@ -113,6 +141,9 @@ module Jiralicious
113
141
  ##
114
142
  # Processes the Transition based on the provided options
115
143
  #
144
+ # [Arguments]
145
+ # :options are passed on to the 'class.go' function
146
+ #
116
147
  def go(options = {})
117
148
  self.class.go(self.jira_key, self.id, options)
118
149
  end