lighthouse-api 1.1.0 → 2.0
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/{README.markdown → README.md} +18 -0
- data/lib/lighthouse-api.rb +1 -1
- data/lib/lighthouse.rb +49 -317
- data/lib/lighthouse/base.rb +20 -0
- data/lib/lighthouse/bin.rb +9 -0
- data/lib/lighthouse/changeset.rb +5 -0
- data/lib/lighthouse/console.rb +1 -1
- data/lib/lighthouse/core_ext/uri.rb +22 -0
- data/lib/lighthouse/membership.rb +8 -0
- data/lib/lighthouse/message.rb +5 -0
- data/lib/lighthouse/milestone.rb +9 -0
- data/lib/lighthouse/project.rb +74 -0
- data/lib/lighthouse/project_membership.rb +10 -0
- data/lib/lighthouse/tag.rb +18 -0
- data/lib/lighthouse/tag_resource.rb +14 -0
- data/lib/lighthouse/ticket.rb +101 -0
- data/lib/lighthouse/token.rb +7 -0
- data/lib/lighthouse/user.rb +7 -0
- metadata +59 -22
@@ -17,7 +17,11 @@ The Lighthouse library comes with a convenient console for testing and quick com
|
|
17
17
|
|
18
18
|
From /lib:
|
19
19
|
|
20
|
+
# For ruby 1.9
|
21
|
+
# irb -I. -r lighthouse/console.rb
|
22
|
+
|
20
23
|
irb -r lighthouse/console
|
24
|
+
|
21
25
|
Lighthouse.account = "activereload"
|
22
26
|
|
23
27
|
#### You can use `authenticate` OR `token`
|
@@ -25,3 +29,17 @@ From /lib:
|
|
25
29
|
#Lighthouse.token = 'YOUR_TOKEN'
|
26
30
|
|
27
31
|
Project.find(:all)
|
32
|
+
|
33
|
+
### Contributions
|
34
|
+
* technoweenie (rick)
|
35
|
+
* caged (Justin Palmer)
|
36
|
+
* granth (Grant Hollingworth)
|
37
|
+
* kneath (Kyle Neath)
|
38
|
+
* djanowski (Damian Janowski)
|
39
|
+
* drnic (Dr Nic Williams)
|
40
|
+
* texel (Leigh Caplan)
|
41
|
+
* trptcolin (Colin Jones)
|
42
|
+
* cyberfox (Morgan Schweers)
|
43
|
+
* krekoten (Крекотень Мар'ян)
|
44
|
+
|
45
|
+
|
data/lib/lighthouse-api.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.join(File.dirname(__FILE__), "lighthouse")
|
data/lib/lighthouse.rb
CHANGED
@@ -1,30 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'uri'
|
5
|
-
require 'addressable/uri'
|
6
|
-
|
7
|
-
module URI
|
8
|
-
def decode(*args)
|
9
|
-
Addressable::URI.decode(*args)
|
10
|
-
end
|
1
|
+
$: << File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
|
11
2
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def parse(*args)
|
17
|
-
Addressable::URI.parse(*args)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
rescue LoadError => e
|
21
|
-
puts "Install the Addressable gem (with dependencies) to support accounts with subdomains."
|
22
|
-
puts "# sudo gem install addressable --development"
|
23
|
-
puts e.message
|
24
|
-
end
|
3
|
+
require 'rubygems'
|
4
|
+
require 'lighthouse/core_ext/uri'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_resource'
|
25
7
|
|
26
|
-
|
27
|
-
require '
|
8
|
+
# required for ruby < 1.9. constants(false) emaulation in active_support is buggy.
|
9
|
+
require 'lighthouse/base'
|
28
10
|
|
29
11
|
# Ruby lib for working with the Lighthouse API's XML interface.
|
30
12
|
# The first thing you need to set is the account name. This is the same
|
@@ -48,319 +30,69 @@ require 'activeresource'
|
|
48
30
|
# http://lighthouseapp.com/api.
|
49
31
|
#
|
50
32
|
module Lighthouse
|
33
|
+
|
34
|
+
extend ActiveSupport::Autoload
|
35
|
+
|
36
|
+
autoload :Bin
|
37
|
+
autoload :Changeset
|
38
|
+
autoload :Membership
|
39
|
+
autoload :Message
|
40
|
+
autoload :Milestone
|
41
|
+
autoload :Project
|
42
|
+
autoload :ProjectMembership
|
43
|
+
autoload :Tag
|
44
|
+
autoload :TagResource
|
45
|
+
autoload :Ticket
|
46
|
+
autoload :Token
|
47
|
+
autoload :User
|
48
|
+
|
51
49
|
class Error < StandardError; end
|
50
|
+
|
51
|
+
class Change < Array; end
|
52
|
+
|
52
53
|
class << self
|
53
|
-
attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
|
54
|
-
attr_reader :
|
55
|
-
|
56
|
-
# Sets the account name, and updates all the resources with the new domain.
|
57
|
-
def account=(name)
|
58
|
-
resources.each do |klass|
|
59
|
-
klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
|
60
|
-
end
|
61
|
-
@account = name
|
62
|
-
end
|
54
|
+
attr_accessor :account, :email, :password, :host_format, :domain_format, :protocol, :port
|
55
|
+
attr_reader :token
|
63
56
|
|
64
57
|
# Sets up basic authentication credentials for all the resources.
|
65
58
|
def authenticate(email, password)
|
66
|
-
|
67
|
-
|
59
|
+
self.email = email
|
60
|
+
self.password = password
|
61
|
+
|
62
|
+
resources.each do |klass|
|
63
|
+
update_auth(klass)
|
64
|
+
end
|
68
65
|
end
|
69
66
|
|
70
67
|
# Sets the API token for all the resources.
|
71
68
|
def token=(value)
|
69
|
+
@token = value
|
72
70
|
resources.each do |klass|
|
73
|
-
klass
|
71
|
+
update_token_header(klass)
|
74
72
|
end
|
75
|
-
@token = value
|
76
73
|
end
|
77
74
|
|
78
75
|
def resources
|
79
76
|
@resources ||= []
|
80
77
|
end
|
81
|
-
end
|
82
|
-
|
83
|
-
self.host_format = '%s://%s%s'
|
84
|
-
self.domain_format = '%s.lighthouseapp.com'
|
85
|
-
self.protocol = 'http'
|
86
|
-
self.port = ''
|
87
|
-
|
88
|
-
class Base < ActiveResource::Base
|
89
|
-
def self.inherited(base)
|
90
|
-
Lighthouse.resources << base
|
91
|
-
class << base
|
92
|
-
attr_accessor :site_format
|
93
|
-
end
|
94
|
-
base.site_format = '%s'
|
95
|
-
super
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Find projects
|
100
|
-
#
|
101
|
-
# Lighthouse::Project.find(:all) # find all projects for the current account.
|
102
|
-
# Lighthouse::Project.find(44) # find individual project by ID
|
103
|
-
#
|
104
|
-
# Creating a Project
|
105
|
-
#
|
106
|
-
# project = Lighthouse::Project.new(:name => 'Ninja Whammy Jammy')
|
107
|
-
# project.save
|
108
|
-
# # => true
|
109
|
-
#
|
110
|
-
# Creating an OSS project
|
111
|
-
#
|
112
|
-
# project = Lighthouse::Project.new(:name => 'OSS Project')
|
113
|
-
# project.access = 'oss'
|
114
|
-
# project.license = 'mit'
|
115
|
-
# project.save
|
116
|
-
#
|
117
|
-
# OSS License Mappings
|
118
|
-
#
|
119
|
-
# 'mit' => "MIT License",
|
120
|
-
# 'apache-2-0' => "Apache License 2.0",
|
121
|
-
# 'artistic-gpl-2' => "Artistic License/GPLv2",
|
122
|
-
# 'gpl-2' => "GNU General Public License v2",
|
123
|
-
# 'gpl-3' => "GNU General Public License v3",
|
124
|
-
# 'lgpl' => "GNU Lesser General Public License"
|
125
|
-
# 'mozilla-1-1' => "Mozilla Public License 1.1"
|
126
|
-
# 'new-bsd' => "New BSD License",
|
127
|
-
# 'afl-3' => "Academic Free License v. 3.0"
|
128
|
-
|
129
|
-
#
|
130
|
-
# Updating a Project
|
131
|
-
#
|
132
|
-
# project = Lighthouse::Project.find(44)
|
133
|
-
# project.name = "Lighthouse Issues"
|
134
|
-
# project.public = false
|
135
|
-
# project.save
|
136
|
-
#
|
137
|
-
# Finding tickets
|
138
|
-
#
|
139
|
-
# project = Lighthouse::Project.find(44)
|
140
|
-
# project.tickets
|
141
|
-
#
|
142
|
-
class Project < Base
|
143
|
-
def tickets(options = {})
|
144
|
-
Ticket.find(:all, :params => options.update(:project_id => id))
|
145
|
-
end
|
146
|
-
|
147
|
-
def messages(options = {})
|
148
|
-
Message.find(:all, :params => options.update(:project_id => id))
|
149
|
-
end
|
150
|
-
|
151
|
-
def milestones(options = {})
|
152
|
-
Milestone.find(:all, :params => options.update(:project_id => id))
|
153
|
-
end
|
154
|
-
|
155
|
-
def bins(options = {})
|
156
|
-
Bin.find(:all, :params => options.update(:project_id => id))
|
157
|
-
end
|
158
78
|
|
159
|
-
def
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
def memberships(options = {})
|
164
|
-
ProjectMembership.find(:all, :params => options.update(:project_id => id))
|
165
|
-
end
|
166
|
-
|
167
|
-
def tags(options = {})
|
168
|
-
TagResource.find(:all, :params => options.update(:project_id => id))
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
class User < Base
|
173
|
-
def memberships(options = {})
|
174
|
-
Membership.find(:all, :params => {:user_id => id})
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
class Membership < Base
|
179
|
-
site_format << '/users/:user_id'
|
180
|
-
def save
|
181
|
-
raise Error, "Cannot modify memberships from the API"
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
class ProjectMembership < Base
|
186
|
-
self.element_name = 'membership'
|
187
|
-
site_format << '/projects/:project_id'
|
188
|
-
|
189
|
-
def url
|
190
|
-
respond_to?(:account) ? account : project
|
191
|
-
end
|
192
|
-
|
193
|
-
def save
|
194
|
-
raise Error, "Cannot modify memberships from the API"
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
class Token < Base
|
199
|
-
def save
|
200
|
-
raise Error, "Cannot modify Tokens from the API"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
# Find tickets
|
205
|
-
#
|
206
|
-
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44 })
|
207
|
-
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
|
208
|
-
#
|
209
|
-
# project = Lighthouse::Project.find(44)
|
210
|
-
# project.tickets
|
211
|
-
# project.tickets(:q => "state:closed tagged:committed")
|
212
|
-
#
|
213
|
-
# Creating a Ticket
|
214
|
-
#
|
215
|
-
# ticket = Lighthouse::Ticket.new(:project_id => 44)
|
216
|
-
# ticket.title = 'asdf'
|
217
|
-
# ...
|
218
|
-
# ticket.tags << 'ruby' << 'rails' << '@high'
|
219
|
-
# ticket.save
|
220
|
-
#
|
221
|
-
# Updating a Ticket
|
222
|
-
#
|
223
|
-
# ticket = Lighthouse::Ticket.find(20, :params => { :project_id => 44 })
|
224
|
-
# ticket.state = 'resolved'
|
225
|
-
# ticket.tags.delete '@high'
|
226
|
-
# ticket.save
|
227
|
-
#
|
228
|
-
class Ticket < Base
|
229
|
-
attr_writer :tags
|
230
|
-
site_format << '/projects/:project_id'
|
231
|
-
|
232
|
-
def id
|
233
|
-
attributes['number'] ||= nil
|
234
|
-
number
|
235
|
-
end
|
236
|
-
|
237
|
-
def tags
|
238
|
-
attributes['tag'] ||= nil
|
239
|
-
@tags ||= tag.blank? ? [] : parse_with_spaces(tag)
|
240
|
-
end
|
241
|
-
|
242
|
-
def body
|
243
|
-
attributes['body'] ||= ''
|
244
|
-
end
|
245
|
-
|
246
|
-
def body=(value)
|
247
|
-
attributes['body'] = value
|
248
|
-
end
|
249
|
-
|
250
|
-
def body_html
|
251
|
-
attributes['body_html'] ||= ''
|
252
|
-
end
|
253
|
-
|
254
|
-
def body_html=(value)
|
255
|
-
attributes['body_html'] = value
|
256
|
-
end
|
257
|
-
|
258
|
-
def save_with_tags
|
259
|
-
self.tag = @tags.collect do |tag|
|
260
|
-
tag.include?(' ') ? tag.inspect : tag
|
261
|
-
end.join(" ") if @tags.is_a?(Array)
|
262
|
-
@tags = nil ; save_without_tags
|
79
|
+
def update_site(resource)
|
80
|
+
resource.site = resource.site_format % (host_format % [protocol, domain_format % account, ":#{port}"])
|
263
81
|
end
|
264
82
|
|
265
|
-
|
266
|
-
|
267
|
-
private
|
268
|
-
# taken from Lighthouse Tag code
|
269
|
-
def parse_with_spaces(list)
|
270
|
-
tags = []
|
271
|
-
|
272
|
-
# first, pull out the quoted tags
|
273
|
-
list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
|
274
|
-
|
275
|
-
# then, get whatever's left
|
276
|
-
tags.concat list.split(/\s/)
|
277
|
-
|
278
|
-
cleanup_tags(tags)
|
279
|
-
end
|
280
|
-
|
281
|
-
def cleanup_tags(tags)
|
282
|
-
returning tags do |tag|
|
283
|
-
tag.collect! do |t|
|
284
|
-
unless tag.blank?
|
285
|
-
t = Tag.new(t,prefix_options[:project_id])
|
286
|
-
t.downcase!
|
287
|
-
t.gsub! /(^')|('$)/, ''
|
288
|
-
t.gsub! /[^a-z0-9 \-_@\!']/, ''
|
289
|
-
t.strip!
|
290
|
-
t.prefix_options = prefix_options
|
291
|
-
t
|
292
|
-
end
|
293
|
-
end
|
294
|
-
tag.compact!
|
295
|
-
tag.uniq!
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
class Message < Base
|
301
|
-
site_format << '/projects/:project_id'
|
302
|
-
end
|
303
|
-
|
304
|
-
class Milestone < Base
|
305
|
-
site_format << '/projects/:project_id'
|
306
|
-
|
307
|
-
def tickets(options = {})
|
308
|
-
Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{milestone:"#{title}"}))
|
83
|
+
def update_token_header(resource)
|
84
|
+
resource.headers['X-LighthouseToken'] = token if token
|
309
85
|
end
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
def tickets(options = {})
|
316
|
-
Ticket.find(:all, :params => options.merge(prefix_options).update(:q => query))
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
class Changeset < Base
|
321
|
-
site_format << '/projects/:project_id'
|
322
|
-
end
|
323
|
-
|
324
|
-
class Change < Array; end
|
325
|
-
|
326
|
-
class TagResource < Base
|
327
|
-
self.element_name = 'tag'
|
328
|
-
site_format << '/projects/:project_id'
|
329
|
-
|
330
|
-
def name
|
331
|
-
@name ||= Tag.new(attributes['name'], prefix_options[:project_id])
|
332
|
-
end
|
333
|
-
|
334
|
-
def tickets(options = {})
|
335
|
-
name.tickets(options)
|
86
|
+
|
87
|
+
def update_auth(resource)
|
88
|
+
return unless email && password
|
89
|
+
resource.user = email
|
90
|
+
resource.password = password
|
336
91
|
end
|
337
92
|
end
|
338
93
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
def initialize(s, project_id)
|
344
|
-
@project_id = project_id
|
345
|
-
super(s)
|
346
|
-
end
|
347
|
-
|
348
|
-
def prefix_options
|
349
|
-
@prefix_options || {}
|
350
|
-
end
|
351
|
-
|
352
|
-
def tickets(options = {})
|
353
|
-
options[:project_id] ||= @project_id
|
354
|
-
Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{tagged:"#{self}"}))
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
module ActiveResource
|
360
|
-
class Connection
|
361
|
-
private
|
362
|
-
def authorization_header
|
363
|
-
(Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
|
364
|
-
end
|
365
|
-
end
|
94
|
+
self.host_format = '%s://%s%s'
|
95
|
+
self.domain_format = '%s.lighthouseapp.com'
|
96
|
+
self.protocol = 'http'
|
97
|
+
self.port = ''
|
366
98
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Lighthouse
|
2
|
+
class Base < ActiveResource::Base
|
3
|
+
def self.inherited(base)
|
4
|
+
Lighthouse.resources << base
|
5
|
+
class << base
|
6
|
+
attr_accessor :site_format
|
7
|
+
|
8
|
+
def site_with_update
|
9
|
+
Lighthouse.update_site(self)
|
10
|
+
site_without_update
|
11
|
+
end
|
12
|
+
alias_method_chain :site, :update
|
13
|
+
end
|
14
|
+
base.site_format = '%s'
|
15
|
+
super
|
16
|
+
Lighthouse.update_token_header(base)
|
17
|
+
Lighthouse.update_auth(base)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/lighthouse/console.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
begin
|
2
|
+
require 'uri'
|
3
|
+
require 'addressable/uri'
|
4
|
+
|
5
|
+
module URI
|
6
|
+
def decode(*args)
|
7
|
+
Addressable::URI.decode(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def escape(*args)
|
11
|
+
Addressable::URI.escape(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(*args)
|
15
|
+
Addressable::URI.parse(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rescue LoadError => e
|
19
|
+
puts "Install the Addressable gem (with dependencies) to support accounts with subdomains."
|
20
|
+
puts "# sudo gem install addressable --development"
|
21
|
+
puts e.message
|
22
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Lighthouse
|
2
|
+
# Find projects
|
3
|
+
#
|
4
|
+
# Lighthouse::Project.find(:all) # find all projects for the current account.
|
5
|
+
# Lighthouse::Project.find(44) # find individual project by ID
|
6
|
+
#
|
7
|
+
# Creating a Project
|
8
|
+
#
|
9
|
+
# project = Lighthouse::Project.new(:name => 'Ninja Whammy Jammy')
|
10
|
+
# project.save
|
11
|
+
# # => true
|
12
|
+
#
|
13
|
+
# Creating an OSS project
|
14
|
+
#
|
15
|
+
# project = Lighthouse::Project.new(:name => 'OSS Project')
|
16
|
+
# project.access = 'oss'
|
17
|
+
# project.license = 'mit'
|
18
|
+
# project.save
|
19
|
+
#
|
20
|
+
# OSS License Mappings
|
21
|
+
#
|
22
|
+
# 'mit' => "MIT License",
|
23
|
+
# 'apache-2-0' => "Apache License 2.0",
|
24
|
+
# 'artistic-gpl-2' => "Artistic License/GPLv2",
|
25
|
+
# 'gpl-2' => "GNU General Public License v2",
|
26
|
+
# 'gpl-3' => "GNU General Public License v3",
|
27
|
+
# 'lgpl' => "GNU Lesser General Public License"
|
28
|
+
# 'mozilla-1-1' => "Mozilla Public License 1.1"
|
29
|
+
# 'new-bsd' => "New BSD License",
|
30
|
+
# 'afl-3' => "Academic Free License v. 3.0"
|
31
|
+
|
32
|
+
#
|
33
|
+
# Updating a Project
|
34
|
+
#
|
35
|
+
# project = Lighthouse::Project.find(44)
|
36
|
+
# project.name = "Lighthouse Issues"
|
37
|
+
# project.public = false
|
38
|
+
# project.save
|
39
|
+
#
|
40
|
+
# Finding tickets
|
41
|
+
#
|
42
|
+
# project = Lighthouse::Project.find(44)
|
43
|
+
# project.tickets
|
44
|
+
#
|
45
|
+
class Project < Base
|
46
|
+
def tickets(options = {})
|
47
|
+
Ticket.find(:all, :params => options.update(:project_id => id))
|
48
|
+
end
|
49
|
+
|
50
|
+
def messages(options = {})
|
51
|
+
Message.find(:all, :params => options.update(:project_id => id))
|
52
|
+
end
|
53
|
+
|
54
|
+
def milestones(options = {})
|
55
|
+
Milestone.find(:all, :params => options.update(:project_id => id))
|
56
|
+
end
|
57
|
+
|
58
|
+
def bins(options = {})
|
59
|
+
Bin.find(:all, :params => options.update(:project_id => id))
|
60
|
+
end
|
61
|
+
|
62
|
+
def changesets(options = {})
|
63
|
+
Changeset.find(:all, :params => options.update(:project_id => id))
|
64
|
+
end
|
65
|
+
|
66
|
+
def memberships(options = {})
|
67
|
+
ProjectMembership.find(:all, :params => options.update(:project_id => id))
|
68
|
+
end
|
69
|
+
|
70
|
+
def tags(options = {})
|
71
|
+
TagResource.find(:all, :params => options.update(:project_id => id))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/core_ext/module/attr_accessor_with_default'
|
2
|
+
|
3
|
+
module Lighthouse
|
4
|
+
class Tag < String
|
5
|
+
attr_accessor_with_default :prefix_options, {}
|
6
|
+
attr_accessor :project_id
|
7
|
+
|
8
|
+
def initialize(s, project_id)
|
9
|
+
self.project_id = project_id
|
10
|
+
super(s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def tickets(options = {})
|
14
|
+
options[:project_id] ||= project_id
|
15
|
+
Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{tagged:"#{self}"}))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lighthouse
|
2
|
+
class TagResource < Base
|
3
|
+
self.element_name = 'tag'
|
4
|
+
site_format << '/projects/:project_id'
|
5
|
+
|
6
|
+
def name
|
7
|
+
@name ||= Tag.new(attributes['name'], prefix_options[:project_id])
|
8
|
+
end
|
9
|
+
|
10
|
+
def tickets(options = {})
|
11
|
+
name.tickets(options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Lighthouse
|
2
|
+
# Find tickets
|
3
|
+
#
|
4
|
+
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44 })
|
5
|
+
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
|
6
|
+
#
|
7
|
+
# project = Lighthouse::Project.find(44)
|
8
|
+
# project.tickets
|
9
|
+
# project.tickets(:q => "state:closed tagged:committed")
|
10
|
+
#
|
11
|
+
# Creating a Ticket
|
12
|
+
#
|
13
|
+
# ticket = Lighthouse::Ticket.new(:project_id => 44)
|
14
|
+
# ticket.title = 'asdf'
|
15
|
+
# ...
|
16
|
+
# ticket.tags << 'ruby' << 'rails' << '@high'
|
17
|
+
# ticket.save
|
18
|
+
#
|
19
|
+
# Updating a Ticket
|
20
|
+
#
|
21
|
+
# ticket = Lighthouse::Ticket.find(20, :params => { :project_id => 44 })
|
22
|
+
# ticket.state = 'resolved'
|
23
|
+
# ticket.tags.delete '@high'
|
24
|
+
# ticket.save
|
25
|
+
#
|
26
|
+
class Ticket < Base
|
27
|
+
|
28
|
+
attr_writer :tags
|
29
|
+
site_format << '/projects/:project_id'
|
30
|
+
|
31
|
+
def id
|
32
|
+
attributes['number'] ||= nil
|
33
|
+
number
|
34
|
+
end
|
35
|
+
|
36
|
+
def tags
|
37
|
+
attributes['tag'] ||= nil
|
38
|
+
@tags ||= tag.blank? ? [] : parse_with_spaces(tag)
|
39
|
+
end
|
40
|
+
|
41
|
+
def body
|
42
|
+
attributes['body'] ||= ''
|
43
|
+
end
|
44
|
+
|
45
|
+
def body=(value)
|
46
|
+
attributes['body'] = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def body_html
|
50
|
+
attributes['body_html'] ||= ''
|
51
|
+
end
|
52
|
+
|
53
|
+
def body_html=(value)
|
54
|
+
attributes['body_html'] = value
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_with_tags
|
58
|
+
self.tag = self.tags.collect do |tag|
|
59
|
+
tag.include?(' ') ? tag.inspect : tag
|
60
|
+
end.join(" ") if self.tags.is_a?(Array)
|
61
|
+
|
62
|
+
self.tags = nil
|
63
|
+
|
64
|
+
save_without_tags
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method_chain :save, :tags
|
68
|
+
|
69
|
+
private
|
70
|
+
# taken from Lighthouse Tag code
|
71
|
+
def parse_with_spaces(list)
|
72
|
+
tags = []
|
73
|
+
|
74
|
+
# first, pull out the quoted tags
|
75
|
+
list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
|
76
|
+
|
77
|
+
# then, get whatever's left
|
78
|
+
tags.concat list.split(/\s/)
|
79
|
+
|
80
|
+
cleanup_tags(tags)
|
81
|
+
end
|
82
|
+
|
83
|
+
def cleanup_tags(tags)
|
84
|
+
returning tags do |tag|
|
85
|
+
tag.collect! do |t|
|
86
|
+
unless tag.blank?
|
87
|
+
t = Tag.new(t,prefix_options[:project_id])
|
88
|
+
t.downcase!
|
89
|
+
t.gsub! /(^')|('$)/, ''
|
90
|
+
t.gsub! /[^a-z0-9 \-_@\!']/, ''
|
91
|
+
t.strip!
|
92
|
+
t.prefix_options = prefix_options
|
93
|
+
t
|
94
|
+
end
|
95
|
+
end
|
96
|
+
tag.compact!
|
97
|
+
tag.uniq!
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
CHANGED
@@ -1,39 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lighthouse-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: "2.0"
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
- Rick
|
12
|
+
- Rick Olson
|
8
13
|
- Justin Palmer
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date:
|
18
|
+
date: 2010-10-04 00:00:00 -07:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: activesupport
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
26
37
|
- !ruby/object:Gem::Dependency
|
27
38
|
name: activeresource
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
31
42
|
requirements:
|
32
43
|
- - ">="
|
33
44
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 3.0.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Ruby API wrapper for Lighthouse - http://lighthouseapp.com
|
37
54
|
email:
|
38
55
|
- justin@entp.com
|
39
56
|
executables: []
|
@@ -43,11 +60,25 @@ extensions: []
|
|
43
60
|
extra_rdoc_files:
|
44
61
|
- LICENSE
|
45
62
|
files:
|
46
|
-
-
|
47
|
-
-
|
63
|
+
- lib/lighthouse/base.rb
|
64
|
+
- lib/lighthouse/bin.rb
|
65
|
+
- lib/lighthouse/changeset.rb
|
66
|
+
- lib/lighthouse/console.rb
|
67
|
+
- lib/lighthouse/core_ext/uri.rb
|
68
|
+
- lib/lighthouse/membership.rb
|
69
|
+
- lib/lighthouse/message.rb
|
70
|
+
- lib/lighthouse/milestone.rb
|
71
|
+
- lib/lighthouse/project.rb
|
72
|
+
- lib/lighthouse/project_membership.rb
|
73
|
+
- lib/lighthouse/tag.rb
|
74
|
+
- lib/lighthouse/tag_resource.rb
|
75
|
+
- lib/lighthouse/ticket.rb
|
76
|
+
- lib/lighthouse/token.rb
|
77
|
+
- lib/lighthouse/user.rb
|
48
78
|
- lib/lighthouse-api.rb
|
49
79
|
- lib/lighthouse.rb
|
50
|
-
-
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
51
82
|
has_rdoc: true
|
52
83
|
homepage: http://lighthouseapp.com/api
|
53
84
|
licenses: []
|
@@ -55,27 +86,33 @@ licenses: []
|
|
55
86
|
post_install_message:
|
56
87
|
rdoc_options:
|
57
88
|
- --main
|
58
|
-
- README.
|
89
|
+
- README.md
|
59
90
|
require_paths:
|
60
91
|
- lib
|
61
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
62
94
|
requirements:
|
63
95
|
- - ">="
|
64
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
65
100
|
version: "0"
|
66
|
-
version:
|
67
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
68
103
|
requirements:
|
69
104
|
- - ">="
|
70
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
71
109
|
version: "0"
|
72
|
-
version:
|
73
110
|
requirements: []
|
74
111
|
|
75
112
|
rubyforge_project: lighthouse
|
76
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.7
|
77
114
|
signing_key:
|
78
115
|
specification_version: 3
|
79
|
-
summary:
|
116
|
+
summary: Ruby API wrapper for Lighthouse - http://lighthouseapp.com
|
80
117
|
test_files: []
|
81
118
|
|