texel-lighthouse-api 1.0.1
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/LICENSE +20 -0
- data/README.markdown +27 -0
- data/lib/lighthouse-api.rb +1 -0
- data/lib/lighthouse.rb +366 -0
- data/lib/lighthouse/console.rb +25 -0
- metadata +79 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Active Reload, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Lighthouse API
|
2
|
+
--------------
|
3
|
+
|
4
|
+
The official Ruby library for interacting with the [Lighthouse REST API](http://lighthouseapp.com/api).
|
5
|
+
|
6
|
+
### Documentation & Requirements
|
7
|
+
* ActiveResource
|
8
|
+
* ActiveSupport
|
9
|
+
|
10
|
+
Check out lib/lighthouse.rb for examples and documentation.
|
11
|
+
|
12
|
+
|
13
|
+
### Using The Lighthouse Console
|
14
|
+
|
15
|
+
The Lighthouse library comes with a convenient console for testing and quick commands
|
16
|
+
(or whatever else you want to use it for).
|
17
|
+
|
18
|
+
From /lib:
|
19
|
+
|
20
|
+
irb -r lighthouse/console
|
21
|
+
Lighthouse.account = "activereload"
|
22
|
+
|
23
|
+
#### You can use `authenticate` OR `token`
|
24
|
+
Lighthouse.authenticate('username', 'password')
|
25
|
+
#Lighthouse.token = 'YOUR_TOKEN'
|
26
|
+
|
27
|
+
Project.find(:all)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lighthouse"
|
data/lib/lighthouse.rb
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
require 'rubygems'
|
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
|
11
|
+
|
12
|
+
def escape(*args)
|
13
|
+
Addressable::URI.escape(*args)
|
14
|
+
end
|
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
|
25
|
+
|
26
|
+
require 'activesupport'
|
27
|
+
require 'activeresource'
|
28
|
+
|
29
|
+
# Ruby lib for working with the Lighthouse API's XML interface.
|
30
|
+
# The first thing you need to set is the account name. This is the same
|
31
|
+
# as the web address for your account.
|
32
|
+
#
|
33
|
+
# Lighthouse.account = 'activereload'
|
34
|
+
#
|
35
|
+
# Then, you should set the authentication. You can either use your login
|
36
|
+
# credentials with HTTP Basic Authentication or with an API Tokens. You can
|
37
|
+
# find more info on tokens at http://lighthouseapp.com/help/using-beacons.
|
38
|
+
#
|
39
|
+
# # with basic authentication
|
40
|
+
# Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
|
41
|
+
#
|
42
|
+
# # or, use a token
|
43
|
+
# Lighthouse.token = 'abcdefg'
|
44
|
+
#
|
45
|
+
# If no token or authentication info is given, you'll only be granted public access.
|
46
|
+
#
|
47
|
+
# This library is a small wrapper around the REST interface. You should read the docs at
|
48
|
+
# http://lighthouseapp.com/api.
|
49
|
+
#
|
50
|
+
module Lighthouse
|
51
|
+
class Error < StandardError; end
|
52
|
+
class << self
|
53
|
+
attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
|
54
|
+
attr_reader :account, :token
|
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
|
63
|
+
|
64
|
+
# Sets up basic authentication credentials for all the resources.
|
65
|
+
def authenticate(email, password)
|
66
|
+
@email = email
|
67
|
+
@password = password
|
68
|
+
end
|
69
|
+
|
70
|
+
# Sets the API token for all the resources.
|
71
|
+
def token=(value)
|
72
|
+
resources.each do |klass|
|
73
|
+
klass.headers['X-LighthouseToken'] = value
|
74
|
+
end
|
75
|
+
@token = value
|
76
|
+
end
|
77
|
+
|
78
|
+
def resources
|
79
|
+
@resources ||= []
|
80
|
+
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
|
+
|
159
|
+
def changesets(options = {})
|
160
|
+
Changeset.find(:all, :params => options.update(:project_id => id))
|
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
|
263
|
+
end
|
264
|
+
|
265
|
+
alias_method_chain :save, :tags
|
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)
|
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}"}))
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
class Bin < Base
|
313
|
+
site_format << '/projects/:project_id'
|
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)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
class Tag < String
|
340
|
+
attr_writer :prefix_options
|
341
|
+
attr_accessor :project_id
|
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
|
366
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'lighthouse'
|
2
|
+
puts <<-TXT
|
3
|
+
Ruby lib for working with the Lighthouse API's XML interface.
|
4
|
+
The first thing you need to set is the account name. This is the same
|
5
|
+
as the web address for your account.
|
6
|
+
|
7
|
+
Lighthouse.account = 'activereload'
|
8
|
+
|
9
|
+
Then, you should set the authentication. You can either use your login
|
10
|
+
credentials with HTTP Basic Authentication or with an API Tokens. You can
|
11
|
+
find more info on tokens at http://lighthouseapp.com/help/using-beacons.
|
12
|
+
|
13
|
+
# with basic authentication
|
14
|
+
Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
|
15
|
+
|
16
|
+
# or, use a token
|
17
|
+
Lighthouse.token = 'abcdefg'
|
18
|
+
|
19
|
+
If no token or authentication info is given, you'll only be granted public access.
|
20
|
+
|
21
|
+
This library is a small wrapper around the REST interface. You should read the docs at
|
22
|
+
http://lighthouseapp.com/api.
|
23
|
+
TXT
|
24
|
+
|
25
|
+
include Lighthouse
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: texel-lighthouse-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Olsen
|
8
|
+
- Justin Palmer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-09-19 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activesupport
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.1.0
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activeresource
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.1.0
|
35
|
+
version:
|
36
|
+
description: RubyGem wrapper for ActiveResource API to http://lighthouseapp.com
|
37
|
+
email:
|
38
|
+
- FIXME email
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
files:
|
46
|
+
- LICENSE
|
47
|
+
- README.markdown
|
48
|
+
- lib/lighthouse-api.rb
|
49
|
+
- lib/lighthouse.rb
|
50
|
+
- lib/lighthouse/console.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://lighthouseapp.com/api
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --main
|
56
|
+
- README.markdown
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: lighthouse
|
74
|
+
rubygems_version: 1.2.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: RubyGem wrapper for ActiveResource API to http://lighthouseapp.com
|
78
|
+
test_files: []
|
79
|
+
|