ticketmaster-lighthouse 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ticketmaster-lighthouse
2
2
 
3
- This is a provider for [ticketmaster](http://ticketrb.com). It provides interoperability with (Lighthouse)[http://www.lighthouseapp.com/] through the ticketmaster gem.
3
+ This is a provider for [ticketmaster](http://ticketrb.com). It provides interoperability with [Lighthouse](http://www.lighthouseapp.com/) through the ticketmaster gem.
4
4
 
5
5
  # Usage and Examples
6
6
 
@@ -11,11 +11,17 @@ First we have to instantiate a new ticketmaster instance:
11
11
 
12
12
  The :account is the name of the account which should be the same as the subdomain used to access the account's projects. For you convenience, you can also pass in :subdomain in place of :account. If you pass in both, it'll use the :account value. If you do not pass in the token or both the username and password, it will only access public information for the account.
13
13
 
14
- Tokens allow access to a specific project or account without having to give out your login credentials. It can be nullified if necessary. I highly suggest you use tokens. For more information, please see Lighthouse's FAQ (How do I get an API token?)[http://help.lighthouseapp.com/faqs/api/how-do-i-get-an-api-token]
14
+ Tokens allow access to a specific project or account without having to give out your login credentials. It can be nullified if necessary. I highly suggest you use tokens. For more information, please see Lighthouse's FAQ [How do I get an API token?](http://help.lighthouseapp.com/faqs/api/how-do-i-get-an-api-token)
15
15
 
16
16
  == Finding Projects
17
17
 
18
- project = lighthouse.project
18
+ project = lighthouse.project['project_name']
19
+ project = lighthouse.project.find(:id => 505)
20
+
21
+ == Finding Tickets
22
+
23
+ tickets = project.tickets
24
+
19
25
 
20
26
  ## Requirements
21
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -0,0 +1,87 @@
1
+ module TicketMaster::Provider
2
+ # This is the Lighthouse Provider for ticketmaster
3
+ module Lighthouse
4
+ include TicketMaster::Provider::Base
5
+
6
+ # This is for cases when you want to instantiate using TicketMaster::Provider::Lighthouse.new(auth)
7
+ def self.new(auth = {})
8
+ TicketMaster.new(:lighthouse, auth)
9
+ end
10
+
11
+ # The authorize and initializer for this provider
12
+ def authorize(auth = {})
13
+ @authentication ||= TicketMaster::Authenticator.new(auth)
14
+ auth = @authentication
15
+ LighthouseAPI.account = auth.account || auth.subdomain
16
+ if auth.token
17
+ LighthouseAPI.token = auth.token
18
+ elsif auth.username && auth.password
19
+ LighthouseAPI.authenticate(auth.username, auth.password)
20
+ end
21
+ end
22
+
23
+ # The projects
24
+ #
25
+ # We have to merge in the auth information because, due to the class-based authentication
26
+ # mechanism, if we don't reset the authorize information for every request, it would
27
+ # end up using whatever the previous instantiated object's account info is.
28
+ def projects(*options)
29
+ authorize
30
+ projects = if options.length > 0
31
+ Project.find(*options)
32
+ else
33
+ Project.find(:all)
34
+ end
35
+ set_master_data(projects)
36
+ end
37
+
38
+ # The project
39
+ def project(*options)
40
+ authorize
41
+ return set_master_data(Project.find(:first, *options)) if options.length > 0
42
+ Project
43
+ end
44
+
45
+ # The tickets
46
+ #
47
+ # Due to the nature of lighthouse, we must have the project_id to pull tickets. You can
48
+ # pass in the id through this format:
49
+ #
50
+ # .tickets(22)
51
+ # .tickets(:project_id => 22)
52
+ #
53
+ # To conform to ticketmaster's standard of returning all tickets on a call to this method
54
+ # without any parameters, if no parameters are passed, it will return all tickets for whatever
55
+ # the first project is.
56
+ def tickets(*options)
57
+ authorize
58
+ arg = options.shift
59
+ tickets = if arg.nil?
60
+ Ticket.find
61
+ elsif arg.is_a?(Fixnum)
62
+ Ticket.find(:all, :params => {:project_id => arg})
63
+ elsif arg.is_a?(Hash)
64
+ Ticket.find(:all, :params => arg) if arg.is_a?(Hash)
65
+ else
66
+ []
67
+ end
68
+ set_master_data(tickets)
69
+ end
70
+
71
+ # the ticket
72
+ def ticket(*options)
73
+ authorize
74
+ return set_master_data(Ticket.find(*options)) if options.length > 0
75
+ Ticket
76
+ end
77
+
78
+ def set_master_data(data)
79
+ if data.is_a?(Array)
80
+ data.collect! { |p| p.system_data.merge!(:master => self); p }
81
+ else
82
+ data.system_data.merge!(:master => self)
83
+ end
84
+ data
85
+ end
86
+ end
87
+ end
@@ -1,48 +1,93 @@
1
- module TicketMasterMod
1
+ module TicketMaster::Provider
2
2
  module Lighthouse
3
- class Project
4
- def self.find(query, options = {})
5
- self.authenticate(options[:authentication]) if options[:authentication]
6
- projects = LighthouseAPI::Project.find :all # Kernel::Lighthouse::Project.find query
7
- formatted_projects = []
8
-
9
- unless projects.empty?
10
- projects.each do |project|
11
- attributes = {:system => "lighthouse", :authentication => options[:authentication],
12
- :system_data => {:project => project}}
13
- attributes.merge!(project.attributes)
14
- formatted_projects << TicketMasterMod::Project.new(attributes)
3
+ # Project class for ticketmaster-lighthouse
4
+ #
5
+ #
6
+ class Project < TicketMaster::Provider::Base::Project
7
+ # The finder method
8
+ #
9
+ # It accepts all the find functionalities defined by ticketmaster
10
+ #
11
+ # + find() and find(:all) - Returns all projects on the account
12
+ # + find(<project_id>) - Returns the project based on the id
13
+ # + find(:first, :name => <project_name>) - Returns the first project based on the attribute
14
+ # + find(:name => <project name>) - Returns all projects based on the attribute
15
+ attr_accessor :prefix_options
16
+ def self.find(*options)
17
+ first = options.shift
18
+ if first.nil? or first == :all
19
+ LighthouseAPI::Project.find(:all).collect do |p|
20
+ self.new p
15
21
  end
22
+ elsif first.is_a?(Fixnum)
23
+ self.new LighthouseAPI::Project.find(first)
24
+ elsif first == :first
25
+ self.new self.search(options.shift || {}, 1).first
26
+ elsif first.is_a?(Hash)
27
+ self.search(first).collect { |p| self.new p }
16
28
  end
17
-
18
- formatted_projects
19
29
  end
20
30
 
21
- def self.authenticate(auth)
22
- LighthouseAPI.account = auth.account || auth.subdomain
23
- if auth.token
24
- LighthouseAPI.token = auth.token
25
- elsif auth.username && auth.password
26
- LighthouseAPI.authenticate(auth.username, auth.password)
31
+ # This is a helper method to find
32
+ def self.search(options = {}, limit = 1000)
33
+ projects = LighthouseAPI::Project.find(:all)
34
+ projects.find_all do |p|
35
+ options.keys.reduce(true) do |memo, key|
36
+ p.send(key) == options[key] and (limit-=1) >= 0
37
+ end
27
38
  end
28
39
  end
29
-
30
- def self.tickets(project_instance)
31
- self.authenticate(project_instance.authentication)
32
- tickets = project_instance.system_data[:project].tickets
33
- formatted_tickets = []
34
-
35
- unless tickets.empty?
36
- tickets.each do |ticket|
37
- attributes = {:system => 'lighthouse', :project => project_instance,
38
- :system_data => {:project => project_instance.system_data[:project], :ticket => ticket}}
39
- attributes.merge!(ticket.attributes)
40
- formatted_tickets << TicketMasterMod::Ticket.new(attributes)
40
+
41
+ # Create a project
42
+ def self.create(*options)
43
+ project = LighthouseAPI::Project.new(options.shift)
44
+ project.save
45
+ self.new project
46
+ end
47
+
48
+ # The initializer
49
+ #
50
+ # A side effect of Hashie causes prefix_options to become an instance of TicketMaster::Provider::Lighthouse::Project
51
+ def initialize(*options)
52
+ @system = :lighthouse
53
+ @system_data = {}
54
+ first = options.shift
55
+ if first.is_a?(LighthouseAPI::Project)
56
+ @system_data[:client] = first
57
+ @prefix_options = first.prefix_options
58
+ super(first.attributes)
59
+ else
60
+ super(first)
61
+ end
62
+ end
63
+
64
+ # All tickets for this project
65
+ def tickets(*options)
66
+ if options.length == 0
67
+ Ticket.find(:project_id => self.id)
68
+ else
69
+ first = options.first
70
+ if first.is_a?(Fixnum)
71
+ [Ticket.find(first, {:project_id => self.id})]
72
+ else
73
+ Ticket.find({:project_id => self.id}.merge(:q => options.first))
41
74
  end
42
75
  end
43
-
44
- formatted_tickets
45
76
  end
77
+
78
+ # The ticket finder
79
+ # returns only one ticket
80
+ def ticket(*options)
81
+ first = options.shift
82
+ if first.nil?
83
+ return Ticket
84
+ elsif first.is_a?(Fixnum)
85
+ return Ticket.find(first, :project_id => self.id)
86
+ else
87
+ Ticket.find(:first, {:project_id => self.id}.merge(:q => first))
88
+ end
89
+ end
90
+
46
91
  end
47
92
  end
48
93
  end
@@ -1,31 +1,106 @@
1
- module TicketMasterMod
1
+ module TicketMaster::Provider
2
2
  module Lighthouse
3
- class Ticket
3
+ # Ticket class for ticketmaster-lighthouse
4
+ class Ticket < TicketMaster::Provider::Base::Ticket
4
5
  # This is an exhaustive list, but should contain the most common ones, add as necessary
5
6
  @@allowed_attributes = ["number", "permalink", "milestone_id", "created_at", "title", "closed", "updated_at", "raw_data", "priority", "tag", "url", "attachments_count", "creator_id", "milestone_due_on", "original_body_html", "user_id", "user_name", "original_body", "latest_body", "assigned_user_id", "creator_name", "state"]
6
- def self.create(ticket)
7
- ticket_attr = ticket.to_hash.delete_if { |k, v| !@@allowed_attributes.include?(k) }
8
- project = ticket.project.system_data[:project]
9
- new_ticket = LighthouseAPI::Ticket.new(:project_id => ticket.project.id)
7
+ @@allowed_states = ['new', 'open', 'resolved', 'hold', 'invalid']
8
+ attr_accessor :prefix_options
9
+
10
+ # The finder
11
+ #
12
+ # It tries to implement all the ticketmaster calls, but since the project id is required as the
13
+ # parent key, it doesnt really make sense to call find(:all) or find(##)
14
+ #
15
+ # * find(:all) - Returns an array of all tickets
16
+ # * find(##, ##) - Returns a ticket based on that id or some other primary (unique) attribute
17
+ # * find(:first, :summary => 'Ticket title') - Returns a ticket based on the ticket's attributes
18
+ # * find(:summary => 'Test Ticket') - Returns all tickets based on the given attributes
19
+ def self.find(*options)
20
+ first = options.shift
21
+ if first.nil? or first == :all
22
+ tickets = []
23
+ LighthouseAPI::Project.find(:all).each do |p|
24
+ tickets |= p.tickets
25
+ end
26
+ tickets.collect { |t| self.new t }
27
+ elsif first.is_a?(Fixnum)
28
+ second = options.shift
29
+ if second.is_a?(Fixnum)
30
+ self.new LighthouseAPI::Ticket.find(first, :params => { :project_id => second })
31
+ elsif second.is_a?(Hash)
32
+ self.new LighthouseAPI::Ticket.find(first, :params => qize(second))
33
+ end
34
+ elsif first == :first
35
+ self.new self.search(options.shift, 1).first
36
+ elsif first.is_a?(Hash)
37
+ self.search(first).collect do |t| self.new t end
38
+ end
39
+ end
40
+
41
+
42
+ def self.qize(params)
43
+ return params unless params[:q] and params[:q].is_a?(Hash)
44
+ q = ''
45
+ params[:q].keys.each do |key|
46
+ value = params[:q][key]
47
+ value = "\"#{value}\"" if value.to_s.include?(' ')
48
+ q += "#{key}:#{value} "
49
+ end
50
+ params[:q] = q
51
+ params
52
+ end
53
+
54
+ # The find helper
55
+ def self.search(options, limit = 1000)
56
+ tickets = LighthouseAPI::Ticket.find(:all, :params => qize(options))
57
+ options.delete(:project_id) || options.delete('project_id')
58
+ tickets.find_all do |t|
59
+ options.keys.reduce(true) do |memo, key|
60
+ p.send(key) == options[key] and (limit-=1) > 0
61
+ end
62
+ end
63
+ end
64
+
65
+ # The initializer
66
+ def initialize(*options)
67
+ @system = :lighthouse
68
+ @system_data = {}
69
+ first = options.shift
70
+ if first.is_a?(LighthouseAPI::Ticket)
71
+ @system_data[:client] = first
72
+ @prefix_options = first.prefix_options
73
+ super(first.attributes)
74
+ else
75
+ super(first)
76
+ end
77
+ end
78
+
79
+ # The creator
80
+ def self.create(*options)
81
+ ticket_attr = options.delete_if { |k, v| !@@allowed_attributes.include?(k) }
82
+ new_ticket = LighthouseAPI::Ticket.new(ticket_attr)
83
+ ticket_attr.delete(:project_id) || ticket_attr.delete('project_id')
10
84
  ticket_attr.each do |k, v|
11
85
  new_ticket.send(k + '=', v)
12
86
  end
13
87
  new_ticket.save
14
88
  end
15
-
16
- def self.save(ticket)
17
- ticket_attr = ticket.to_hash.delete_if { |k, v| !@@allowed_attributes.include?(k) || ticket.system_data[:ticket].send(k) == v }
18
- project = ticket.project.system_data[:project]
19
- lh_ticket = ticket.system_data[:ticket]
89
+
90
+ # The saver
91
+ def save
92
+ ticket_attr = self.to_hash.delete_if { |k, v| !@@allowed_attributes.include?(k) || ticket.system_data[:client].send(k) == v }
93
+ lh_ticket = ticket.system_data[:client]
20
94
  ticket_attr.each do |k, v|
21
95
  lh_ticket.send(k + '=', v)
22
96
  end
23
97
  lh_ticket.save
24
98
  end
25
-
26
- def self.close(ticket, resolution)
27
- project = ticket.project.system_data[:project]
28
- ticket = LighthouseAPI::Ticket.find(ticket.id, :params => {:project_id => ticket.project.id})
99
+
100
+ # The closer
101
+ def close(resolution = 'resolved')
102
+ resolution = 'resolved' unless @@allowed_states.include?(resolution)
103
+ ticket = LighthouseAPI::Ticket.find(self.id, :params => {:project_id => self.prefix_options[:project_id]})
29
104
  ticket.state = resolution
30
105
  ticket.save
31
106
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/lighthouse/lighthouse-api'
2
2
 
3
- %w{ ticket project }.each do |f|
3
+ %w{ lighthouse ticket project }.each do |f|
4
4
  require File.dirname(__FILE__) + '/provider/' + f + '.rb';
5
5
  end
6
6
 
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require '../ticketmaster/lib/ticketmaster'
3
4
  require 'ticketmaster-lighthouse'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
@@ -1,7 +1,62 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "TicketmasterLighthouse" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
3
+ describe "Ticketmaster" do
4
+ before(:each) do
5
+ @ticketmaster = TicketMaster.new(:lighthouse, :token => '00c00123b00f00dc0de', :account => 'ticketmaster')
6
+ @project_class = TicketMaster::Provider::Lighthouse::Project
7
+ @ticket_class = TicketMaster::Provider::Lighthouse::Ticket
8
+ @lh_project = LighthouseAPI::Project.new
9
+ @lh_project.attributes = {"permalink"=>"lh-test", "name"=>"lh-test", "created_at"=>Time.now, "description_html"=>"<div><p>This is a test project created in order to test the\nticketmaster-lighthouse gem.</p></div>", "closed_states_list"=>"resolved,hold,invalid", "public"=>true, "default_ticket_text"=>nil, "license"=>nil, "default_milestone_id"=>nil, "closed_states"=>"resolved/6A0 # You can customize colors\nhold/EB0 # with 3 or 6 character hex codes\ninvalid/A30 # 'A30' expands to 'AA3300'", "updated_at"=>Time.now, "archived"=>false, "send_changesets_to_events"=>true, "open_states_list"=>"new,open", "open_tickets_count"=>2, "id"=>54448, "default_assigned_user_id"=>nil, "description"=>"This is a test project created in order to test the ticketmaster-lighthouse gem.", "open_states"=>"new/f17 # You can add comments here\nopen/aaa # if you want to.", "hidden"=>false}
10
+ @lh_project.prefix_options = {}
11
+
12
+ end
13
+
14
+ # Essentially just a sanity check on the include since .new always returns the object's instance
15
+ it "should be able to instantiate a new instance" do
16
+ @ticketmaster.should be_an_instance_of TicketMaster
17
+ @ticketmaster.should be_a_kind_of TicketMaster::Provider::Lighthouse
18
+ end
19
+
20
+ it "should be able to load projects" do
21
+ LighthouseAPI::Project.should_receive(:find).with(:all).at_least(:once).and_return([@lh_project])
22
+ @ticketmaster.projects.should be_an_instance_of Array
23
+ @ticketmaster.projects.first.should be_an_instance_of @project_class
24
+ @ticketmaster.projects.first.description.should == @lh_project.attributes['description']
25
+ @ticketmaster.projects(:id => 54448).should be_an_instance_of Array
26
+ @ticketmaster.projects(:id => 54448).first.should be_an_instance_of @project_class
27
+ @ticketmaster.projects(:id => 54448).first.id.should == 54448
28
+
29
+ @ticketmaster.project.should == @project_class
30
+ @ticketmaster.project(:name => "lh-test").should be_an_instance_of @project_class
31
+ @ticketmaster.project(:name => "lh-test").name.should == "lh-test"
32
+ @ticketmaster.project.find(:first, :description => @lh_project.attributes['description']).should be_an_instance_of @project_class
33
+ @ticketmaster.project.find(:first, :description => @lh_project.attributes['description']).description.should == @lh_project.attributes['description']
34
+ end
35
+
36
+ it "should be able to do project stuff" do
37
+ info = {:name => 'Test create'}
38
+ LighthouseAPI::Project.should_receive(:new).at_least(:once).and_return(@lh_project)
39
+ @lh_project.should_receive(:save).at_least(:once).and_return(true)
40
+ @ticketmaster.project.create(info).should be_an_instance_of @project_class
41
+ @ticketmaster.project.new(info).should be_an_instance_of @project_class
42
+ @ticketmaster.project.create(info).id.should == 54448
43
+ end
44
+
45
+ it "should be able to load tickets" do
46
+ LighthouseAPI::Project.should_receive(:find).with(:all).at_least(:once).and_return([@lh_project])
47
+ LighthouseAPI::Ticket.should_receive(:find).with(:all, :params => {:project_id => 54448}).at_least(:once).and_return([LighthouseAPI::Ticket.new])
48
+ LighthouseAPI::Ticket.should_receive(:find).with(999, :params => {:project_id => 54448}).at_least(:once).and_return(LighthouseAPI::Ticket.new(:id => 999))
49
+ LighthouseAPI::Ticket.should_receive(:find).with(:all, :params => {:project_id => 54448, :id => 888}).at_least(:once).and_return([LighthouseAPI::Ticket.new(:id => 888)])
50
+ project = @ticketmaster.projects.first
51
+ project.tickets.should be_an_instance_of Array
52
+ project.tickets.first.should be_an_instance_of @ticket_class
53
+ project.tickets(999).should be_an_instance_of Array
54
+ project.tickets(999).first.should be_an_instance_of @ticket_class
55
+ project.tickets(999).first.id.should == 999
56
+
57
+ project.ticket.should == TicketMaster::Provider::Lighthouse::Ticket
58
+ project.ticket(999).should be_an_instance_of @ticket_class
59
+ project.ticket(999).id.should == 999
60
+ project.ticket.find(:first, :project_id => 54448, :id => 888).should be_an_instance_of @ticket_class
6
61
  end
7
62
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ticketmaster-lighthouse}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Hong"]
12
- s.date = %q{2010-06-14}
12
+ s.date = %q{2010-06-22}
13
13
  s.description = %q{Allows ticketmaster to interact with Lighthouse's issue tracking system.}
14
14
  s.email = %q{hong.quach@abigfisch.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/lighthouse/LICENSE",
27
27
  "lib/lighthouse/README.markdown",
28
28
  "lib/lighthouse/lighthouse-api.rb",
29
- "lib/provider/authenticator.rb",
29
+ "lib/provider/lighthouse.rb",
30
30
  "lib/provider/project.rb",
31
31
  "lib/provider/ticket.rb",
32
32
  "lib/ticketmaster-lighthouse.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketmaster-lighthouse
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hong
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-14 00:00:00 -07:00
18
+ date: 2010-06-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -101,7 +101,7 @@ files:
101
101
  - lib/lighthouse/LICENSE
102
102
  - lib/lighthouse/README.markdown
103
103
  - lib/lighthouse/lighthouse-api.rb
104
- - lib/provider/authenticator.rb
104
+ - lib/provider/lighthouse.rb
105
105
  - lib/provider/project.rb
106
106
  - lib/provider/ticket.rb
107
107
  - lib/ticketmaster-lighthouse.rb
@@ -1,4 +0,0 @@
1
- module TicketMasterMod
2
- class Authenticator < Hashie::Mash
3
- end
4
- end