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.
- data/README.md +3 -0
- data/jiralicious.gemspec +0 -2
- data/lib/jiralicious.rb +4 -0
- data/lib/jiralicious/avatar.rb +101 -0
- data/lib/jiralicious/base.rb +53 -15
- data/lib/jiralicious/configuration.rb +30 -4
- data/lib/jiralicious/custom_field_option.rb +7 -3
- data/lib/jiralicious/errors.rb +10 -0
- data/lib/jiralicious/field.rb +23 -12
- data/lib/jiralicious/issue.rb +69 -11
- data/lib/jiralicious/issue/comment.rb +54 -12
- data/lib/jiralicious/issue/fields.rb +44 -3
- data/lib/jiralicious/issue/transitions.rb +42 -11
- data/lib/jiralicious/issue/watchers.rb +19 -2
- data/lib/jiralicious/parsers/field_parser.rb +12 -0
- data/lib/jiralicious/project.rb +7 -1
- data/lib/jiralicious/project/avatar.rb +126 -0
- data/lib/jiralicious/search.rb +9 -0
- data/lib/jiralicious/search_result.rb +15 -7
- data/lib/jiralicious/session.rb +5 -0
- data/lib/jiralicious/user.rb +154 -0
- data/lib/jiralicious/user/avatar.rb +130 -0
- data/lib/jiralicious/version.rb +1 -1
- data/spec/avatar_spec.rb +50 -0
- data/spec/basic_session_spec.rb +4 -0
- data/spec/comment_spec.rb +2 -2
- data/spec/fixtures/avatar.json +7 -0
- data/spec/fixtures/avatar_custom.json +16 -0
- data/spec/fixtures/avatar_list.json +16 -0
- data/spec/fixtures/avatar_temp.json +7 -0
- data/spec/fixtures/avatar_test.png +0 -0
- data/spec/fixtures/user.json +27 -0
- data/spec/fixtures/user_array.json +26 -0
- data/spec/fixtures/user_picker.json +18 -0
- data/spec/issue_spec.rb +10 -9
- data/spec/project_avatar_spec.rb +66 -0
- data/spec/project_spec.rb +2 -2
- data/spec/search_spec.rb +2 -1
- data/spec/support/http.rb +24 -0
- data/spec/user_avatar_spec.rb +66 -0
- data/spec/user_spec.rb +79 -0
- data/spec/watchers_spec.rb +2 -2
- metadata +30 -18
@@ -0,0 +1,130 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Jiralicious
|
3
|
+
class User
|
4
|
+
##
|
5
|
+
# Avatars in the Project class.
|
6
|
+
#
|
7
|
+
class Avatar < Jiralicious::Base
|
8
|
+
|
9
|
+
##
|
10
|
+
# Initialization Method
|
11
|
+
#
|
12
|
+
# [Arguments]
|
13
|
+
# :decoded_json (optional) decoded json object
|
14
|
+
#
|
15
|
+
def initialize(decoded_json = nil)
|
16
|
+
@loaded = false
|
17
|
+
if !decoded_json.nil?
|
18
|
+
if decoded_json.is_a? Hash
|
19
|
+
decoded_json = properties_from_hash(decoded_json)
|
20
|
+
super(decoded_json)
|
21
|
+
parse!(decoded_json)
|
22
|
+
self.each do |k, v|
|
23
|
+
if v.is_a? Hash
|
24
|
+
self[k] = self.class.new(v)
|
25
|
+
elsif v.is_a? Array
|
26
|
+
v.each_index do |i|
|
27
|
+
if v[i].is_a? Hash
|
28
|
+
v[i] = self.class.new(v[i])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
self[k] = v
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@loaded = true
|
35
|
+
else
|
36
|
+
i = 0;
|
37
|
+
decoded_json.each do |list|
|
38
|
+
if !list['id'].nil?
|
39
|
+
if numeric? list['id']
|
40
|
+
id = :"id_#{list['id']}"
|
41
|
+
else
|
42
|
+
id = :"#{list['id']}"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
id = :"_#{i}"
|
46
|
+
i += 1
|
47
|
+
end
|
48
|
+
self.class.property id
|
49
|
+
self[id] = self.class.new(list)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
##
|
57
|
+
# Converts the temporary avatar to a real avatar
|
58
|
+
#
|
59
|
+
# [Arguments]
|
60
|
+
# :username (required) username to change
|
61
|
+
#
|
62
|
+
# :cropperWidth (optional) width of the avatar
|
63
|
+
#
|
64
|
+
# :cropperOffsetX (optional) X offset on image
|
65
|
+
#
|
66
|
+
# :cropperOffsetY (optional) Y offset on image
|
67
|
+
#
|
68
|
+
# :needsCropping (optional) boolean if it needs cropping
|
69
|
+
#
|
70
|
+
def post(username, options = {})
|
71
|
+
options.merge!({:username => username})
|
72
|
+
response = fetch({:method => :post, :parent_uri => "#{parent_name}/", :body => options})
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Update Avatar information
|
77
|
+
#
|
78
|
+
# [Arguments]
|
79
|
+
# :username (required) project key
|
80
|
+
#
|
81
|
+
# :options (optional) not documented
|
82
|
+
#
|
83
|
+
def put(username, options = {})
|
84
|
+
options.merge!({:username => username})
|
85
|
+
response = fetch({:method => :put, :parent_uri => "#{parent_name}/", :body => options})
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Creates temporary avatar
|
90
|
+
#
|
91
|
+
# [Arguments]
|
92
|
+
# :username (required) project key
|
93
|
+
#
|
94
|
+
# :filename (optional) file to upload
|
95
|
+
#
|
96
|
+
# :size (optional) size of the file
|
97
|
+
#
|
98
|
+
def temporary(username, options = {})
|
99
|
+
options.merge!({:username => username})
|
100
|
+
response = fetch({:method => :post, :parent_uri => "#{parent_name}/", :key => 'temporary', :body => options})
|
101
|
+
return self.new(response.parsed_response)
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Deletes or removes the avatar from the project
|
106
|
+
#
|
107
|
+
# [Arguments]
|
108
|
+
# :username (required) project key
|
109
|
+
#
|
110
|
+
# :id (required) avatar id
|
111
|
+
#
|
112
|
+
def remove(username, id)
|
113
|
+
response = fetch({:method => :delete, :body_to_params => true, :parent_uri => "#{parent_name}/", :key => "#{id}", :body => {:username => username}})
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Gets a list of avatars
|
118
|
+
#
|
119
|
+
# [Arguments]
|
120
|
+
# :username (required) user name
|
121
|
+
#
|
122
|
+
def avatars(username, options = {})
|
123
|
+
options.merge!({:username => username})
|
124
|
+
response = fetch({:method => :get, :body_to_params => true, :url => "#{Jiralicious.rest_path}/#{parent_name}/#{endpoint_name}s", :body => options})
|
125
|
+
return self.new(response.parsed_response)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/jiralicious/version.rb
CHANGED
data/spec/avatar_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Jiralicious, "avatar" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Jiralicious.configure do |config|
|
8
|
+
config.username = "jstewart"
|
9
|
+
config.password = "topsecret"
|
10
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
11
|
+
config.auth_type = :basic
|
12
|
+
config.api_version = "latest"
|
13
|
+
end
|
14
|
+
|
15
|
+
FakeWeb.register_uri(:get,
|
16
|
+
"#{Jiralicious.rest_path}/avatar/user/system",
|
17
|
+
:status => "200",
|
18
|
+
:body => avatar_list_json)
|
19
|
+
FakeWeb.register_uri(:post,
|
20
|
+
"#{Jiralicious.rest_path}/avatar/user/temporary",
|
21
|
+
:status => "200",
|
22
|
+
:body => avatar_temp_json)
|
23
|
+
FakeWeb.register_uri(:post,
|
24
|
+
"#{Jiralicious.rest_path}/avatar/user/temporaryCrop",
|
25
|
+
:status => "200")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "obtain system avatar list" do
|
29
|
+
avatar = Jiralicious::Avatar.system('user')
|
30
|
+
avatar.should be_instance_of(Jiralicious::Avatar)
|
31
|
+
avatar.system.count.should == 2
|
32
|
+
avatar.system[0].id.should == '10100'
|
33
|
+
avatar.system[1].isSystemAvatar.should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sends new avatar" do
|
37
|
+
file = "#{File.dirname(__FILE__)}/fixtures/avatar_test.png"
|
38
|
+
avatar = Jiralicious::Avatar.temporary('user', {:filename => file, :size => 4035})
|
39
|
+
avatar.needsCropping.should == true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "crops the current avatar" do
|
43
|
+
response = Jiralicious::Avatar.temporary_crop('user', {:cropperWidth => 120,
|
44
|
+
:cropperOffsetX => 50,
|
45
|
+
:cropperOffsety => 50,
|
46
|
+
:needsCropping => false})
|
47
|
+
response.response.class.should == Net::HTTPOK
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/basic_session_spec.rb
CHANGED
data/spec/comment_spec.rb
CHANGED
@@ -7,8 +7,8 @@ describe Jiralicious, "search" do
|
|
7
7
|
Jiralicious.configure do |config|
|
8
8
|
config.username = "jstewart"
|
9
9
|
config.password = "topsecret"
|
10
|
-
config.uri = "http://localhost"
|
11
|
-
config.auth_type = :
|
10
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
11
|
+
config.auth_type = :basic
|
12
12
|
config.api_version = "latest"
|
13
13
|
end
|
14
14
|
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"self": "http://www.example.com/jira/rest/api/2/user?username=test_user",
|
3
|
+
"name": "test",
|
4
|
+
"emailAddress": "test_user@example.com",
|
5
|
+
"avatarUrls": {
|
6
|
+
"16x16": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=test_user",
|
7
|
+
"48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=test_user"
|
8
|
+
},
|
9
|
+
"displayName": "Test User",
|
10
|
+
"active": true,
|
11
|
+
"timeZone": "Australia/Sydney",
|
12
|
+
"groups": {
|
13
|
+
"size": 3,
|
14
|
+
"items": [
|
15
|
+
{
|
16
|
+
"name": "jira-user"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "jira-admin"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"name": "important"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
},
|
26
|
+
"expand": "groups"
|
27
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"self": "http://www.example.com/jira/rest/api/2/user?username=test_user",
|
4
|
+
"name": "test_user",
|
5
|
+
"emailAddress": "test_user@example.com",
|
6
|
+
"avatarUrls": {
|
7
|
+
"16x16": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=test_user",
|
8
|
+
"48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=test_user"
|
9
|
+
},
|
10
|
+
"displayName": "Test User",
|
11
|
+
"active": false,
|
12
|
+
"timeZone": "America/Chicago"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"self": "http://www.example.com/jira/rest/api/2/user?username=simple_user",
|
16
|
+
"name": "simple_user",
|
17
|
+
"emailAddress": "simple_user@example.com",
|
18
|
+
"avatarUrls": {
|
19
|
+
"16x16": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=simple_user",
|
20
|
+
"48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=simple_user"
|
21
|
+
},
|
22
|
+
"displayName": "Simple User",
|
23
|
+
"active": false,
|
24
|
+
"timeZone": "America/Chicago"
|
25
|
+
}
|
26
|
+
]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"users": [
|
3
|
+
{
|
4
|
+
"name": "test_user",
|
5
|
+
"html": "test_user@example.com",
|
6
|
+
"displayName": "Test User",
|
7
|
+
"avatarUrl": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=test_user"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"name": "simple_user",
|
11
|
+
"html": "simple_user@example.com",
|
12
|
+
"displayName": "Simple User",
|
13
|
+
"avatarURL": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=simple_user"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"total": 2,
|
17
|
+
"header": "Showing 2 of 25 matching groups"
|
18
|
+
}
|
data/spec/issue_spec.rb
CHANGED
@@ -7,8 +7,8 @@ describe Jiralicious::Issue, "finding" do
|
|
7
7
|
Jiralicious.configure do |config|
|
8
8
|
config.username = "jstewart"
|
9
9
|
config.password = "topsecret"
|
10
|
-
config.uri = "http://localhost"
|
11
|
-
config.auth_type = :
|
10
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
11
|
+
config.auth_type = :basic
|
12
12
|
config.api_version = "latest"
|
13
13
|
end
|
14
14
|
|
@@ -56,8 +56,8 @@ describe Jiralicious::Issue, "Managing Issues" do
|
|
56
56
|
Jiralicious.configure do |config|
|
57
57
|
config.username = "jstewart"
|
58
58
|
config.password = "topsecret"
|
59
|
-
config.uri = "http://localhost"
|
60
|
-
config.auth_type = :
|
59
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
60
|
+
config.auth_type = :basic
|
61
61
|
config.api_version = "latest"
|
62
62
|
end
|
63
63
|
|
@@ -159,8 +159,8 @@ describe Jiralicious::Issue, "Managing Issues" do
|
|
159
159
|
Jiralicious.configure do |config|
|
160
160
|
config.username = "jstewart"
|
161
161
|
config.password = "topsecret"
|
162
|
-
config.uri = "http://localhost"
|
163
|
-
config.auth_type = :
|
162
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
163
|
+
config.auth_type = :basic
|
164
164
|
config.api_version = "latest"
|
165
165
|
end
|
166
166
|
|
@@ -215,8 +215,8 @@ describe Jiralicious::Issue, "Issue Information and Field Class" do
|
|
215
215
|
Jiralicious.configure do |config|
|
216
216
|
config.username = "jstewart"
|
217
217
|
config.password = "topsecret"
|
218
|
-
config.uri = "http://localhost"
|
219
|
-
config.auth_type = :
|
218
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
219
|
+
config.auth_type = :basic
|
220
220
|
config.api_version = "latest"
|
221
221
|
end
|
222
222
|
|
@@ -281,7 +281,8 @@ describe Jiralicious::Issue, "transitions" do
|
|
281
281
|
Jiralicious.configure do |config|
|
282
282
|
config.username = "jstewart"
|
283
283
|
config.password = "topsecret"
|
284
|
-
config.uri = "http://localhost"
|
284
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
285
|
+
config.auth_type = :basic
|
285
286
|
config.api_version = "latest"
|
286
287
|
end
|
287
288
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Jiralicious, "Project Avatar" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Jiralicious.configure do |config|
|
8
|
+
config.username = "jstewart"
|
9
|
+
config.password = "topsecret"
|
10
|
+
config.uri = "http://jstewart:topsecret@localhost"
|
11
|
+
config.auth_type = :basic
|
12
|
+
config.api_version = "latest"
|
13
|
+
end
|
14
|
+
|
15
|
+
FakeWeb.register_uri(:put,
|
16
|
+
"#{Jiralicious.rest_path}/project/EX/avatar/",
|
17
|
+
:status => "204")
|
18
|
+
FakeWeb.register_uri(:post,
|
19
|
+
"#{Jiralicious.rest_path}/project/EX/avatar/",
|
20
|
+
:status => "200")
|
21
|
+
FakeWeb.register_uri(:delete,
|
22
|
+
"#{Jiralicious.rest_path}/project/EX/avatar/10100",
|
23
|
+
:status => "200")
|
24
|
+
FakeWeb.register_uri(:get,
|
25
|
+
"#{Jiralicious.rest_path}/project/EX/avatars/",
|
26
|
+
:status => "200",
|
27
|
+
:body => avatar_list_json)
|
28
|
+
FakeWeb.register_uri(:post,
|
29
|
+
"#{Jiralicious.rest_path}/project/EX/avatar/temporary",
|
30
|
+
:status => "200",
|
31
|
+
:body => avatar_temp_json)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "obtain project avatar list" do
|
35
|
+
avatar = Jiralicious::Project::Avatar.avatars('EX')
|
36
|
+
avatar.should be_instance_of(Jiralicious::Project::Avatar)
|
37
|
+
avatar.system.count.should == 2
|
38
|
+
avatar.system[0].id.should == '10100'
|
39
|
+
avatar.system[1].isSystemAvatar.should == true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sends new project avatar" do
|
43
|
+
file = "#{File.dirname(__FILE__)}/fixtures/avatar_test.png"
|
44
|
+
avatar = Jiralicious::Project::Avatar.temporary('EX', {:filename => file, :size => 4035})
|
45
|
+
avatar.needsCropping.should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "crops the current project avatar" do
|
49
|
+
response = Jiralicious::Project::Avatar.post('EX', {:cropperWidth => 120,
|
50
|
+
:cropperOffsetX => 50,
|
51
|
+
:cropperOffsety => 50,
|
52
|
+
:needsCropping => false})
|
53
|
+
response.response.class.should == Net::HTTPOK
|
54
|
+
end
|
55
|
+
|
56
|
+
it "updates current project avatar" do
|
57
|
+
response = Jiralicious::Project::Avatar.put('EX')
|
58
|
+
response.response.class.should == Net::HTTPNoContent
|
59
|
+
end
|
60
|
+
|
61
|
+
it "updates current project avatar" do
|
62
|
+
response = Jiralicious::Project::Avatar.remove('EX', 10100)
|
63
|
+
response.response.class.should == Net::HTTPOK
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|