jira-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in jira_api.gemspec
4
4
  gemspec
5
- gem 'rspec'
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 => "/jira/plugins/servlet/oauth/request-token",
178
- :authorize_path => "/jira/plugins/servlet/oauth/authorize",
179
- :access_token_path => "/jira/plugins/servlet/oauth/access-token",
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 => "/jira/rest/api/2"
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
@@ -27,4 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_runtime_dependency "activesupport"
28
28
  s.add_development_dependency "activesupport"
29
29
  s.add_development_dependency "webmock"
30
+ s.add_development_dependency "rspec"
30
31
  end
data/lib/jira.rb CHANGED
@@ -24,3 +24,4 @@ require 'jira/resource/issue'
24
24
 
25
25
  require 'jira/client'
26
26
 
27
+ require 'jira/railtie' if defined?(Rails)
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 => "/jira/plugins/servlet/oauth/request-token",
16
- # :authorize_path => "/jira/plugins/servlet/oauth/authorize",
17
- # :access_token_path => "/jira/plugins/servlet/oauth/access-token",
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 => "/jira/rest/api/2"
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
- delegate [:key, :secret, :get_request_token] => :consumer
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 => "/jira/plugins/servlet/oauth/request-token",
49
- :authorize_path => "/jira/plugins/servlet/oauth/authorize",
50
- :access_token_path => "/jira/plugins/servlet/oauth/access-token",
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 => "/jira/rest/api/2"
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)
@@ -4,7 +4,7 @@ module JIRA
4
4
  class HTTPError < StandardError
5
5
  extend Forwardable
6
6
 
7
- delegate [:message, :code] => :response
7
+ def_instance_delegators :@response, :message, :code
8
8
  attr_reader :response
9
9
 
10
10
  def initialize(response)
@@ -0,0 +1,10 @@
1
+ require 'jira'
2
+ require 'rails'
3
+
4
+ module JIRA
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load 'tasks/generate.rake'
8
+ end
9
+ end
10
+ end
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- #FIXME SERIOUSLY. THIS IS NOT A REAL SOLUTION. I FEEL SO UNCLEAN.
5
- system("for i in {1..10}; do echo $RANDOM$RANDOM$RANDOM; done | md5 | awk '{ print \"You can use this as your consumer key: \" $0 }'")
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"
@@ -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 == '{"foo":"bar","dead":"beef"}'
376
+ subject.to_json.should == subject.attrs.to_json
377
377
  end
378
378
 
379
379
  describe "extract attrs from response" do
@@ -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
- JIRA::Client::DEFAULT_OPTIONS.each do |key, value|
27
- subject.options[key].should == value
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
- # ... but leaves the rest intact
37
- JIRA::Client::DEFAULT_OPTIONS.keys.reject do |key|
38
- key == :site
39
- end.each do |key|
40
- client.options[key].should == JIRA::Client::DEFAULT_OPTIONS[key]
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
- .and_return(response)
13
- client.should_receive(:get).with('/jira/rest/api/2/issue/101')
14
- .and_return(response)
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.3
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-01-30 00:00:00.000000000Z
12
+ date: 2012-07-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &70202332043180 !ruby/object:Gem::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: *70202332043180
24
+ version_requirements: *70194827879980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth
27
- requirement: &70202332042760 !ruby/object:Gem::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: *70202332042760
35
+ version_requirements: *70194827879560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: railties
38
- requirement: &70202332042340 !ruby/object:Gem::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: *70202332042340
46
+ version_requirements: *70194827879140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: railties
49
- requirement: &70202332041920 !ruby/object:Gem::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: *70202332041920
57
+ version_requirements: *70194827878720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70202332041500 !ruby/object:Gem::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: *70202332041500
68
+ version_requirements: *70194827878300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &70202332041080 !ruby/object:Gem::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: *70202332041080
79
+ version_requirements: *70194827877880
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: webmock
82
- requirement: &70202332040660 !ruby/object:Gem::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: *70202332040660
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