Caged-lighthouse-api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +27 -0
- data/lib/lighthouse-api.rb +1 -0
- data/lib/lighthouse.rb +263 -0
- data/lib/lighthouse/console.rb +25 -0
- metadata +77 -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,263 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activesupport'
|
3
|
+
require 'activeresource'
|
4
|
+
|
5
|
+
# Ruby lib for working with the Lighthouse API's XML interface.
|
6
|
+
# The first thing you need to set is the account name. This is the same
|
7
|
+
# as the web address for your account.
|
8
|
+
#
|
9
|
+
# Lighthouse.account = 'activereload'
|
10
|
+
#
|
11
|
+
# Then, you should set the authentication. You can either use your login
|
12
|
+
# credentials with HTTP Basic Authentication or with an API Tokens. You can
|
13
|
+
# find more info on tokens at http://lighthouseapp.com/help/using-beacons.
|
14
|
+
#
|
15
|
+
# # with basic authentication
|
16
|
+
# Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
|
17
|
+
#
|
18
|
+
# # or, use a token
|
19
|
+
# Lighthouse.token = 'abcdefg'
|
20
|
+
#
|
21
|
+
# If no token or authentication info is given, you'll only be granted public access.
|
22
|
+
#
|
23
|
+
# This library is a small wrapper around the REST interface. You should read the docs at
|
24
|
+
# http://lighthouseapp.com/api.
|
25
|
+
#
|
26
|
+
module Lighthouse
|
27
|
+
class Error < StandardError; end
|
28
|
+
class << self
|
29
|
+
attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
|
30
|
+
attr_reader :account, :token
|
31
|
+
|
32
|
+
# Sets the account name, and updates all the resources with the new domain.
|
33
|
+
def account=(name)
|
34
|
+
resources.each do |klass|
|
35
|
+
klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
|
36
|
+
end
|
37
|
+
@account = name
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets up basic authentication credentials for all the resources.
|
41
|
+
def authenticate(email, password)
|
42
|
+
@email = email
|
43
|
+
@password = password
|
44
|
+
end
|
45
|
+
|
46
|
+
# Sets the API token for all the resources.
|
47
|
+
def token=(value)
|
48
|
+
resources.each do |klass|
|
49
|
+
klass.headers['X-LighthouseToken'] = value
|
50
|
+
end
|
51
|
+
@token = value
|
52
|
+
end
|
53
|
+
|
54
|
+
def resources
|
55
|
+
@resources ||= []
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
self.host_format = '%s://%s%s'
|
60
|
+
self.domain_format = '%s.lighthouseapp.com'
|
61
|
+
self.protocol = 'http'
|
62
|
+
self.port = ''
|
63
|
+
|
64
|
+
class Base < ActiveResource::Base
|
65
|
+
def self.inherited(base)
|
66
|
+
Lighthouse.resources << base
|
67
|
+
class << base
|
68
|
+
attr_accessor :site_format
|
69
|
+
end
|
70
|
+
base.site_format = '%s'
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Find projects
|
76
|
+
#
|
77
|
+
# Lighthouse::Project.find(:all) # find all projects for the current account.
|
78
|
+
# Lighthouse::Project.find(44) # find individual project by ID
|
79
|
+
#
|
80
|
+
# Creating a Project
|
81
|
+
#
|
82
|
+
# project = Lighthouse::Project.new(:name => 'Ninja Whammy Jammy')
|
83
|
+
# project.save
|
84
|
+
# # => true
|
85
|
+
#
|
86
|
+
# Creating an OSS project
|
87
|
+
#
|
88
|
+
# project = Lighthouse::Project.new(:name => 'OSS Project')
|
89
|
+
# project.access = 'oss'
|
90
|
+
# project.license = 'mit'
|
91
|
+
# project.save
|
92
|
+
#
|
93
|
+
# OSS License Mappings
|
94
|
+
#
|
95
|
+
# 'mit' => "MIT License",
|
96
|
+
# 'apache-2-0' => "Apache License 2.0",
|
97
|
+
# 'artistic-gpl-2' => "Artistic License/GPLv2",
|
98
|
+
# 'gpl-2' => "GNU General Public License v2",
|
99
|
+
# 'gpl-3' => "GNU General Public License v3",
|
100
|
+
# 'lgpl' => "GNU Lesser General Public License"
|
101
|
+
# 'mozilla-1-1' => "Mozilla Public License 1.1"
|
102
|
+
# 'new-bsd' => "New BSD License",
|
103
|
+
# 'afl-3' => "Academic Free License v. 3.0"
|
104
|
+
|
105
|
+
#
|
106
|
+
# Updating a Project
|
107
|
+
#
|
108
|
+
# project = Lighthouse::Project.find(44)
|
109
|
+
# project.name = "Lighthouse Issues"
|
110
|
+
# project.public = false
|
111
|
+
# project.save
|
112
|
+
#
|
113
|
+
# Finding tickets
|
114
|
+
#
|
115
|
+
# project = Lighthouse::Project.find(44)
|
116
|
+
# project.tickets
|
117
|
+
#
|
118
|
+
class Project < Base
|
119
|
+
def tickets(options = {})
|
120
|
+
Ticket.find(:all, :params => options.update(:project_id => id))
|
121
|
+
end
|
122
|
+
|
123
|
+
def messages(options = {})
|
124
|
+
Message.find(:all, :params => options.update(:project_id => id))
|
125
|
+
end
|
126
|
+
|
127
|
+
def milestones(options = {})
|
128
|
+
Milestone.find(:all, :params => options.update(:project_id => id))
|
129
|
+
end
|
130
|
+
|
131
|
+
def bins(options = {})
|
132
|
+
Bin.find(:all, :params => options.update(:project_id => id))
|
133
|
+
end
|
134
|
+
|
135
|
+
def changesets(options = {})
|
136
|
+
Changeset.find(:all, :params => options.update(:project_id => id))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class User < Base
|
141
|
+
def memberships
|
142
|
+
Membership.find(:all, :params => {:user_id => id})
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Membership < Base
|
147
|
+
site_format << '/users/:user_id'
|
148
|
+
def save
|
149
|
+
raise Error, "Cannot modify memberships from the API"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class Token < Base
|
154
|
+
def save
|
155
|
+
raise Error, "Cannot modify Tokens from the API"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Find tickets
|
160
|
+
#
|
161
|
+
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44 })
|
162
|
+
# Lighthouse::Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
|
163
|
+
#
|
164
|
+
# project = Lighthouse::Project.find(44)
|
165
|
+
# project.tickets
|
166
|
+
# project.tickets(:q => "state:closed tagged:committed")
|
167
|
+
#
|
168
|
+
# Creating a Ticket
|
169
|
+
#
|
170
|
+
# ticket = Lighthouse::Ticket.new(:project_id => 44)
|
171
|
+
# ticket.title = 'asdf'
|
172
|
+
# ...
|
173
|
+
# ticket.tags << 'ruby' << 'rails' << '@high'
|
174
|
+
# ticket.save
|
175
|
+
#
|
176
|
+
# Updating a Ticket
|
177
|
+
#
|
178
|
+
# ticket = Lighthouse::Ticket.find(20, :params => { :project_id => 44 })
|
179
|
+
# ticket.state = 'resolved'
|
180
|
+
# ticket.tags.delete '@high'
|
181
|
+
# ticket.save
|
182
|
+
#
|
183
|
+
class Ticket < Base
|
184
|
+
attr_writer :tags
|
185
|
+
site_format << '/projects/:project_id'
|
186
|
+
|
187
|
+
def id
|
188
|
+
attributes['number'] ||= nil
|
189
|
+
number
|
190
|
+
end
|
191
|
+
|
192
|
+
def tags
|
193
|
+
attributes['tag'] ||= nil
|
194
|
+
@tags ||= tag.blank? ? [] : parse_with_spaces(tag)
|
195
|
+
end
|
196
|
+
|
197
|
+
def save_with_tags
|
198
|
+
self.tag = @tags.collect do |tag|
|
199
|
+
tag.include?(' ') ? tag.inspect : tag
|
200
|
+
end.join(" ") if @tags.is_a?(Array)
|
201
|
+
@tags = nil ; save_without_tags
|
202
|
+
end
|
203
|
+
|
204
|
+
alias_method_chain :save, :tags
|
205
|
+
|
206
|
+
private
|
207
|
+
# taken from Lighthouse Tag code
|
208
|
+
def parse_with_spaces(list)
|
209
|
+
tags = []
|
210
|
+
|
211
|
+
# first, pull out the quoted tags
|
212
|
+
list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
|
213
|
+
|
214
|
+
# then, get whatever's left
|
215
|
+
tags.concat list.split(/\s/)
|
216
|
+
|
217
|
+
cleanup_tags(tags)
|
218
|
+
end
|
219
|
+
|
220
|
+
def cleanup_tags(tags)
|
221
|
+
returning tags do |tag|
|
222
|
+
tag.collect! do |t|
|
223
|
+
unless tag.blank?
|
224
|
+
t.downcase!
|
225
|
+
t.gsub! /(^')|('$)/, ''
|
226
|
+
t.gsub! /[^a-z0-9 \-_@\!']/, ''
|
227
|
+
t.strip!
|
228
|
+
t
|
229
|
+
end
|
230
|
+
end
|
231
|
+
tag.compact!
|
232
|
+
tag.uniq!
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class Message < Base
|
238
|
+
site_format << '/projects/:project_id'
|
239
|
+
end
|
240
|
+
|
241
|
+
class Milestone < Base
|
242
|
+
site_format << '/projects/:project_id'
|
243
|
+
end
|
244
|
+
|
245
|
+
class Bin < Base
|
246
|
+
site_format << '/projects/:project_id'
|
247
|
+
end
|
248
|
+
|
249
|
+
class Changeset < Base
|
250
|
+
site_format << '/projects/:project_id'
|
251
|
+
end
|
252
|
+
|
253
|
+
class Change < Array; end
|
254
|
+
end
|
255
|
+
|
256
|
+
module ActiveResource
|
257
|
+
class Connection
|
258
|
+
private
|
259
|
+
def authorization_header
|
260
|
+
(Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
|
261
|
+
end
|
262
|
+
end
|
263
|
+
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,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Caged-lighthouse-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
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
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activeresource
|
27
|
+
version_requirement:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
version:
|
34
|
+
description: RubyGem wrapper for ActiveResource API to http://lighthouseapp.com
|
35
|
+
email:
|
36
|
+
- FIXME email
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
- lib/lighthouse-api.rb
|
47
|
+
- lib/lighthouse.rb
|
48
|
+
- lib/lighthouse/console.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://lighthouseapp.com/api
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --main
|
54
|
+
- README.markdown
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: lighthouse
|
72
|
+
rubygems_version: 1.2.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 2
|
75
|
+
summary: RubyGem wrapper for ActiveResource API to http://lighthouseapp.com
|
76
|
+
test_files: []
|
77
|
+
|