cyberfox-lighthouse-api 1.0.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/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,328 @@
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
21
+ puts "Install the Addressable gem to support accounts with subdomains."
22
+ puts "# sudo gem install addressable"
23
+ puts
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
+ end
163
+
164
+ class User < Base
165
+ def memberships
166
+ Membership.find(:all, :params => {:user_id => id})
167
+ end
168
+ end
169
+
170
+ class Membership < Base
171
+ site_format << '/users/:user_id'
172
+ def save
173
+ raise Error, "Cannot modify memberships from the API"
174
+ end
175
+ end
176
+
177
+ class Token < Base
178
+ def save
179
+ raise Error, "Cannot modify Tokens from the API"
180
+ end
181
+ end
182
+
183
+ # Find tickets
184
+ #
185
+ # Lighthouse::Ticket.find(:all, :params => { :project_id => 44 })
186
+ # Lighthouse::Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
187
+ #
188
+ # project = Lighthouse::Project.find(44)
189
+ # project.tickets
190
+ # project.tickets(:q => "state:closed tagged:committed")
191
+ #
192
+ # Creating a Ticket
193
+ #
194
+ # ticket = Lighthouse::Ticket.new(:project_id => 44)
195
+ # ticket.title = 'asdf'
196
+ # ...
197
+ # ticket.tags << 'ruby' << 'rails' << '@high'
198
+ # ticket.save
199
+ #
200
+ # Updating a Ticket
201
+ #
202
+ # ticket = Lighthouse::Ticket.find(20, :params => { :project_id => 44 })
203
+ # ticket.state = 'resolved'
204
+ # ticket.tags.delete '@high'
205
+ # ticket.save
206
+ #
207
+ class Ticket < Base
208
+ attr_writer :tags
209
+ site_format << '/projects/:project_id'
210
+
211
+ def id
212
+ attributes['number'] ||= nil
213
+ number
214
+ end
215
+
216
+ def tags
217
+ attributes['tag'] ||= nil
218
+ @tags ||= tag.blank? ? [] : parse_with_spaces(tag)
219
+ end
220
+
221
+ def body
222
+ attributes['body'] ||= ''
223
+ end
224
+
225
+ def body=(value)
226
+ attributes['body'] = value
227
+ end
228
+
229
+ def body_html
230
+ attributes['body_html'] ||= ''
231
+ end
232
+
233
+ def body_html=(value)
234
+ attributes['body_html'] = value
235
+ end
236
+
237
+ def save_with_tags
238
+ self.tag = @tags.collect do |tag|
239
+ tag.include?(' ') ? tag.inspect : tag
240
+ end.join(" ") if @tags.is_a?(Array)
241
+ @tags = nil ; save_without_tags
242
+ end
243
+
244
+ alias_method_chain :save, :tags
245
+
246
+ private
247
+ # taken from Lighthouse Tag code
248
+ def parse_with_spaces(list)
249
+ tags = []
250
+
251
+ # first, pull out the quoted tags
252
+ list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
253
+
254
+ # then, get whatever's left
255
+ tags.concat list.split(/\s/)
256
+
257
+ cleanup_tags(tags)
258
+ end
259
+
260
+ def cleanup_tags(tags)
261
+ returning tags do |tag|
262
+ tag.collect! do |t|
263
+ unless tag.blank?
264
+ t = Tag.new(t)
265
+ t.downcase!
266
+ t.gsub! /(^')|('$)/, ''
267
+ t.gsub! /[^a-z0-9 \-_@\!']/, ''
268
+ t.strip!
269
+ t.prefix_options = prefix_options
270
+ t
271
+ end
272
+ end
273
+ tag.compact!
274
+ tag.uniq!
275
+ end
276
+ end
277
+
278
+ class Version < Base
279
+ site_format << '/projects/:project_id'
280
+ end
281
+ end
282
+
283
+ class Message < Base
284
+ site_format << '/projects/:project_id'
285
+ end
286
+
287
+ class Milestone < Base
288
+ site_format << '/projects/:project_id'
289
+
290
+ def tickets(options = {})
291
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{milestone:"#{title}"}))
292
+ end
293
+ end
294
+
295
+ class Bin < Base
296
+ site_format << '/projects/:project_id'
297
+
298
+ def tickets(options = {})
299
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => query))
300
+ end
301
+ end
302
+
303
+ class Changeset < Base
304
+ site_format << '/projects/:project_id'
305
+ end
306
+
307
+ class Change < Array; end
308
+
309
+ class Tag < String
310
+ attr_writer :prefix_options
311
+ def prefix_options
312
+ @prefix_options || {}
313
+ end
314
+
315
+ def tickets(options = {})
316
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{tagged:"#{self}"}))
317
+ end
318
+ end
319
+ end
320
+
321
+ module ActiveResource
322
+ class Connection
323
+ private
324
+ def authorization_header
325
+ (Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
326
+ end
327
+ end
328
+ 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: cyberfox-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
+