caifara-lighthouse-api 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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.
@@ -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"
@@ -0,0 +1,365 @@
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
+
231
+ def id
232
+ attributes['number'] ||= nil
233
+ number
234
+ end
235
+
236
+ def tags
237
+ attributes['tag'] ||= nil
238
+ @tags ||= tag.blank? ? [] : parse_with_spaces(tag)
239
+ end
240
+
241
+ def body
242
+ attributes['body'] ||= ''
243
+ end
244
+
245
+ def body=(value)
246
+ attributes['body'] = value
247
+ end
248
+
249
+ def body_html
250
+ attributes['body_html'] ||= ''
251
+ end
252
+
253
+ def body_html=(value)
254
+ attributes['body_html'] = value
255
+ end
256
+
257
+ def save_with_tags
258
+ self.tag = @tags.collect do |tag|
259
+ tag.include?(' ') ? tag.inspect : tag
260
+ end.join(" ") if @tags.is_a?(Array)
261
+ @tags = nil ; save_without_tags
262
+ end
263
+
264
+ alias_method_chain :save, :tags
265
+
266
+ private
267
+ # taken from Lighthouse Tag code
268
+ def parse_with_spaces(list)
269
+ tags = []
270
+
271
+ # first, pull out the quoted tags
272
+ list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
273
+
274
+ # then, get whatever's left
275
+ tags.concat list.split(/\s/)
276
+
277
+ cleanup_tags(tags)
278
+ end
279
+
280
+ def cleanup_tags(tags)
281
+ returning tags do |tag|
282
+ tag.collect! do |t|
283
+ unless tag.blank?
284
+ t = Tag.new(t,prefix_options[:project_id])
285
+ t.downcase!
286
+ t.gsub! /(^')|('$)/, ''
287
+ t.gsub! /[^a-z0-9 \-_@\!']/, ''
288
+ t.strip!
289
+ t.prefix_options = prefix_options
290
+ t
291
+ end
292
+ end
293
+ tag.compact!
294
+ tag.uniq!
295
+ end
296
+ end
297
+ end
298
+
299
+ class Message < Base
300
+ site_format << '/projects/:project_id'
301
+ end
302
+
303
+ class Milestone < Base
304
+ site_format << '/projects/:project_id'
305
+
306
+ def tickets(options = {})
307
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{milestone:"#{title}"}))
308
+ end
309
+ end
310
+
311
+ class Bin < Base
312
+ site_format << '/projects/:project_id'
313
+
314
+ def tickets(options = {})
315
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => query))
316
+ end
317
+ end
318
+
319
+ class Changeset < Base
320
+ site_format << '/projects/:project_id'
321
+ end
322
+
323
+ class Change < Array; end
324
+
325
+ class TagResource < Base
326
+ self.element_name = 'tag'
327
+ site_format << '/projects/:project_id'
328
+
329
+ def name
330
+ @name ||= Tag.new(attributes['name'], prefix_options[:project_id])
331
+ end
332
+
333
+ def tickets(options = {})
334
+ name.tickets(options)
335
+ end
336
+ end
337
+
338
+ class Tag < String
339
+ attr_writer :prefix_options
340
+ attr_accessor :project_id
341
+
342
+ def initialize(s, project_id)
343
+ @project_id = project_id
344
+ super(s)
345
+ end
346
+
347
+ def prefix_options
348
+ @prefix_options || {}
349
+ end
350
+
351
+ def tickets(options = {})
352
+ options[:project_id] ||= @project_id
353
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{tagged:"#{self}"}))
354
+ end
355
+ end
356
+ end
357
+
358
+ module ActiveResource
359
+ class Connection
360
+ private
361
+ def authorization_header
362
+ (Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
363
+ end
364
+ end
365
+ 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: caifara-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
+