jiraby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +94 -4
  2. data/jiraby.gemspec +1 -1
  3. data/lib/jiraby/jira.rb +13 -34
  4. metadata +2 -2
data/README.md CHANGED
@@ -1,11 +1,29 @@
1
1
  Jiraby
2
2
  ======
3
+ [![Build Status](https://secure.travis-ci.org/a-e/jiraby.png?branch=dev)](http://travis-ci.org/a-e/jiraby)
3
4
 
4
5
  Jiraby is a Ruby wrapper for the [JIRA](http://www.atlassian.com/JIRA)
5
6
  [REST API](https://docs.atlassian.com/jira/REST/latest/), supporting Jira
6
- versions 6.2 and up.
7
+ versions 6.x onward.
7
8
 
8
- [Full documentation is on rdoc.info](http://rubydoc.info/github/a-e/jiraby/master/frames).
9
+ - [Source](https://github.com/a-e/jiraby)
10
+ - [Documentation](http://rubydoc.info/github/a-e/jiraby/master/frames)
11
+ - [Gem](http://rubygems.org/gems/jiraby)
12
+ - [Status](https://travis-ci.org/a-e/jiraby)
13
+
14
+
15
+ Install
16
+ -------
17
+
18
+ Just do:
19
+
20
+ $ gem install jiraby
21
+
22
+ Or add:
23
+
24
+ gem 'cherby'
25
+
26
+ to your project's Gemfile or gemspec.
9
27
 
10
28
 
11
29
  Connect to Jira
@@ -49,8 +67,8 @@ All REST methods return a `Jiraby::Entity` (a hash-like object built directly fr
49
67
  the JSON response), or an `Array` of them (for those REST methods that return arrays).
50
68
 
51
69
 
52
- Wrappers
53
- --------
70
+ Issue wrapper
71
+ -------------
54
72
 
55
73
  You can look up a Jira issue using the `#issue` method:
56
74
 
@@ -104,6 +122,78 @@ Then save the updates back to Jira:
104
122
  # => true
105
123
 
106
124
 
125
+ Enumerator wrapper
126
+ ------------------
127
+
128
+ Several of Jira's REST API methods return their data in batches, based on the
129
+ value of `startAt` and `maxResults` parameters, effectively breaking larger
130
+ result sets into pages. Since it's likely you'll want to eventually fetch all
131
+ pages of results, the `Jiraby::Jira` class can wrap such methods in an
132
+ `Enumerator`, via the `#enumerator` method.
133
+
134
+ For example, using the issue `search` method to look up all issues in project
135
+ "FOO", then using `.each` to iterate over them:
136
+
137
+ query = 'project=FOO order by key'
138
+ jira.enumerator(
139
+ :post, 'search', {:jql => query}, 'issues'
140
+ ).each do |issue|
141
+ puts "#{issue.key}: #{issue.fields.summary}"
142
+ end
143
+
144
+ The output might be:
145
+
146
+ FOO-1: First issue in Foo project
147
+ FOO-2: Another issue
148
+ (...)
149
+ FOO-149: Penultimate issue
150
+ FOO-150: Last issue
151
+
152
+ Because the `search` method is so useful, it includes a wrapper of its own; all
153
+ you need to provide is a JQL query:
154
+
155
+ issues = jira.search('project=FOO order by key')
156
+ # => #<Enumerator: ...>
157
+
158
+ This `Enumerator` spits out `Issue` instances. Simply iterate over the issues
159
+ using `.each`, `.map`, `.select` or their ilk, and each page will be fetched
160
+ as it's needed, transparently:
161
+
162
+ issues.each do |issue|
163
+ puts "#{issue.key}: #{issue['summary']}"
164
+ end
165
+
166
+ issue_keys = issues.map { |issue| issue.key }
167
+
168
+ unassigned_subtasks = issues.select do |issue|
169
+ !issue.is_assigned? && issue.is_subtask?
170
+ end
171
+
172
+ Using the `Enumerator` prevents having to load the entire list of issues into
173
+ memory at once, but can mean doing a lot of requests to Jira. If you plan to
174
+ iterate through the issues more than once and would like to avoid repeated
175
+ requests to the REST API, you could convert the `Enumerator` to an `Array`:
176
+
177
+ issues_array = issues.to_a
178
+
179
+ Below is a complete list of Jira REST API methods that accept `startAt`
180
+ and `maxResults`.
181
+
182
+ Returning `Jiraby::Entity`:
183
+
184
+ GET /dashboard => { 'dashboards' => [...], 'total' => N } (dashboards)
185
+ GET /search => { 'issues' => [...], 'total' => N } (issues)
186
+ POST /search => { 'issues' => [...], 'total' => N } (issues)
187
+
188
+ Returning `Array` of `Jiraby::Entity`:
189
+
190
+ GET /user/assignable/multiProjectSearch => [...] (users)
191
+ GET /user/assignable/search => [...] (users)
192
+ GET /user/permission/search => [...] (users)
193
+ GET /user/search => [...] (users)
194
+ GET /user/viewissue/search => [...] (users)
195
+
196
+
107
197
  Copyright
108
198
  ---------
109
199
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "jiraby"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "Jira-Ruby bridge"
5
5
  s.description = <<-EOS
6
6
  Jiraby is a Ruby wrapper for the JIRA REST API,
@@ -136,40 +136,19 @@ module Jiraby
136
136
 
137
137
  # Return an Enumerator yielding items returned by a REST method that
138
138
  # accepts `startAt` and `maxResults` parameters. This allows you to
139
- # iterate through large data sets
140
- #
141
- # For example, using the issue `search` method to look up all issues
142
- # in project "FOO", then using `each` to iterate over them:
143
- #
144
- # query = 'project=FOO order by key'
145
- # jira.enumerator(
146
- # :post, 'search', {:jql => query}, 'issues'
147
- # ).each do |issue|
148
- # puts "#{issue.key}: #{issue.fields.summary}"
149
- # end
150
- #
151
- # The output might be:
152
- #
153
- # FOO-1: First issue in Foo project
154
- # FOO-2: Another issue
155
- # (...)
156
- # FOO-149: Penultimate issue
157
- # FOO-150: Last issue
158
- #
159
- # Below is a complete list of Jira REST API methods that accept `startAt`
160
- # and `maxResults`.
161
- #
162
- # Returning Entity:
163
- # GET /dashboard => { 'dashboards' => [...], 'total' => N } (dashboards)
164
- # GET /search => { 'issues' => [...], 'total' => N } (issues)
165
- # POST /search => { 'issues' => [...], 'total' => N } (issues)
166
- #
167
- # Returning Array of Entity:
168
- # GET /user/assignable/multiProjectSearch => [...] (users)
169
- # GET /user/assignable/search => [...] (users)
170
- # GET /user/permission/search => [...] (users)
171
- # GET /user/search => [...] (users)
172
- # GET /user/viewissue/search => [...] (users)
139
+ # iterate through large data sets.
140
+ #
141
+ # @param [String,Symbol] method
142
+ # HTTP request method to use (`:get` or `:post`)
143
+ # @param [String] path
144
+ # Relative path to the REST method (such as `user/search`)
145
+ # @param [Hash] params
146
+ # GET or POST parameters to submit (depending on which method
147
+ # and path you're requesting)
148
+ # @param [String] list_key
149
+ # For REST methods returning an array embedded in an object
150
+ # (like `search` and `dashboard`), the attribute name where
151
+ # the array of things is stored.
173
152
  #
174
153
  def enumerator(method, path, params={}, list_key=nil)
175
154
  max_results = @@max_results
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jiraby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-17 00:00:00.000000000 Z
12
+ date: 2014-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client