jira-ruby-dmg 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +46 -0
  6. data/README.rdoc +309 -0
  7. data/Rakefile +28 -0
  8. data/example.rb +119 -0
  9. data/http-basic-example.rb +112 -0
  10. data/jira-ruby-dmg.gemspec +28 -0
  11. data/lib/jira/base.rb +497 -0
  12. data/lib/jira/base_factory.rb +49 -0
  13. data/lib/jira/client.rb +165 -0
  14. data/lib/jira/has_many_proxy.rb +43 -0
  15. data/lib/jira/http_client.rb +69 -0
  16. data/lib/jira/http_error.rb +16 -0
  17. data/lib/jira/oauth_client.rb +84 -0
  18. data/lib/jira/railtie.rb +10 -0
  19. data/lib/jira/request_client.rb +18 -0
  20. data/lib/jira/resource/attachment.rb +12 -0
  21. data/lib/jira/resource/comment.rb +14 -0
  22. data/lib/jira/resource/component.rb +10 -0
  23. data/lib/jira/resource/field.rb +10 -0
  24. data/lib/jira/resource/filter.rb +15 -0
  25. data/lib/jira/resource/issue.rb +76 -0
  26. data/lib/jira/resource/issuetype.rb +10 -0
  27. data/lib/jira/resource/priority.rb +10 -0
  28. data/lib/jira/resource/project.rb +31 -0
  29. data/lib/jira/resource/status.rb +10 -0
  30. data/lib/jira/resource/transition.rb +33 -0
  31. data/lib/jira/resource/user.rb +14 -0
  32. data/lib/jira/resource/version.rb +10 -0
  33. data/lib/jira/resource/worklog.rb +16 -0
  34. data/lib/jira/tasks.rb +0 -0
  35. data/lib/jira/version.rb +3 -0
  36. data/lib/jira.rb +33 -0
  37. data/lib/tasks/generate.rake +18 -0
  38. data/spec/integration/attachment_spec.rb +23 -0
  39. data/spec/integration/comment_spec.rb +55 -0
  40. data/spec/integration/component_spec.rb +42 -0
  41. data/spec/integration/field_spec.rb +35 -0
  42. data/spec/integration/issue_spec.rb +94 -0
  43. data/spec/integration/issuetype_spec.rb +26 -0
  44. data/spec/integration/priority_spec.rb +27 -0
  45. data/spec/integration/project_spec.rb +56 -0
  46. data/spec/integration/status_spec.rb +27 -0
  47. data/spec/integration/transition_spec.rb +52 -0
  48. data/spec/integration/user_spec.rb +25 -0
  49. data/spec/integration/version_spec.rb +43 -0
  50. data/spec/integration/worklog_spec.rb +55 -0
  51. data/spec/jira/base_factory_spec.rb +46 -0
  52. data/spec/jira/base_spec.rb +586 -0
  53. data/spec/jira/client_spec.rb +188 -0
  54. data/spec/jira/has_many_proxy_spec.rb +45 -0
  55. data/spec/jira/http_client_spec.rb +109 -0
  56. data/spec/jira/http_error_spec.rb +25 -0
  57. data/spec/jira/oauth_client_spec.rb +111 -0
  58. data/spec/jira/request_client_spec.rb +14 -0
  59. data/spec/jira/resource/attachment_spec.rb +20 -0
  60. data/spec/jira/resource/filter_spec.rb +97 -0
  61. data/spec/jira/resource/issue_spec.rb +107 -0
  62. data/spec/jira/resource/project_factory_spec.rb +13 -0
  63. data/spec/jira/resource/project_spec.rb +70 -0
  64. data/spec/jira/resource/worklog_spec.rb +24 -0
  65. data/spec/mock_responses/attachment/10000.json +20 -0
  66. data/spec/mock_responses/component/10000.invalid.put.json +5 -0
  67. data/spec/mock_responses/component/10000.json +39 -0
  68. data/spec/mock_responses/component/10000.put.json +39 -0
  69. data/spec/mock_responses/component.post.json +28 -0
  70. data/spec/mock_responses/field/1.json +15 -0
  71. data/spec/mock_responses/field.json +32 -0
  72. data/spec/mock_responses/issue/10002/comment/10000.json +29 -0
  73. data/spec/mock_responses/issue/10002/comment/10000.put.json +29 -0
  74. data/spec/mock_responses/issue/10002/comment.json +65 -0
  75. data/spec/mock_responses/issue/10002/comment.post.json +29 -0
  76. data/spec/mock_responses/issue/10002/transitions.json +49 -0
  77. data/spec/mock_responses/issue/10002/transitions.post.json +1 -0
  78. data/spec/mock_responses/issue/10002/worklog/10000.json +31 -0
  79. data/spec/mock_responses/issue/10002/worklog/10000.put.json +30 -0
  80. data/spec/mock_responses/issue/10002/worklog.json +98 -0
  81. data/spec/mock_responses/issue/10002/worklog.post.json +30 -0
  82. data/spec/mock_responses/issue/10002.invalid.put.json +6 -0
  83. data/spec/mock_responses/issue/10002.json +126 -0
  84. data/spec/mock_responses/issue/10002.put.missing_field_update.json +6 -0
  85. data/spec/mock_responses/issue.json +1108 -0
  86. data/spec/mock_responses/issue.post.json +5 -0
  87. data/spec/mock_responses/issuetype/5.json +8 -0
  88. data/spec/mock_responses/issuetype.json +42 -0
  89. data/spec/mock_responses/priority/1.json +8 -0
  90. data/spec/mock_responses/priority.json +42 -0
  91. data/spec/mock_responses/project/SAMPLEPROJECT.issues.json +1108 -0
  92. data/spec/mock_responses/project/SAMPLEPROJECT.json +84 -0
  93. data/spec/mock_responses/project.json +12 -0
  94. data/spec/mock_responses/status/1.json +7 -0
  95. data/spec/mock_responses/status.json +37 -0
  96. data/spec/mock_responses/user_username=admin.json +17 -0
  97. data/spec/mock_responses/version/10000.invalid.put.json +5 -0
  98. data/spec/mock_responses/version/10000.json +11 -0
  99. data/spec/mock_responses/version/10000.put.json +7 -0
  100. data/spec/mock_responses/version.post.json +7 -0
  101. data/spec/spec_helper.rb +22 -0
  102. data/spec/support/clients_helper.rb +16 -0
  103. data/spec/support/matchers/have_attributes.rb +11 -0
  104. data/spec/support/matchers/have_many.rb +9 -0
  105. data/spec/support/matchers/have_one.rb +5 -0
  106. data/spec/support/shared_examples/integration.rb +190 -0
  107. metadata +301 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c07448f99963fb48aa853b5306c3b282c7d07ee1
4
+ data.tar.gz: c8ddbf9b54cf03c5cf523104c60a6f67054a8f7b
5
+ SHA512:
6
+ metadata.gz: 3c8b513fc02ee7eafa30543e9222f5fff2698886e197e069aadb978d888d79da127a219d74b79eba5db2e5d5cecbdbbb646a7aab3479f051257e559be4cc114f
7
+ data.tar.gz: 51fc2db5eca63cc660a731f4f0006ffe2267e321db94fa9d58b068f1877b858a5c7119508a2d02fa9c895b6dcf2997eeae2a01c0fc9f73e96ff157567892fad2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .idea
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ .rvmrc
7
+ .rspec
8
+ *.pem
9
+ .DS_STORE
10
+ doc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_script:
5
+ - rake jira:generate_public_cert
6
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jira-api-dmg.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,46 @@
1
+ Open Software License v. 3.0 (OSL-3.0)
2
+ This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
3
+
4
+ Licensed under the Open Software License version 3.0
5
+
6
+ 1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
7
+
8
+ a) to reproduce the Original Work in copies, either alone or as part of a collective work;
9
+
10
+ b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
11
+
12
+ c) to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
13
+
14
+ d) to perform the Original Work publicly; and
15
+
16
+ e) to display the Original Work publicly.
17
+
18
+ 2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
19
+
20
+ 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
21
+
22
+ 4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
23
+
24
+ 5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
25
+
26
+ 6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
27
+
28
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
29
+
30
+ 8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
31
+
32
+ 9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
33
+
34
+ 10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
35
+
36
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
37
+
38
+ 12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
39
+
40
+ 13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
41
+
42
+ 14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
43
+
44
+ 15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
45
+
46
+ 16) Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
data/README.rdoc ADDED
@@ -0,0 +1,309 @@
1
+ = JIRA API Gem
2
+ {<img src="https://codeclimate.com/github/sumoheavy/jira-ruby.png" />}[https://codeclimate.com/github/sumoheavy/jira-ruby]
3
+ {<img src="https://travis-ci.org/sumoheavy/jira-ruby.png?branch=master"}[https://travis-ci.org/sumoheavy/jira-ruby]
4
+
5
+ This gem provides access to the Atlassian JIRA REST API.
6
+
7
+ == Example usage
8
+
9
+ client = JIRA::Client.new({:consumer_key => CONSUMER_KEY, :consumer_secret => CONSUMER_SECRET})
10
+
11
+ project = client.Project.find('SAMPLEPROJECT')
12
+
13
+ project.issues.each do |issue|
14
+ puts "#{issue.id} - #{issue.summary}"
15
+ end
16
+
17
+ issue.comments.each {|comment| ... }
18
+
19
+ comment = issue.comments.build
20
+ comment.save({'body':'My new comment'})
21
+ comment.delete
22
+
23
+ == Links to JIRA REST API documentation
24
+
25
+ * {Overview}[https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs]
26
+ * {Reference}[http://docs.atlassian.com/jira/REST/latest/]
27
+
28
+
29
+ == Setting up the JIRA SDK
30
+
31
+ On Mac OS,
32
+
33
+ * Follow the instructions under "Mac OSX Installer" here: https://developer.atlassian.com/display/DOCS/Install+the+Atlassian+SDK+on+a+Linux+or+Mac+System
34
+ * From within the archive directory, run:
35
+
36
+ ./bin/atlas-run-standalone --product jira
37
+
38
+ Once this is running, you should be able to connect to
39
+ http://localhost:2990/ and login to the JIRA admin system using `admin:admin`
40
+
41
+ You'll need to create a dummy project and probably some issues to test using
42
+ this library.
43
+
44
+ == Configuring JIRA to use OAuth
45
+
46
+ From the JIRA API tutorial
47
+
48
+ The first step is to register a new consumer in JIRA. This is done through
49
+ the Application Links administration screens in JIRA. Create a new
50
+ Application Link.
51
+ {Administration/Plugins/Application Links}[http://localhost:2990/jira/plugins/servlet/applinks/listApplicationLinks]
52
+
53
+ When creating the Application Link use a placeholder URL or the correct URL
54
+ to your client (e.g. `http://localhost:3000`), if your client can be reached
55
+ via HTTP and choose the Generic Application type. After this Application Link
56
+ has been created, edit the configuration and go to the incoming
57
+ authentication configuration screen and select OAuth. Enter in this the
58
+ public key and the consumer key which your client will use when making
59
+ requests to JIRA.
60
+
61
+ This public key and consumer key will need to be generated by the Gem user, using OpenSSL
62
+ or similar to generate the public key and the provided rake task to generate the consumer
63
+ key.
64
+
65
+ After you have entered all the information click OK and ensure OAuth authentication is
66
+ enabled.
67
+
68
+ == Configuring JIRA to use HTTP Basic Auth
69
+
70
+ Follow the same steps described above to set up a new Application Link in JIRA,
71
+ however there is no need to set up any "incoming authentication" as this
72
+ defaults to HTTP Basic Auth.
73
+
74
+ == Using the API Gem in a command line application
75
+
76
+ Using HTTP Basic Authentication, configure and connect a client to your instance
77
+ of JIRA.
78
+
79
+ require 'rubygems'
80
+ require 'pp'
81
+ require 'jira'
82
+
83
+ # Consider the use of :use_ssl and :ssl_verify_mode options if running locally
84
+ # for tests.
85
+
86
+ username = "myremoteuser"
87
+ password = "myuserspassword"
88
+
89
+ options = {
90
+ :username => username,
91
+ :password => password,
92
+ :site => 'http://localhost:8080/',
93
+ :context_path => '/myjira',
94
+ :auth_type => :basic
95
+ }
96
+
97
+ client = JIRA::Client.new(options)
98
+
99
+ # Show all projects
100
+ projects = client.Project.all
101
+
102
+ projects.each do |project|
103
+ puts "Project -> key: #{project.key}, name: #{project.name}"
104
+ end
105
+
106
+ == Using the API Gem in your Rails application
107
+
108
+ Using oauth, the gem requires the consumer key and public certificate file (which
109
+ are generated in their respective rake tasks) to initialize an access token for
110
+ using the JIRA API.
111
+
112
+ Note that currently the rake task which generates the public certificate
113
+ requires OpenSSL to be installed on the machine.
114
+
115
+ Below is an example for setting up a rails application for OAuth authorization.
116
+
117
+ Ensure the JIRA gem is loaded correctly
118
+
119
+ # Gemfile
120
+ ...
121
+ gem 'jira-ruby', :require => 'jira'
122
+ ...
123
+
124
+ Add common methods to your application controller and ensure access token
125
+ errors are handled gracefully
126
+
127
+ # app/controllers/application_controller.rb
128
+ class ApplicationController < ActionController::Base
129
+ protect_from_forgery
130
+
131
+ rescue_from JIRA::OauthClient::UninitializedAccessTokenError do
132
+ redirect_to new_jira_session_url
133
+ end
134
+
135
+ private
136
+
137
+ def get_jira_client
138
+
139
+ # add any extra configuration options for your instance of JIRA,
140
+ # e.g. :use_ssl, :ssl_verify_mode, :context_path, :site
141
+ options = {
142
+ :private_key_file => "rsakey.pem",
143
+ :consumer_key => 'test'
144
+ }
145
+
146
+ @jira_client = JIRA::Client.new(options)
147
+
148
+ # Add AccessToken if authorised previously.
149
+ if session[:jira_auth]
150
+ @jira_client.set_access_token(
151
+ session[:jira_auth][:access_token],
152
+ session[:jira_auth][:access_key]
153
+ )
154
+ end
155
+ end
156
+ end
157
+
158
+ Create a controller for handling the OAuth conversation.
159
+
160
+ # app/controllers/jira_sessions_controller.rb
161
+ class JiraSessionsController < ApplicationController
162
+
163
+ before_filter :get_jira_client
164
+
165
+ def new
166
+ request_token = @jira_client.request_token
167
+ session[:request_token] = request_token.token
168
+ session[:request_secret] = request_token.secret
169
+
170
+ redirect_to request_token.authorize_url
171
+ end
172
+
173
+ def authorize
174
+ request_token = @jira_client.set_request_token(
175
+ session[:request_token], session[:request_secret]
176
+ )
177
+ access_token = @jira_client.init_access_token(
178
+ :oauth_verifier => params[:oauth_verifier]
179
+ )
180
+
181
+ session[:jira_auth] = {
182
+ :access_token => access_token.token,
183
+ :access_key => access_token.secret
184
+ }
185
+
186
+ session.delete(:request_token)
187
+ session.delete(:request_secret)
188
+
189
+ redirect_to projects_path
190
+ end
191
+
192
+ def destroy
193
+ session.data.delete(:jira_auth)
194
+ end
195
+ end
196
+
197
+ Create your own controllers for the JIRA resources you wish to access.
198
+
199
+ # app/controllers/issues_controller.rb
200
+ class IssuesController < ApplicationController
201
+ before_filter :get_jira_client
202
+ def index
203
+ @issues = @jira_client.Issue.all
204
+ end
205
+
206
+ def show
207
+ @issue = @jira_client.Issue.find(params[:id])
208
+ end
209
+ end
210
+
211
+ == Using the API Gem in your Sinatra application
212
+
213
+ Here's the same example as a Sinatra application:
214
+
215
+ require 'jira'
216
+ class App < Sinatra::Base
217
+ enable :sessions
218
+
219
+ # This section gets called before every request. Here, we set up the
220
+ # OAuth consumer details including the consumer key, private key,
221
+ # site uri, and the request token, access token, and authorize paths
222
+ before do
223
+ options = {
224
+ :site => 'http://localhost:2990',
225
+ :context_path => '/jira',
226
+ :signature_method => 'RSA-SHA1',
227
+ :request_token_path => "/plugins/servlet/oauth/request-token",
228
+ :authorize_path => "/plugins/servlet/oauth/authorize",
229
+ :access_token_path => "/plugins/servlet/oauth/access-token",
230
+ :private_key_file => "rsakey.pem",
231
+ :rest_base_path => "/rest/api/2",
232
+ :consumer_key => "jira-ruby-example"
233
+ }
234
+
235
+ @jira_client = JIRA::Client.new(options)
236
+ @jira_client.consumer.http.set_debug_output($stderr)
237
+
238
+ # Add AccessToken if authorised previously.
239
+ if session[:jira_auth]
240
+ @jira_client.set_access_token(
241
+ session[:jira_auth][:access_token],
242
+ session[:jira_auth][:access_key]
243
+ )
244
+ end
245
+ end
246
+
247
+
248
+ # Starting point: http://<yourserver>/
249
+ # This will serve up a login link if you're not logged in. If you are, it'll show some user info and a
250
+ # signout link
251
+ get '/' do
252
+ if !session[:jira_auth]
253
+ # not logged in
254
+ <<-eos
255
+ <h1>jira-ruby (JIRA 5 Ruby Gem) demo </h1>You're not signed in. Why don't you
256
+ <a href=/signin>sign in</a> first.
257
+ eos
258
+ else
259
+ #logged in
260
+ @issues = @jira_client.Issue.all
261
+
262
+ # HTTP response inlined with bind data below...
263
+ <<-eos
264
+ You're now signed in. There #{@issues.count == 1 ? "is" : "are"} #{@issues.count}
265
+ issue#{@issues.count == 1 ? "" : "s"} in this JIRA instance. <a href='/signout'>Signout</a>
266
+ eos
267
+ end
268
+ end
269
+
270
+ # http://<yourserver>/signin
271
+ # Initiates the OAuth dance by first requesting a token then redirecting to
272
+ # http://<yourserver>/auth to get the @access_token
273
+ get '/signin' do
274
+ request_token = @jira_client.request_token
275
+ session[:request_token] = request_token.token
276
+ session[:request_secret] = request_token.secret
277
+
278
+ redirect request_token.authorize_url
279
+ end
280
+
281
+ # http://<yourserver>/callback
282
+ # Retrieves the @access_token then stores it inside a session cookie. In a real app,
283
+ # you'll want to persist the token in a datastore associated with the user.
284
+ get "/callback/" do
285
+ request_token = @jira_client.set_request_token(
286
+ session[:request_token], session[:request_secret]
287
+ )
288
+ access_token = @jira_client.init_access_token(
289
+ :oauth_verifier => params[:oauth_verifier]
290
+ )
291
+
292
+ session[:jira_auth] = {
293
+ :access_token => access_token.token,
294
+ :access_key => access_token.secret
295
+ }
296
+
297
+ session.delete(:request_token)
298
+ session.delete(:request_secret)
299
+
300
+ redirect "/"
301
+ end
302
+
303
+ # http://<yourserver>/signout
304
+ # Expires the session
305
+ get "/signout" do
306
+ session.delete(:jira_auth)
307
+ redirect "/"
308
+ end
309
+ end
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rubygems'
4
+ require 'rspec/core/rake_task'
5
+ require 'rdoc/task'
6
+
7
+ Dir.glob('lib/tasks/*.rake').each { |r| import r }
8
+
9
+ task :default => [:test]
10
+
11
+ task :test => [:prepare, :spec]
12
+
13
+ desc 'Prepare and run rspec tests'
14
+ task :prepare do
15
+ rsa_key = File.expand_path('rsakey.pem')
16
+ unless File.exists?(rsa_key)
17
+ raise 'rsakey.pem does not exist, tests will fail. Run `rake jira:generate_public_cert` first'
18
+ end
19
+ end
20
+
21
+ desc 'Run RSpec tests'
22
+ RSpec::Core::RakeTask.new(:spec)
23
+
24
+ Rake::RDocTask.new(:doc) do |rd|
25
+ rd.main = 'README.rdoc'
26
+ rd.rdoc_dir = 'doc'
27
+ rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
28
+ end
data/example.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'pp'
2
+ require './lib/jira'
3
+
4
+ CONSUMER_KEY = 'test'
5
+ SITE = 'https://test.jira.com'
6
+
7
+ options = {
8
+ :private_key_file => "rsakey.pem",
9
+ :context_path => '',
10
+ :consumer_key => CONSUMER_KEY,
11
+ :site => SITE
12
+ }
13
+
14
+ client = JIRA::Client.new(options)
15
+
16
+ if ARGV.length == 0
17
+ # If not passed any command line arguments, open a browser and prompt the
18
+ # user for the OAuth verifier.
19
+ request_token = client.request_token
20
+ puts "Opening #{request_token.authorize_url}"
21
+ system "open #{request_token.authorize_url}"
22
+
23
+ puts "Enter the oauth_verifier: "
24
+ oauth_verifier = gets.strip
25
+
26
+ access_token = client.init_access_token(:oauth_verifier => oauth_verifier)
27
+ puts "Access token: #{access_token.token} secret: #{access_token.secret}"
28
+ elsif ARGV.length == 2
29
+ # Otherwise assume the arguments are a previous access token and secret.
30
+ access_token = client.set_access_token(ARGV[0], ARGV[1])
31
+ else
32
+ # Script must be passed 0 or 2 arguments
33
+ raise "Usage: #{$0} [ token secret ]"
34
+ end
35
+
36
+ # Show all projects
37
+ projects = client.Project.all
38
+
39
+ projects.each do |project|
40
+ puts "Project -> key: #{project.key}, name: #{project.name}"
41
+ end
42
+ issue = client.Issue.find('SAMPLEPROJECT-1')
43
+ pp issue
44
+
45
+ # # Find a specific project by key
46
+ # # ------------------------------
47
+ # project = client.Project.find('SAMPLEPROJECT')
48
+ # pp project
49
+ # project.issues.each do |issue|
50
+ # puts "#{issue.id} - #{issue.fields['summary']}"
51
+ # end
52
+ #
53
+ # # List all Issues
54
+ # # ---------------
55
+ # client.Issue.all.each do |issue|
56
+ # puts "#{issue.id} - #{issue.fields['summary']}"
57
+ # end
58
+ #
59
+ # # List issues by JQL query
60
+ # # ------------------------
61
+ # client.Issue.jql('PROJECT = "SAMPLEPROJECT"', [comments, summary]).each do |issue|
62
+ # puts "#{issue.id} - #{issue.fields['summary']}"
63
+ # end
64
+ #
65
+ # # Delete an issue
66
+ # # ---------------
67
+ # issue = client.Issue.find('SAMPLEPROJECT-2')
68
+ # if issue.delete
69
+ # puts "Delete of issue SAMPLEPROJECT-2 sucessful"
70
+ # else
71
+ # puts "Delete of issue SAMPLEPROJECT-2 failed"
72
+ # end
73
+ #
74
+ # # Create an issue
75
+ # # ---------------
76
+ # issue = client.Issue.build
77
+ # issue.save({"fields"=>{"summary"=>"blarg from in example.rb","project"=>{"id"=>"10001"},"issuetype"=>{"id"=>"3"}}})
78
+ # issue.fetch
79
+ # pp issue
80
+ #
81
+ # # Update an issue
82
+ # # ---------------
83
+ # issue = client.Issue.find("10002")
84
+ # issue.save({"fields"=>{"summary"=>"EVEN MOOOOOOARRR NINJAAAA!"}})
85
+ # pp issue
86
+ #
87
+ # # Find a user
88
+ # # -----------
89
+ # user = client.User.find('admin')
90
+ # pp user
91
+ #
92
+ # # Get all issue types
93
+ # # -------------------
94
+ # issuetypes = client.Issuetype.all
95
+ # pp issuetypes
96
+ #
97
+ # # Get a single issue type
98
+ # # -----------------------
99
+ # issuetype = client.Issuetype.find('5')
100
+ # pp issuetype
101
+ #
102
+ # # Get all comments for an issue
103
+ # # -----------------------------
104
+ # issue.comments.each do |comment|
105
+ # pp comment
106
+ # end
107
+ #
108
+ # # Build and Save a comment
109
+ # # ------------------------
110
+ # comment = issue.comments.build
111
+ # comment.save!(:body => "New comment from example script")
112
+ #
113
+ # # Delete a comment from the collection
114
+ # # ------------------------------------
115
+ # issue.comments.last.delete
116
+ #
117
+ # # Update an existing comment
118
+ # # --------------------------
119
+ # issue.comments.first.save({"body" => "an updated comment frome example.rb"})
@@ -0,0 +1,112 @@
1
+ require 'rubygems'
2
+ require 'pp'
3
+ require 'jira'
4
+
5
+ if ARGV.length == 0
6
+ # If not passed any command line arguments, prompt the
7
+ # user for the username and password.
8
+ puts "Enter the username: "
9
+ username = gets.strip
10
+
11
+ puts "Enter the password: "
12
+ password = gets.strip
13
+ elsif ARGV.length == 2
14
+ username, password = ARGV[0], ARGV[1]
15
+ else
16
+ # Script must be passed 0 or 2 arguments
17
+ raise "Usage: #{$0} [ username password ]"
18
+ end
19
+
20
+ options = {
21
+ :username => username,
22
+ :password => password,
23
+ :site => 'http://localhost:8080/',
24
+ :context_path => '',
25
+ :auth_type => :basic,
26
+ :use_ssl => false
27
+ }
28
+
29
+ client = JIRA::Client.new(options)
30
+
31
+ # Show all projects
32
+ projects = client.Project.all
33
+
34
+ projects.each do |project|
35
+ puts "Project -> key: #{project.key}, name: #{project.name}"
36
+ end
37
+
38
+ # # Find a specific project by key
39
+ # # ------------------------------
40
+ # project = client.Project.find('SAMPLEPROJECT')
41
+ # pp project
42
+ # project.issues.each do |issue|
43
+ # puts "#{issue.id} - #{issue.fields['summary']}"
44
+ # end
45
+ #
46
+ # # List all Issues
47
+ # # ---------------
48
+ # client.Issue.all.each do |issue|
49
+ # puts "#{issue.id} - #{issue.fields['summary']}"
50
+ # end
51
+ #
52
+ # # List issues by JQL query
53
+ # # ------------------------
54
+ # client.Issue.jql('PROJECT = "SAMPLEPROJECT"', [comments, summary]).each do |issue|
55
+ # puts "#{issue.id} - #{issue.fields['summary']}"
56
+ # end
57
+ #
58
+ # # Delete an issue
59
+ # # ---------------
60
+ # issue = client.Issue.find('SAMPLEPROJECT-2')
61
+ # if issue.delete
62
+ # puts "Delete of issue SAMPLEPROJECT-2 sucessful"
63
+ # else
64
+ # puts "Delete of issue SAMPLEPROJECT-2 failed"
65
+ # end
66
+ #
67
+ # # Create an issue
68
+ # # ---------------
69
+ # issue = client.Issue.build
70
+ # issue.save({"fields"=>{"summary"=>"blarg from in example.rb","project"=>{"id"=>"10001"},"issuetype"=>{"id"=>"3"}}})
71
+ # issue.fetch
72
+ # pp issue
73
+ #
74
+ # # Update an issue
75
+ # # ---------------
76
+ # issue = client.Issue.find("10002")
77
+ # issue.save({"fields"=>{"summary"=>"EVEN MOOOOOOARRR NINJAAAA!"}})
78
+ # pp issue
79
+ #
80
+ # # Find a user
81
+ # # -----------
82
+ # user = client.User.find('admin')
83
+ # pp user
84
+ #
85
+ # # Get all issue types
86
+ # # -------------------
87
+ # issuetypes = client.Issuetype.all
88
+ # pp issuetypes
89
+ #
90
+ # # Get a single issue type
91
+ # # -----------------------
92
+ # issuetype = client.Issuetype.find('5')
93
+ # pp issuetype
94
+ #
95
+ # # Get all comments for an issue
96
+ # # -----------------------------
97
+ # issue.comments.each do |comment|
98
+ # pp comment
99
+ # end
100
+ #
101
+ # # Build and Save a comment
102
+ # # ------------------------
103
+ # comment = issue.comments.build
104
+ # comment.save!(:body => "New comment from example script")
105
+ #
106
+ # # Delete a comment from the collection
107
+ # # ------------------------------------
108
+ # issue.comments.last.delete
109
+ #
110
+ # # Update an existing comment
111
+ # # --------------------------
112
+ # issue.comments.first.save({"body" => "an updated comment frome example.rb"})
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jira/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jira-ruby-dmg"
7
+ s.version = JIRA::VERSION
8
+ s.authors = ["ThisIs! DMG"]
9
+ s.homepage = "http://www.thisisdmg.com"
10
+ s.summary = %q{Ruby Gem for use with the Atlassian JIRA REST API}
11
+ s.description = %q{API for JIRA}
12
+ s.licenses = ["OSL-3.0"]
13
+
14
+ s.rubyforge_project = "jira-ruby-dmg"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "railties"
22
+ s.add_runtime_dependency "oauth"
23
+ s.add_runtime_dependency "activesupport"
24
+ s.add_development_dependency "webmock"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "rake"
27
+ end
28
+