jiralicious 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +44 -0
- data/jiralicious.gemspec +1 -3
- data/lib/jiralicious.rb +4 -1
- data/lib/jiralicious/basic_session.rb +7 -0
- data/lib/jiralicious/configuration.rb +3 -1
- data/lib/jiralicious/cookie_session.rb +96 -0
- data/lib/jiralicious/issue.rb +19 -27
- data/lib/jiralicious/parsers/field_parser.rb +14 -5
- data/lib/jiralicious/search.rb +12 -10
- data/lib/jiralicious/session.rb +23 -80
- data/lib/jiralicious/version.rb +1 -1
- data/spec/basic_session_spec.rb +17 -0
- data/spec/configuration_spec.rb +6 -3
- data/spec/{session_spec.rb → cookie_session_spec.rb} +25 -35
- data/spec/field_parser_spec.rb +2 -1
- data/spec/issue_spec.rb +5 -3
- data/spec/jiralicious_spec.rb +1 -1
- data/spec/search_result_spec.rb +1 -1
- data/spec/search_spec.rb +3 -2
- data/spec/support/configuration.rb +1 -0
- metadata +102 -55
- data/README.rdoc +0 -21
data/.gitignore
CHANGED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# jiralicious
|
2
|
+
|
3
|
+
## Examples:
|
4
|
+
|
5
|
+
Before doing anything, you must configure your session:
|
6
|
+
|
7
|
+
Jiralicious.configure do |config|
|
8
|
+
# Leave out username and password
|
9
|
+
config.username = "youruser"
|
10
|
+
config.password = "yourpass"
|
11
|
+
config.uri = "http://example.com/foo/bar"
|
12
|
+
config.api_version = "latest"
|
13
|
+
config.auth_type = :basic
|
14
|
+
end
|
15
|
+
|
16
|
+
Default auth type is now Basic auth. Cookie auth is still available with the
|
17
|
+
following option:
|
18
|
+
|
19
|
+
config.auth_type = :cookie
|
20
|
+
|
21
|
+
Search for issues:
|
22
|
+
|
23
|
+
result = Jiralicious.search("key = HSP-1") # Any jql can be used here
|
24
|
+
result.issues
|
25
|
+
|
26
|
+
Finding a single issue:
|
27
|
+
|
28
|
+
issue = Jiralicious::Issue.find("HSP-1")
|
29
|
+
issue.key => "HSP-1"
|
30
|
+
|
31
|
+
## Contributing to jiralicious
|
32
|
+
|
33
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
34
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
35
|
+
* Fork the project
|
36
|
+
* Start a feature/bugfix branch
|
37
|
+
* Commit and push until you are happy with your contribution
|
38
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2012 Jason Stewart. See LICENSE for
|
44
|
+
further details.
|
data/jiralicious.gemspec
CHANGED
@@ -12,10 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %Q{A Ruby library for interacting with JIRA's REST API}
|
13
13
|
s.email = "jstewart@fusionary.com"
|
14
14
|
s.authors = ["Jason Stewart"]
|
15
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
16
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
17
15
|
s.add_runtime_dependency 'httparty', '~>0.7.8'
|
18
|
-
s.add_runtime_dependency 'hashie', '~>1.1
|
16
|
+
s.add_runtime_dependency 'hashie', '~>1.1'
|
19
17
|
s.add_runtime_dependency 'json', '~>1.6.3'
|
20
18
|
s.add_development_dependency 'rspec', '~>2.6.0'
|
21
19
|
s.add_development_dependency 'fakeweb', '~>1.3.0'
|
data/lib/jiralicious.rb
CHANGED
@@ -11,6 +11,8 @@ require 'jiralicious/issue'
|
|
11
11
|
require 'jiralicious/search'
|
12
12
|
require 'jiralicious/search_result'
|
13
13
|
require 'jiralicious/session'
|
14
|
+
require 'jiralicious/basic_session'
|
15
|
+
require 'jiralicious/cookie_session'
|
14
16
|
|
15
17
|
|
16
18
|
module Jiralicious
|
@@ -18,7 +20,8 @@ module Jiralicious
|
|
18
20
|
extend self
|
19
21
|
|
20
22
|
def session
|
21
|
-
|
23
|
+
session_type = "#{self.auth_type.to_s.capitalize}Session"
|
24
|
+
@session ||= Jiralicious.const_get(session_type).new
|
22
25
|
end
|
23
26
|
|
24
27
|
def rest_path
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module Jiralicious
|
4
4
|
module Configuration
|
5
|
-
VALID_OPTIONS = [:username, :password, :uri, :api_version]
|
5
|
+
VALID_OPTIONS = [:username, :password, :uri, :api_version, :auth_type]
|
6
6
|
DEFAULT_USERNAME = nil
|
7
|
+
DEFAULT_AUTH_TYPE = :basic
|
7
8
|
DEFAULT_PASSWORD = nil
|
8
9
|
DEFAULT_URI = nil
|
9
10
|
DEFAULT_API_VERSION = "latest"
|
@@ -30,6 +31,7 @@ module Jiralicious
|
|
30
31
|
self.password = DEFAULT_PASSWORD
|
31
32
|
self.uri = DEFAULT_URI
|
32
33
|
self.api_version = DEFAULT_API_VERSION
|
34
|
+
self.auth_type = DEFAULT_AUTH_TYPE
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Jiralicious
|
4
|
+
class CookieSession < Session
|
5
|
+
attr_accessor :authenticating, :session, :login_info
|
6
|
+
|
7
|
+
def alive?
|
8
|
+
@session && @login_info
|
9
|
+
end
|
10
|
+
|
11
|
+
def before_request
|
12
|
+
self.login if require_login? && !@authenticating
|
13
|
+
end
|
14
|
+
|
15
|
+
def after_request(response)
|
16
|
+
unless @authenticating
|
17
|
+
if captcha_required(response)
|
18
|
+
raise Jiralicious::CaptchaRequired.
|
19
|
+
new("Captacha is required. Try logging into Jira via the web interface")
|
20
|
+
elsif cookie_invalid(response)
|
21
|
+
# Can usually be fixed by logging in again
|
22
|
+
clear_session
|
23
|
+
raise Jiralicious::CookieExpired
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@authenticating = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def login
|
30
|
+
@authenticating = true
|
31
|
+
handler = Proc.new do |response|
|
32
|
+
if response.code == 200
|
33
|
+
@session = response["session"]
|
34
|
+
@login_info = response["loginInfo"]
|
35
|
+
self.class.cookies({self.session["name"] => self.session["value"]})
|
36
|
+
else
|
37
|
+
clear_session
|
38
|
+
case response.code
|
39
|
+
when 401 then
|
40
|
+
raise Jiralicious::InvalidLogin.new("Invalid login")
|
41
|
+
when 403
|
42
|
+
raise Jiralicious::CaptchaRequired.new("Captacha is required. Try logging into Jira via the web interface")
|
43
|
+
else
|
44
|
+
# Give Net::HTTP reason
|
45
|
+
raise Jiralicious::JiraError.new(response)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
self.request(:post, '/rest/auth/latest/session',
|
51
|
+
:body => { :username => Jiralicious.username,
|
52
|
+
:password => Jiralicious.password}.to_json,
|
53
|
+
:handler => handler)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def logout
|
58
|
+
handler = Proc.new do |request|
|
59
|
+
if response.code == 204
|
60
|
+
clear_session
|
61
|
+
else
|
62
|
+
case response.code
|
63
|
+
when 401 then
|
64
|
+
raise Jiralicious::NotLoggedIn.new("Not logged in")
|
65
|
+
else
|
66
|
+
# Give Net::HTTP reason
|
67
|
+
raise Jiralicious::JiraError.new(response)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
request(:delete, '/rest/auth/latest/session', :handler => handler)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def captcha_required(response)
|
78
|
+
response.code == 401 &&
|
79
|
+
# Fakeweb lowercases headers automatically. :(
|
80
|
+
(response.headers["X-Seraph-LoginReason"] == "AUTHENTICATION_DENIED" ||
|
81
|
+
response.headers["x-seraph-loginreason"] == "AUTHENTICATION_DENIED")
|
82
|
+
end
|
83
|
+
|
84
|
+
def cookie_invalid(response)
|
85
|
+
response.code == 401 && response.body =~ /cookie/i
|
86
|
+
end
|
87
|
+
|
88
|
+
def require_login?
|
89
|
+
!(Jiralicious.username.empty? && Jiralicious.password.empty?) && !alive?
|
90
|
+
end
|
91
|
+
|
92
|
+
def clear_session
|
93
|
+
@session = @login_info = nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/jiralicious/issue.rb
CHANGED
@@ -8,6 +8,7 @@ module Jiralicious
|
|
8
8
|
property :jira_self, :from => :self
|
9
9
|
property :fields
|
10
10
|
property :transitions
|
11
|
+
property :id
|
11
12
|
|
12
13
|
def initialize(decoded_json, default = nil, &blk)
|
13
14
|
super(decoded_json)
|
@@ -15,42 +16,33 @@ module Jiralicious
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.find(key, options = {})
|
18
|
-
response = Jiralicious.session.
|
19
|
-
Jiralicious::Session.get("#{Jiralicious.rest_path}/issue/#{key}")
|
20
|
-
end
|
21
|
-
|
22
|
-
if response.code == 200
|
23
|
-
response = JSON.parse(response.body)
|
24
|
-
else
|
25
|
-
raise Jiralicious::IssueNotFound
|
26
|
-
end
|
27
|
-
|
19
|
+
response = Jiralicious.session.request(:get, "#{Jiralicious.rest_path}/issue/#{key}", :handler => handler)
|
28
20
|
new(response)
|
29
21
|
end
|
30
22
|
|
31
23
|
def self.get_transitions(transitions_url)
|
32
|
-
|
33
|
-
Jiralicious::Session.get(transitions_url)
|
34
|
-
end
|
35
|
-
JSON.parse(response.body)
|
24
|
+
Jiralicious.session.request(:get, transitions_url, :handler => handler)
|
36
25
|
end
|
37
26
|
|
38
27
|
def self.transition(transitions_url, data)
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
Jiralicious.session.request(:post, transitions_url,
|
29
|
+
:handler => handler,
|
30
|
+
:body => data.to_json)
|
31
|
+
end
|
42
32
|
|
43
|
-
|
44
|
-
|
45
|
-
response.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
33
|
+
def self.handler
|
34
|
+
Proc.new do |response|
|
35
|
+
case response.code
|
36
|
+
when 200..204
|
37
|
+
response
|
38
|
+
when 400
|
39
|
+
raise Jiralicious::TransitionError.new(response['errorMessages'].join('\n'))
|
40
|
+
when 404
|
41
|
+
raise Jiralicious::IssueNotFound.new(response['errorMessages'].join('\n'))
|
42
|
+
else
|
43
|
+
raise Jiralicious::JiraError.new(response['errorMessages'].join('\n'))
|
44
|
+
end
|
52
45
|
end
|
53
46
|
end
|
54
|
-
|
55
47
|
end
|
56
48
|
end
|
@@ -10,11 +10,14 @@ module Jiralicious
|
|
10
10
|
singleton = class << self; self end
|
11
11
|
|
12
12
|
fields.each do |field, details|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
if details.is_a?(Hash)
|
14
|
+
next if details["name"].nil?
|
15
|
+
method_value = mashify(details["value"])
|
16
|
+
method_name = normalize(details["name"])
|
17
|
+
else
|
18
|
+
method_value = mashify(details)
|
19
|
+
method_name = normalize(field)
|
20
|
+
end
|
18
21
|
|
19
22
|
if singleton.method_defined?(method_name)
|
20
23
|
method_name = "jira_#{method_name}"
|
@@ -29,6 +32,12 @@ module Jiralicious
|
|
29
32
|
|
30
33
|
private
|
31
34
|
|
35
|
+
def normalize(name)
|
36
|
+
name.gsub(/(\w+)([A-Z].*)/, '\1_\2').
|
37
|
+
gsub(/\W/, "_").
|
38
|
+
downcase
|
39
|
+
end
|
40
|
+
|
32
41
|
def mashify(data)
|
33
42
|
if data.is_a?(Array)
|
34
43
|
data.map { |d| mashify(d) }
|
data/lib/jiralicious/search.rb
CHANGED
@@ -10,17 +10,19 @@ module Jiralicious
|
|
10
10
|
:maxResults => options[:max_results]
|
11
11
|
}.to_json
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
handler = Proc.new do |response|
|
14
|
+
if response.code == 200
|
15
|
+
Jiralicious::SearchResult.new(response)
|
16
|
+
else
|
17
|
+
raise Jiralicious::JqlError.new(response['errorMessages'].join('\n'))
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
Jiralicious.session.request(
|
22
|
+
:post,
|
23
|
+
"#{Jiralicious.rest_path}/search",
|
24
|
+
:body => request_body,
|
25
|
+
:handler => handler
|
26
|
+
)
|
25
27
|
end
|
26
28
|
end
|
data/lib/jiralicious/session.rb
CHANGED
@@ -4,97 +4,40 @@ require 'jiralicious/configuration'
|
|
4
4
|
module Jiralicious
|
5
5
|
class Session
|
6
6
|
include HTTParty
|
7
|
-
attr_accessor :session, :login_info
|
8
|
-
headers 'Content-Type' => 'application/json'
|
9
|
-
|
10
|
-
def alive?
|
11
|
-
@session && @login_info
|
12
|
-
end
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
self.class.post('/rest/auth/latest/session',
|
17
|
-
:body => {
|
18
|
-
:username => Jiralicious.username,
|
19
|
-
:password => Jiralicious.password}.to_json)
|
20
|
-
end
|
8
|
+
format :json
|
9
|
+
headers 'Content-Type' => 'application/json'
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@login_info = response["loginInfo"]
|
26
|
-
self.class.cookies({self.session["name"] => self.session["value"]})
|
11
|
+
def request(method, *options)
|
12
|
+
if options.last.is_a?(Hash) && options.last[:handler]
|
13
|
+
response_handler = options.last.delete(:handler)
|
27
14
|
else
|
28
|
-
|
29
|
-
case response.code
|
30
|
-
when 401 then
|
31
|
-
raise Jiralicious::InvalidLogin.new("Invalid login")
|
32
|
-
when 403
|
33
|
-
raise Jiralicious::CaptchaRequired.new("Captacha is required. Try logging into Jira via the web interface")
|
34
|
-
else
|
35
|
-
# Give Net::HTTP reason
|
36
|
-
raise Jiralicious::JiraError.new(response.response.message)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def logout
|
42
|
-
response = perform_request do
|
43
|
-
self.class.delete('/rest/auth/latest/session')
|
15
|
+
response_handler = handler
|
44
16
|
end
|
45
17
|
|
46
|
-
if response.code == 204
|
47
|
-
clear_session
|
48
|
-
else
|
49
|
-
case response.code
|
50
|
-
when 401 then
|
51
|
-
raise Jiralicious::NotLoggedIn.new("Not logged in")
|
52
|
-
else
|
53
|
-
# Give Net::HTTP reason
|
54
|
-
raise Jiralicious::JiraError.new(response.response.message)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def perform_request(options = {}, &block)
|
60
18
|
self.class.base_uri Jiralicious.uri
|
61
|
-
|
19
|
+
before_request if respond_to?(:before_request)
|
20
|
+
response = self.class.send(method, *options)
|
21
|
+
after_request(response) if respond_to?(:after_request)
|
62
22
|
|
63
|
-
|
64
|
-
unless options[:authenticating]
|
65
|
-
if captcha_required(response)
|
66
|
-
raise Jiralicious::CaptchaRequired.
|
67
|
-
new("Captacha is required. Try logging into Jira via the web interface")
|
68
|
-
elsif cookie_invalid(response)
|
69
|
-
# Can usually be fixed by logging in again
|
70
|
-
clear_session
|
71
|
-
self.login
|
72
|
-
response = block.call
|
73
|
-
raise Jiralicious::CookieExpired if cookie_invalid(response)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
response
|
23
|
+
response_handler.call(response)
|
77
24
|
end
|
78
25
|
|
79
26
|
private
|
80
27
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
def clear_session
|
97
|
-
@session = @login_info = nil
|
28
|
+
def handler
|
29
|
+
Proc.new do |response|
|
30
|
+
case response
|
31
|
+
when 200..204
|
32
|
+
response.body
|
33
|
+
else
|
34
|
+
message = response.body
|
35
|
+
if message.is_a?(Hash)
|
36
|
+
message = message['errorMessages'].join('\n')
|
37
|
+
end
|
38
|
+
Jiralicious::JiraError.new(message)
|
39
|
+
end
|
40
|
+
end
|
98
41
|
end
|
99
42
|
end
|
100
43
|
end
|
data/lib/jiralicious/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe "performing a request" do
|
5
|
+
before :each do
|
6
|
+
FakeWeb.register_uri(:get,
|
7
|
+
Jiralicious.uri + '/ok',
|
8
|
+
:status => "200")
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:session) { Jiralicious::BasicSession.new }
|
12
|
+
|
13
|
+
it "sets the basic auth info beforehand" do
|
14
|
+
Jiralicious::BasicSession.should_receive(:basic_auth).with("jstewart", "topsecret")
|
15
|
+
session.request(:get, '/ok')
|
16
|
+
end
|
17
|
+
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe Jiralicious::Configuration do
|
5
5
|
before :each do
|
@@ -11,6 +11,7 @@ describe Jiralicious::Configuration do
|
|
11
11
|
Jiralicious.password.should be_nil
|
12
12
|
Jiralicious.uri.should be_nil
|
13
13
|
Jiralicious.api_version.should == "latest"
|
14
|
+
Jiralicious.auth_type.should == :basic
|
14
15
|
end
|
15
16
|
|
16
17
|
it "allows setting of options in a block" do
|
@@ -19,11 +20,13 @@ describe Jiralicious::Configuration do
|
|
19
20
|
config.password = "derp"
|
20
21
|
config.uri = "http://example.com/foo/bar"
|
21
22
|
config.api_version = "2.0aplha"
|
23
|
+
config.auth_type = :cookie_session
|
22
24
|
end
|
23
25
|
|
24
26
|
Jiralicious.username.should == "jstewart"
|
25
27
|
Jiralicious.password.should == "derp"
|
26
|
-
Jiralicious.uri
|
27
|
-
Jiralicious.api_version
|
28
|
+
Jiralicious.uri.should == "http://example.com/foo/bar"
|
29
|
+
Jiralicious.api_version.should == "2.0aplha"
|
30
|
+
Jiralicious.auth_type.should == :cookie_session
|
28
31
|
end
|
29
32
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
|
-
describe Jiralicious::
|
4
|
+
describe Jiralicious::CookieSession, "when logging in" do
|
5
5
|
context "successfully" do
|
6
6
|
before :each do
|
7
7
|
register_login
|
8
|
-
@session = Jiralicious::
|
8
|
+
@session = Jiralicious::CookieSession.new
|
9
9
|
@session.login
|
10
10
|
end
|
11
11
|
|
@@ -32,7 +32,7 @@ describe Jiralicious::Session, "when logging in" do
|
|
32
32
|
FakeWeb.register_uri(:post,
|
33
33
|
Jiralicious.uri + '/rest/auth/latest/session',
|
34
34
|
:status => ["401", "Not Authorized"])
|
35
|
-
@session = Jiralicious::
|
35
|
+
@session = Jiralicious::CookieSession.new
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises the correct exception" do
|
@@ -59,7 +59,7 @@ describe Jiralicious::Session, "when logging in" do
|
|
59
59
|
FakeWeb.register_uri(:post,
|
60
60
|
Jiralicious.uri + '/rest/auth/latest/session',
|
61
61
|
:status => ["403", "Captcha Required"])
|
62
|
-
@session = Jiralicious::
|
62
|
+
@session = Jiralicious::CookieSession.new
|
63
63
|
end
|
64
64
|
|
65
65
|
it "raises an exception" do
|
@@ -80,8 +80,9 @@ describe Jiralicious::Session, "when logging in" do
|
|
80
80
|
before :each do
|
81
81
|
FakeWeb.register_uri(:post,
|
82
82
|
Jiralicious.uri + '/rest/auth/latest/session',
|
83
|
+
:body => "Internal Server Error",
|
83
84
|
:status => ["500", "Internal Server Error"])
|
84
|
-
@session = Jiralicious::
|
85
|
+
@session = Jiralicious::CookieSession.new
|
85
86
|
end
|
86
87
|
|
87
88
|
it "raises an exception" do
|
@@ -107,10 +108,10 @@ describe Jiralicious::Session, "when logging in" do
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
describe Jiralicious::
|
111
|
+
describe Jiralicious::CookieSession, "when logging out" do
|
111
112
|
before :each do
|
112
113
|
register_login
|
113
|
-
@session = Jiralicious::
|
114
|
+
@session = Jiralicious::CookieSession.new
|
114
115
|
@session.login
|
115
116
|
@session.should be_alive
|
116
117
|
FakeWeb.register_uri(:delete,
|
@@ -130,7 +131,7 @@ describe Jiralicious::Session, "when logging out" do
|
|
130
131
|
|
131
132
|
context "when not logged in" do
|
132
133
|
before :each do
|
133
|
-
@session = Jiralicious::
|
134
|
+
@session = Jiralicious::CookieSession.new
|
134
135
|
FakeWeb.register_uri(:delete,
|
135
136
|
Jiralicious.uri + '/rest/auth/latest/session',
|
136
137
|
:status => ["401", "Not Authorized"])
|
@@ -143,7 +144,7 @@ describe Jiralicious::Session, "when logging out" do
|
|
143
144
|
|
144
145
|
context "with any other HTTP error" do
|
145
146
|
before :each do
|
146
|
-
@session = Jiralicious::
|
147
|
+
@session = Jiralicious::CookieSession.new
|
147
148
|
FakeWeb.register_uri(:delete,
|
148
149
|
Jiralicious.uri + '/rest/auth/latest/session',
|
149
150
|
:status => ["500", "Internal Server Error"])
|
@@ -164,7 +165,7 @@ describe Jiralicious::Session, "when logging out" do
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
167
|
-
describe Jiralicious::
|
168
|
+
describe Jiralicious::CookieSession, "performing a request" do
|
168
169
|
include ConfigurationHelper
|
169
170
|
include LoginHelper
|
170
171
|
|
@@ -176,29 +177,25 @@ describe Jiralicious::Session, "performing a request" do
|
|
176
177
|
|
177
178
|
context "when login is required" do
|
178
179
|
before :each do
|
179
|
-
@session = Jiralicious::
|
180
|
+
@session = Jiralicious::CookieSession.new
|
180
181
|
@session.stub!(:require_login?).and_return(true)
|
181
182
|
end
|
182
183
|
|
183
184
|
it "attempts to log in beforehand" do
|
184
185
|
@session.should_receive(:login)
|
185
|
-
@session.
|
186
|
-
Jiralicious::Session.get('/fake/uri')
|
187
|
-
end
|
186
|
+
@session.request(:get, '/fake/uri')
|
188
187
|
end
|
189
188
|
end
|
190
189
|
|
191
190
|
context "when login is not required" do
|
192
191
|
before :each do
|
193
|
-
@session = Jiralicious::
|
192
|
+
@session = Jiralicious::CookieSession.new
|
194
193
|
@session.stub!(:require_login?).and_return(false)
|
195
194
|
end
|
196
195
|
|
197
196
|
it "doesn't try to log in before making the request" do
|
198
197
|
@session.should_receive(:login).never
|
199
|
-
@session.
|
200
|
-
Jiralicious::Session.get('/fake/uri')
|
201
|
-
end
|
198
|
+
@session.request(:get, '/fake/uri')
|
202
199
|
end
|
203
200
|
end
|
204
201
|
end
|
@@ -218,21 +215,18 @@ describe "performing a request with a successful response" do
|
|
218
215
|
register_login
|
219
216
|
end
|
220
217
|
|
221
|
-
let(:session) { Jiralicious::
|
218
|
+
let(:session) { Jiralicious::CookieSession.new }
|
222
219
|
|
223
220
|
it "returns the response on ok" do
|
224
|
-
|
225
|
-
r.class.should == HTTParty::Response
|
221
|
+
session.request(:get, '/ok').class.should == HTTParty::Response
|
226
222
|
end
|
227
223
|
|
228
224
|
it "returns the response on created" do
|
229
|
-
|
230
|
-
r.class.should == HTTParty::Response
|
225
|
+
session.request(:post, '/created').class.should == HTTParty::Response
|
231
226
|
end
|
232
227
|
|
233
228
|
it "returns the response on no content" do
|
234
|
-
|
235
|
-
r.class.should == HTTParty::Response
|
229
|
+
session.request(:delete, '/nocontent').class.should == HTTParty::Response
|
236
230
|
end
|
237
231
|
end
|
238
232
|
|
@@ -251,28 +245,24 @@ describe "performing a request with an unsuccessful response" do
|
|
251
245
|
register_login
|
252
246
|
end
|
253
247
|
|
254
|
-
let(:session) { Jiralicious::
|
248
|
+
let(:session) { Jiralicious::CookieSession.new }
|
255
249
|
|
256
|
-
it "
|
257
|
-
session.should_receive(:login).twice
|
258
|
-
session.perform_request { Jiralicious::Session.get('/cookie_expired') }
|
259
|
-
end
|
260
|
-
|
261
|
-
it "raises an exception when retried and failed" do
|
250
|
+
it "raises an exception when cookie invalid" do
|
262
251
|
FakeWeb.register_uri(:get,
|
263
252
|
Jiralicious.uri + '/cookie_expired',
|
264
253
|
[
|
265
254
|
{:status => "401", :body => "Cookie Expired"},
|
266
255
|
{:status => "401", :body => "Cookie Expired"}
|
267
256
|
])
|
257
|
+
|
268
258
|
lambda {
|
269
|
-
session.
|
259
|
+
session.request(:get, '/cookie_expired')
|
270
260
|
}.should raise_error(Jiralicious::CookieExpired)
|
271
261
|
end
|
272
262
|
|
273
263
|
it "raises an exception when the captcha is required" do
|
274
264
|
lambda {
|
275
|
-
session.
|
265
|
+
session.request(:get, '/captcha_needed')
|
276
266
|
}.should raise_error(Jiralicious::CaptchaRequired)
|
277
267
|
end
|
278
268
|
end
|
data/spec/field_parser_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
class ParserMock
|
5
5
|
include Jiralicious::Parsers::FieldParser
|
@@ -14,6 +14,7 @@ describe Jiralicious::Parsers::FieldParser do
|
|
14
14
|
before :each do
|
15
15
|
@parsed_data = {
|
16
16
|
"testfield" => {"name" => "testfield", "value" => "Test Data"},
|
17
|
+
"without_hash" => "test",
|
17
18
|
"methods" => {"name" => "methods", "value" => "Test Data 2"},
|
18
19
|
"testField" => {"name" => "testField", "value" => "Test Data 3"},
|
19
20
|
"test_field_dash" => {"name" => "test-field-dash", "value" => "Test Data 4"},
|
data/spec/issue_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe Jiralicious::Issue, "finding" do
|
5
5
|
|
@@ -8,6 +8,7 @@ describe Jiralicious::Issue, "finding" do
|
|
8
8
|
config.username = "jstewart"
|
9
9
|
config.password = "topsecret"
|
10
10
|
config.uri = "http://localhost"
|
11
|
+
config.auth_type = :cookie
|
11
12
|
config.api_version = "latest"
|
12
13
|
end
|
13
14
|
|
@@ -26,6 +27,7 @@ describe Jiralicious::Issue, "finding" do
|
|
26
27
|
lambda {
|
27
28
|
FakeWeb.register_uri(:get,
|
28
29
|
"#{Jiralicious.rest_path}/issue/EX-1",
|
30
|
+
:body => "{errorMessages: ['error']}",
|
29
31
|
:status => ["404" "Not Found"])
|
30
32
|
Jiralicious::Issue.find("EX-1")
|
31
33
|
}.should raise_error(Jiralicious::IssueNotFound)
|
@@ -69,7 +71,7 @@ describe Jiralicious::Issue, "transitions" do
|
|
69
71
|
|
70
72
|
result = Jiralicious::Issue.transition("#{Jiralicious.rest_path}/issue/EX-1/transitions",
|
71
73
|
{"transition" => "3", "fields" => []})
|
72
|
-
result.should
|
74
|
+
result.should be_nil
|
73
75
|
end
|
74
76
|
|
75
77
|
it "raises an exception on transition failure" do
|
@@ -93,4 +95,4 @@ describe Jiralicious::Issue, "transitions" do
|
|
93
95
|
{"transition" => "invalid"})
|
94
96
|
}.should raise_error(Jiralicious::IssueNotFound)
|
95
97
|
end
|
96
|
-
end
|
98
|
+
end
|
data/spec/jiralicious_spec.rb
CHANGED
data/spec/search_result_spec.rb
CHANGED
data/spec/search_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
|
-
describe Jiralicious, "search"
|
4
|
+
describe Jiralicious, "search" do
|
5
5
|
|
6
6
|
before :each do
|
7
7
|
Jiralicious.configure do |config|
|
@@ -31,6 +31,7 @@ describe Jiralicious, "search", do
|
|
31
31
|
before :each do
|
32
32
|
FakeWeb.register_uri(:post,
|
33
33
|
"#{Jiralicious.rest_path}/search",
|
34
|
+
:body => "{errorMessages: ['error']}",
|
34
35
|
:status => "400")
|
35
36
|
end
|
36
37
|
|
metadata
CHANGED
@@ -1,88 +1,124 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jiralicious
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jason Stewart
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-11-01 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: httparty
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
26
|
+
requirements:
|
19
27
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
- 8
|
21
34
|
version: 0.7.8
|
22
35
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
26
38
|
name: hashie
|
27
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
41
|
none: false
|
29
|
-
requirements:
|
42
|
+
requirements:
|
30
43
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 1
|
49
|
+
version: "1.1"
|
33
50
|
type: :runtime
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
37
53
|
name: json
|
38
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
56
|
none: false
|
40
|
-
requirements:
|
57
|
+
requirements:
|
41
58
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 9
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 6
|
64
|
+
- 3
|
43
65
|
version: 1.6.3
|
44
66
|
type: :runtime
|
45
|
-
|
46
|
-
|
47
|
-
- !ruby/object:Gem::Dependency
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
48
69
|
name: rspec
|
49
|
-
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
72
|
none: false
|
51
|
-
requirements:
|
73
|
+
requirements:
|
52
74
|
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 23
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 6
|
80
|
+
- 0
|
54
81
|
version: 2.6.0
|
55
82
|
type: :development
|
56
|
-
|
57
|
-
|
58
|
-
- !ruby/object:Gem::Dependency
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
59
85
|
name: fakeweb
|
60
|
-
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
88
|
none: false
|
62
|
-
requirements:
|
89
|
+
requirements:
|
63
90
|
- - ~>
|
64
|
-
- !ruby/object:Gem::Version
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 27
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 3
|
96
|
+
- 0
|
65
97
|
version: 1.3.0
|
66
98
|
type: :development
|
67
|
-
|
68
|
-
version_requirements: *2161586140
|
99
|
+
version_requirements: *id005
|
69
100
|
description: A Ruby library for interacting with JIRA's REST API
|
70
101
|
email: jstewart@fusionary.com
|
71
102
|
executables: []
|
103
|
+
|
72
104
|
extensions: []
|
105
|
+
|
73
106
|
extra_rdoc_files: []
|
74
|
-
|
107
|
+
|
108
|
+
files:
|
75
109
|
- .document
|
76
110
|
- .gitignore
|
77
111
|
- .rspec
|
78
112
|
- .rvmrc
|
79
113
|
- Gemfile
|
80
114
|
- LICENSE
|
81
|
-
- README.
|
115
|
+
- README.md
|
82
116
|
- Rakefile
|
83
117
|
- jiralicious.gemspec
|
84
118
|
- lib/jiralicious.rb
|
119
|
+
- lib/jiralicious/basic_session.rb
|
85
120
|
- lib/jiralicious/configuration.rb
|
121
|
+
- lib/jiralicious/cookie_session.rb
|
86
122
|
- lib/jiralicious/errors.rb
|
87
123
|
- lib/jiralicious/issue.rb
|
88
124
|
- lib/jiralicious/parsers/field_parser.rb
|
@@ -90,7 +126,9 @@ files:
|
|
90
126
|
- lib/jiralicious/search_result.rb
|
91
127
|
- lib/jiralicious/session.rb
|
92
128
|
- lib/jiralicious/version.rb
|
129
|
+
- spec/basic_session_spec.rb
|
93
130
|
- spec/configuration_spec.rb
|
131
|
+
- spec/cookie_session_spec.rb
|
94
132
|
- spec/field_parser_spec.rb
|
95
133
|
- spec/fixtures/issue.json
|
96
134
|
- spec/fixtures/search.json
|
@@ -99,37 +137,47 @@ files:
|
|
99
137
|
- spec/jiralicious_spec.rb
|
100
138
|
- spec/search_result_spec.rb
|
101
139
|
- spec/search_spec.rb
|
102
|
-
- spec/session_spec.rb
|
103
140
|
- spec/spec_helper.rb
|
104
141
|
- spec/support/configuration.rb
|
105
142
|
- spec/support/http.rb
|
143
|
+
has_rdoc: true
|
106
144
|
homepage: http://github.com/jstewart/jiralicious
|
107
|
-
licenses:
|
145
|
+
licenses:
|
108
146
|
- MIT
|
109
147
|
post_install_message:
|
110
148
|
rdoc_options: []
|
111
|
-
|
149
|
+
|
150
|
+
require_paths:
|
112
151
|
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
153
|
none: false
|
115
|
-
requirements:
|
116
|
-
- -
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
|
119
|
-
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
162
|
none: false
|
121
|
-
requirements:
|
122
|
-
- -
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
125
170
|
requirements: []
|
171
|
+
|
126
172
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.4.2
|
128
174
|
signing_key:
|
129
175
|
specification_version: 3
|
130
176
|
summary: A Ruby library for interacting with JIRA's REST API
|
131
|
-
test_files:
|
177
|
+
test_files:
|
178
|
+
- spec/basic_session_spec.rb
|
132
179
|
- spec/configuration_spec.rb
|
180
|
+
- spec/cookie_session_spec.rb
|
133
181
|
- spec/field_parser_spec.rb
|
134
182
|
- spec/fixtures/issue.json
|
135
183
|
- spec/fixtures/search.json
|
@@ -138,7 +186,6 @@ test_files:
|
|
138
186
|
- spec/jiralicious_spec.rb
|
139
187
|
- spec/search_result_spec.rb
|
140
188
|
- spec/search_spec.rb
|
141
|
-
- spec/session_spec.rb
|
142
189
|
- spec/spec_helper.rb
|
143
190
|
- spec/support/configuration.rb
|
144
191
|
- spec/support/http.rb
|
data/README.rdoc
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
= jiralicious
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
TODO: Add something useful here.
|
6
|
-
|
7
|
-
== Contributing to jiralicious
|
8
|
-
|
9
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
10
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
11
|
-
* Fork the project
|
12
|
-
* Start a feature/bugfix branch
|
13
|
-
* Commit and push until you are happy with your contribution
|
14
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
-
|
17
|
-
== Copyright
|
18
|
-
|
19
|
-
Copyright (c) 2010 Jason Stewart. See LICENSE for
|
20
|
-
further details.
|
21
|
-
|