jira-ruby 0.0.3 → 0.0.4
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/Gemfile +0 -1
- data/README.rdoc +18 -6
- data/jira-ruby.gemspec +1 -0
- data/lib/jira.rb +1 -0
- data/lib/jira/base.rb +4 -1
- data/lib/jira/client.rb +17 -9
- data/lib/jira/http_error.rb +1 -1
- data/lib/jira/railtie.rb +10 -0
- data/lib/jira/version.rb +1 -1
- data/lib/tasks/generate.rake +4 -2
- data/spec/jira/base_spec.rb +2 -2
- data/spec/jira/client_spec.rb +11 -10
- data/spec/jira/resource/issue_spec.rb +4 -4
- metadata +28 -16
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -76,8 +76,21 @@ The gem requires the consumer key and public certificate file (which
|
|
76
76
|
are generated in their respective rake tasks) to initialize an access token for
|
77
77
|
using the JIRA API.
|
78
78
|
|
79
|
+
Note that currently the rake task which generates the public certificate
|
80
|
+
requires OpenSSL to be installed on the machine.
|
81
|
+
|
79
82
|
Below is an example for setting up a rails application for OAuth authorization.
|
80
83
|
|
84
|
+
Ensure the JIRA gem is loaded correctly
|
85
|
+
|
86
|
+
# Gemfile
|
87
|
+
...
|
88
|
+
gem 'jira-ruby', :require => 'jira'
|
89
|
+
...
|
90
|
+
|
91
|
+
Add common methods to your application controller and ensure access token
|
92
|
+
errors are handled gracefully
|
93
|
+
|
81
94
|
# app/controllers/application_controller.rb
|
82
95
|
class ApplicationController < ActionController::Base
|
83
96
|
protect_from_forgery
|
@@ -107,8 +120,6 @@ Below is an example for setting up a rails application for OAuth authorization.
|
|
107
120
|
Create a controller for handling the OAuth conversation.
|
108
121
|
|
109
122
|
# app/controllers/jira_sessions_controller.rb
|
110
|
-
require 'jira'
|
111
|
-
|
112
123
|
class JiraSessionsController < ApplicationController
|
113
124
|
|
114
125
|
before_filter :get_jira_client
|
@@ -173,12 +184,13 @@ Here's the same example as a Sinatra application:
|
|
173
184
|
before do
|
174
185
|
options = {
|
175
186
|
:site => 'http://localhost:2990',
|
187
|
+
:context_path => '/jira',
|
176
188
|
:signature_method => 'RSA-SHA1',
|
177
|
-
:request_token_path => "/
|
178
|
-
:authorize_path => "/
|
179
|
-
:access_token_path => "/
|
189
|
+
:request_token_path => "/plugins/servlet/oauth/request-token",
|
190
|
+
:authorize_path => "/plugins/servlet/oauth/authorize",
|
191
|
+
:access_token_path => "/plugins/servlet/oauth/access-token",
|
180
192
|
:private_key_file => "rsakey.pem",
|
181
|
-
:rest_base_path => "/
|
193
|
+
:rest_base_path => "/rest/api/2"
|
182
194
|
}
|
183
195
|
|
184
196
|
@jira_client = JIRA::Client.new('jira-ruby-example', '', options)
|
data/jira-ruby.gemspec
CHANGED
data/lib/jira.rb
CHANGED
data/lib/jira/base.rb
CHANGED
@@ -92,7 +92,6 @@ module JIRA
|
|
92
92
|
def self.all(client, options = {})
|
93
93
|
response = client.get(collection_path(client))
|
94
94
|
json = parse_json(response.body)
|
95
|
-
puts collection_attributes_are_nested
|
96
95
|
if collection_attributes_are_nested
|
97
96
|
json = json[endpoint_name.pluralize]
|
98
97
|
end
|
@@ -275,6 +274,10 @@ module JIRA
|
|
275
274
|
@collection_attributes_are_nested = value
|
276
275
|
end
|
277
276
|
|
277
|
+
def id
|
278
|
+
attrs['id']
|
279
|
+
end
|
280
|
+
|
278
281
|
# Returns a symbol for the given instance, for example
|
279
282
|
# JIRA::Resource::Issue returns :issue
|
280
283
|
def to_sym
|
data/lib/jira/client.rb
CHANGED
@@ -11,12 +11,13 @@ module JIRA
|
|
11
11
|
# are:
|
12
12
|
#
|
13
13
|
# :site => 'http://localhost:2990',
|
14
|
+
# :context_path => '/jira',
|
14
15
|
# :signature_method => 'RSA-SHA1',
|
15
|
-
# :request_token_path => "/
|
16
|
-
# :authorize_path => "/
|
17
|
-
# :access_token_path => "/
|
16
|
+
# :request_token_path => "/plugins/servlet/oauth/request-token",
|
17
|
+
# :authorize_path => "/plugins/servlet/oauth/authorize",
|
18
|
+
# :access_token_path => "/plugins/servlet/oauth/access-token",
|
18
19
|
# :private_key_file => "rsakey.pem",
|
19
|
-
# :rest_base_path => "/
|
20
|
+
# :rest_base_path => "/rest/api/2"
|
20
21
|
#
|
21
22
|
#
|
22
23
|
# See the JIRA::Base class methods for all of the available methods on these accessor
|
@@ -40,21 +41,28 @@ module JIRA
|
|
40
41
|
# The configuration options for this client instance
|
41
42
|
attr_reader :options
|
42
43
|
|
43
|
-
|
44
|
+
def_instance_delegators :@consumer, :key, :secret, :get_request_token
|
44
45
|
|
45
46
|
DEFAULT_OPTIONS = {
|
46
47
|
:site => 'http://localhost:2990',
|
48
|
+
:context_path => '/jira',
|
47
49
|
:signature_method => 'RSA-SHA1',
|
48
|
-
:request_token_path => "/
|
49
|
-
:authorize_path => "/
|
50
|
-
:access_token_path => "/
|
50
|
+
:request_token_path => "/plugins/servlet/oauth/request-token",
|
51
|
+
:authorize_path => "/plugins/servlet/oauth/authorize",
|
52
|
+
:access_token_path => "/plugins/servlet/oauth/access-token",
|
51
53
|
:private_key_file => "rsakey.pem",
|
52
|
-
:rest_base_path => "/
|
54
|
+
:rest_base_path => "/rest/api/2"
|
53
55
|
}
|
54
56
|
|
55
57
|
def initialize(consumer_key, consumer_secret, options={})
|
56
58
|
options = DEFAULT_OPTIONS.merge(options)
|
57
59
|
|
60
|
+
# prepend the context path to all authorization and rest paths
|
61
|
+
options[:request_token_path] = options[:context_path] + options[:request_token_path]
|
62
|
+
options[:authorize_path] = options[:context_path] + options[:authorize_path]
|
63
|
+
options[:access_token_path] = options[:context_path] + options[:access_token_path]
|
64
|
+
options[:rest_base_path] = options[:context_path] + options[:rest_base_path]
|
65
|
+
|
58
66
|
@options = options
|
59
67
|
@options.freeze
|
60
68
|
@consumer = OAuth::Consumer.new(consumer_key,consumer_secret,options)
|
data/lib/jira/http_error.rb
CHANGED
data/lib/jira/railtie.rb
ADDED
data/lib/jira/version.rb
CHANGED
data/lib/tasks/generate.rake
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
namespace :jira do
|
2
4
|
desc "Generate a consumer key for your application"
|
3
5
|
task :generate_consumer_key do
|
4
|
-
|
5
|
-
|
6
|
+
key = SecureRandom.hex(16)
|
7
|
+
puts "You can use this as your consumer key: #{key}"
|
6
8
|
end
|
7
9
|
|
8
10
|
desc "Run the system call to generate a RSA public certificate"
|
data/spec/jira/base_spec.rb
CHANGED
@@ -358,7 +358,7 @@ describe JIRA::Base do
|
|
358
358
|
subject.attrs['foo'] = 'bar'
|
359
359
|
subject.attrs['dead'] = 'beef'
|
360
360
|
|
361
|
-
subject.to_s.should match(/#<JIRA::Resource::Deadbeef:\d+ @attrs=#{attrs.inspect}>/)
|
361
|
+
subject.to_s.should match(/#<JIRA::Resource::Deadbeef:\d+ @attrs=#{Regexp.quote(attrs.inspect)}>/)
|
362
362
|
end
|
363
363
|
|
364
364
|
it "returns the key attribute" do
|
@@ -373,7 +373,7 @@ describe JIRA::Base do
|
|
373
373
|
it "converts to json" do
|
374
374
|
subject.attrs = {"foo" => "bar","dead" => "beef"}
|
375
375
|
|
376
|
-
subject.to_json.should ==
|
376
|
+
subject.to_json.should == subject.attrs.to_json
|
377
377
|
end
|
378
378
|
|
379
379
|
describe "extract attrs from response" do
|
data/spec/jira/client_spec.rb
CHANGED
@@ -22,9 +22,10 @@ describe JIRA::Client do
|
|
22
22
|
subject.secret.should == 'bar'
|
23
23
|
end
|
24
24
|
|
25
|
-
it "sets the default options" do
|
26
|
-
|
27
|
-
|
25
|
+
it "sets the non path default options" do
|
26
|
+
options = [:site, :signature_method, :private_key_file]
|
27
|
+
options.each do |key|
|
28
|
+
subject.options[key].should == JIRA::Client::DEFAULT_OPTIONS[key]
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
@@ -32,15 +33,15 @@ describe JIRA::Client do
|
|
32
33
|
# Check it overrides a given option ...
|
33
34
|
client = JIRA::Client.new('foo', 'bar', :site => 'http://foo.com/')
|
34
35
|
client.options[:site].should == 'http://foo.com/'
|
36
|
+
JIRA::Client::DEFAULT_OPTIONS[:site].should_not == 'http://foo.com/'
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
it "prepends the context path to all authorization and rest paths" do
|
40
|
+
options = [:request_token_path, :authorize_path, :access_token_path, :rest_base_path]
|
41
|
+
defaults = JIRA::Client::DEFAULT_OPTIONS
|
42
|
+
options.each do |key|
|
43
|
+
subject.options[key].should == defaults[:context_path] + defaults[key]
|
41
44
|
end
|
42
|
-
|
43
|
-
JIRA::Client::DEFAULT_OPTIONS[:site].should_not == 'http://foo.com/'
|
44
45
|
end
|
45
46
|
|
46
47
|
# To avoid having to validate options after initialisation, e.g. setting
|
@@ -8,10 +8,10 @@ describe JIRA::Resource::Issue do
|
|
8
8
|
response = mock()
|
9
9
|
response.stub(:body).and_return('{"key":"foo","id":"101"}')
|
10
10
|
JIRA::Resource::Issue.stub(:collection_path).and_return('/jira/rest/api/2/issue')
|
11
|
-
client.should_receive(:get).with('/jira/rest/api/2/issue/foo')
|
12
|
-
|
13
|
-
client.should_receive(:get).with('/jira/rest/api/2/issue/101')
|
14
|
-
|
11
|
+
client.should_receive(:get).with('/jira/rest/api/2/issue/foo').
|
12
|
+
and_return(response)
|
13
|
+
client.should_receive(:get).with('/jira/rest/api/2/issue/101').
|
14
|
+
and_return(response)
|
15
15
|
|
16
16
|
issue_from_id = JIRA::Resource::Issue.find(client,101)
|
17
17
|
issue_from_key = JIRA::Resource::Issue.find(client,'foo')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jira-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &70194827879980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70194827879980
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &70194827879560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70194827879560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: railties
|
38
|
-
requirement: &
|
38
|
+
requirement: &70194827879140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70194827879140
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: railties
|
49
|
-
requirement: &
|
49
|
+
requirement: &70194827878720 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70194827878720
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &70194827878300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70194827878300
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
|
-
requirement: &
|
71
|
+
requirement: &70194827877880 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70194827877880
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: webmock
|
82
|
-
requirement: &
|
82
|
+
requirement: &70194827877460 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,18 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70194827877460
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &70194827877040 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70194827877040
|
91
102
|
description: API for JIRA 5
|
92
103
|
email:
|
93
104
|
executables: []
|
@@ -106,6 +117,7 @@ files:
|
|
106
117
|
- lib/jira/client.rb
|
107
118
|
- lib/jira/has_many_proxy.rb
|
108
119
|
- lib/jira/http_error.rb
|
120
|
+
- lib/jira/railtie.rb
|
109
121
|
- lib/jira/resource/attachment.rb
|
110
122
|
- lib/jira/resource/comment.rb
|
111
123
|
- lib/jira/resource/component.rb
|