lackac-rira 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -0
- data/VERSION.yml +4 -0
- data/lib/rira.rb +31 -0
- data/lib/rira/base.rb +77 -0
- data/lib/rira/model.rb +37 -0
- data/test/rira_test.rb +27 -0
- data/test/test_helper.rb +10 -0
- metadata +61 -0
data/README.rdoc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Rira
|
2
|
+
====
|
3
|
+
|
4
|
+
Rira is a ruby gem for interfacing Jira. Check out the Jira documentation for the {origin of the name}[http://confluence.atlassian.com/pages/viewpage.action?pageId=192544].
|
5
|
+
|
6
|
+
COPYRIGHT
|
7
|
+
=========
|
8
|
+
|
9
|
+
Copyright (c) 2008 László Bácsi. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/lib/rira.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'xmlrpc/client'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'rira', 'model')
|
5
|
+
require File.join(File.dirname(__FILE__), 'rira', 'base')
|
6
|
+
|
7
|
+
def Rira(url)
|
8
|
+
unless url =~ %r{/rpc/xmlrpc$}
|
9
|
+
url += '/' unless url[-1] == ?/
|
10
|
+
url += 'rpc/xmlrpc'
|
11
|
+
end
|
12
|
+
Rira::Client.new(url)
|
13
|
+
end
|
14
|
+
|
15
|
+
module Rira
|
16
|
+
class RPCError < StandardError
|
17
|
+
def initialize(fault_exception)
|
18
|
+
super("#{fault_exception.faultCode}: #{fault_exception.faultString}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Client
|
23
|
+
def initialize(url)
|
24
|
+
@url = url
|
25
|
+
end
|
26
|
+
|
27
|
+
def login(username, password)
|
28
|
+
Rira::Base.new(@url, username, password)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rira/base.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Rira
|
2
|
+
class Base
|
3
|
+
def initialize(url, username, password, options = {})
|
4
|
+
@url, @username, @password = url, username, password
|
5
|
+
@token = xmlrpc_client.call("jira1.login", @username, @password)
|
6
|
+
rescue XMLRPC::FaultException => e
|
7
|
+
raise RPCError.new(e)
|
8
|
+
end
|
9
|
+
|
10
|
+
def xmlrpc_client
|
11
|
+
XMLRPC::Client.new2(@url)
|
12
|
+
end
|
13
|
+
|
14
|
+
MAPPINGS = {
|
15
|
+
:projects => ['project', "getProjectsNoSchemes", "getProjects"],
|
16
|
+
:projects_no_schemes => ['project', "getProjectsNoSchemes", "getProjects"],
|
17
|
+
:components => ['component', "getComponents"],
|
18
|
+
:versions => ['version', "getVersions"],
|
19
|
+
:issue_types => ['issue_type', "getIssueTypes"],
|
20
|
+
:issue_types_for_project => ['issue_type', "getIssueTypesForProject"],
|
21
|
+
:sub_task_issue_types => ['issue_type', "getSubTaskIssueTypes"],
|
22
|
+
:sub_task_issue_types_for_project => ['issue_type', "getSubTaskIssueTypesForProject"],
|
23
|
+
:create_issue => ['issue', "createIssue"],
|
24
|
+
:update_issue => ['issue', "updateIssue"],
|
25
|
+
:issue => ['issue', "getIssue"],
|
26
|
+
:issues_from_filter => ['issue', "getIssuesFromFilter"],
|
27
|
+
:search => ['issue', "getIssuesFromTextSearch"],
|
28
|
+
:search_with_project => ['issue', "getIssuesFromTextSearchWithProject"],
|
29
|
+
:add_comment => [nil, "addComment"],
|
30
|
+
:comments => ['comment', "getComments"],
|
31
|
+
:priorities => ['priority', "getPriorities"],
|
32
|
+
:resolutions => ['resolution', "getResolutions"],
|
33
|
+
:statuses => ['status', "getStatuses"],
|
34
|
+
:favourite_filters => ['filter', "getFavouriteFilters"],
|
35
|
+
:saved_filters => ['filter', "getSavedFilters"],
|
36
|
+
:server_info => ['server_info', "getServerInfo"],
|
37
|
+
:user => ['user', "getUser"],
|
38
|
+
:logout => [nil, "logout"],
|
39
|
+
}
|
40
|
+
|
41
|
+
def method_missing(method, *args)
|
42
|
+
model, *methods = MAPPINGS[method]
|
43
|
+
|
44
|
+
super(method, *args) if methods.empty?
|
45
|
+
|
46
|
+
begin
|
47
|
+
case result = xmlrpc_client.call("jira1.#{methods.shift}", @token, *args)
|
48
|
+
when Hash
|
49
|
+
model_or_struct(model, result)
|
50
|
+
when Array
|
51
|
+
result.map do |item|
|
52
|
+
if item.is_a?(Hash)
|
53
|
+
model_or_struct(model, item)
|
54
|
+
else
|
55
|
+
item
|
56
|
+
end
|
57
|
+
end
|
58
|
+
else
|
59
|
+
result
|
60
|
+
end
|
61
|
+
rescue XMLRPC::FaultException => e
|
62
|
+
retry unless methods.empty?
|
63
|
+
raise RPCError.new(e)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def model_or_struct(model, result)
|
70
|
+
if model
|
71
|
+
Model.new(self, model, result)
|
72
|
+
else
|
73
|
+
OpenStruct.new(result)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/rira/model.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rira
|
2
|
+
class Model
|
3
|
+
ASSOCIATIONS = {
|
4
|
+
"add_comment" => ["issue", "key"],
|
5
|
+
"comments" => ["issue", "key"],
|
6
|
+
"components" => ["project", "key"],
|
7
|
+
"issues" => ["filter", "id",
|
8
|
+
"issues_from_filter"],
|
9
|
+
"search" => ["project", "keys",
|
10
|
+
"search_with_project"],
|
11
|
+
"issue_types" => ["project", "id", "issue_types_for_project"],
|
12
|
+
"sub_task_issue_types" => ["project", "id",
|
13
|
+
"sub_task_issue_types_for_project"],
|
14
|
+
"versions" => ["project", "key"],
|
15
|
+
"update" => ["issue", "key",
|
16
|
+
"update_issue"],
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(base, model, hash)
|
20
|
+
@base, @model, @attributes = base, model, hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method, *args)
|
24
|
+
method = method.to_s
|
25
|
+
if args.empty? and @attributes.has_key?(method)
|
26
|
+
@attributes[method]
|
27
|
+
elsif map = ASSOCIATIONS[method] and map.first == @model
|
28
|
+
_, att, rp = map
|
29
|
+
scope = att[-1] == ?s ? Array(@attributes[att[0..-2]]) : @attributes[att]
|
30
|
+
args.unshift(scope)
|
31
|
+
@base.send(rp || method, *args)
|
32
|
+
else
|
33
|
+
super(method.to_sym, *args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/rira_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RiraTest < Test::Unit::TestCase
|
4
|
+
JIRA_URL = "http://jira.lackac.hu"
|
5
|
+
JIRA_USER = "rubi"
|
6
|
+
JIRA_PASS = "j1r4b0t"
|
7
|
+
|
8
|
+
context "A Rira Client" do
|
9
|
+
should "be able to login with correct password" do
|
10
|
+
rira = Rira(JIRA_URL + "/rpc/xmlrpc")
|
11
|
+
assert_nothing_raised do
|
12
|
+
rira = rira.login(JIRA_USER, JIRA_PASS)
|
13
|
+
end
|
14
|
+
assert rira.instance_variable_get('@token').length > 0
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be created with the short URL (without /rpc/xmlrpc)" do
|
18
|
+
rira = Rira(JIRA_URL)
|
19
|
+
assert_nothing_raised { rira.login(JIRA_USER, JIRA_PASS) }
|
20
|
+
end
|
21
|
+
|
22
|
+
should "not get token with wrong password" do
|
23
|
+
rira = Rira(JIRA_URL)
|
24
|
+
assert_raise(Rira::RPCError) { rira.login("wrong", "authentication") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lackac-rira
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "L\xC3\xA1szl\xC3\xB3 B\xC3\xA1csi"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-04 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Nice interface for Jira, the Ruby way.
|
17
|
+
email: lackac@lackac.hu
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- VERSION.yml
|
27
|
+
- lib/rira
|
28
|
+
- lib/rira/base.rb
|
29
|
+
- lib/rira/model.rb
|
30
|
+
- lib/rira.rb
|
31
|
+
- test/rira_test.rb
|
32
|
+
- test/test_helper.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/lackac/rira
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --inline-source
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: Nice interface for Jira, the Ruby way.
|
60
|
+
test_files: []
|
61
|
+
|