diff --git a/app/models/app.rb b/app/models/app.rb index b87f7d8..fb0f809 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -17,6 +17,8 @@ class App embeds_many :watchers embeds_many :deploys embeds_one :issue_tracker + embeds_one :notification_service + has_many :problems, :inverse_of => :app, :dependent => :destroy before_validation :generate_api_key, :on => :create diff --git a/app/models/issue_trackers/campfire_tracker.rb b/app/models/issue_trackers/campfire_tracker.rb deleted file mode 100644 index 9dae889..0000000 --- a/app/models/issue_trackers/campfire_tracker.rb +++ /dev/null @@ -1,39 +0,0 @@ -class IssueTrackers::CampfireTracker < IssueTracker - Label = "campfire" - Fields = [ - [:subdomain, { - :placeholder => "Campfire Subdomain" - }], - [:api_token, { - :placeholder => "API Token" - }], - [:project_id, { - :placeholder => "Room ID", - :label => "Room ID" - }], - ] - - def check_params - if Fields.detect {|f| self[f[0]].blank? } - errors.add :base, 'You must specify your Campfire Subdomain, API token and Room ID' - end - end - - def create_issue(problem, reported_by = nil) - # build the campfire client - campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => project_id) - - # post the issue to the campfire room - campy.speak "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{issue_title problem}" - - # update the problem to say where it was sent - problem.update_attributes( - :issue_link => url, - :issue_type => Label - ) - end - - def url - "http://#{subdomain}.campfirenow.com" - end -end \ No newline at end of file diff --git a/app/models/notification_services/campfire_service.rb b/app/models/notification_services/campfire_service.rb new file mode 100644 index 0000000..9623d02 --- /dev/null +++ b/app/models/notification_services/campfire_service.rb @@ -0,0 +1,29 @@ +class NotificationService::CampfireService < IssueTracker + Label = "campfire" + Fields = [ + [:subdomain, { + :placeholder => "Campfire Subdomain" + }], + [:api_token, { + :placeholder => "API Token" + }], + [:room_id, { + :placeholder => "Room ID", + :label => "Room ID" + }], + ] + + def check_params + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, 'You must specify your Campfire Subdomain, API token and Room ID' + end + end + + def create_notification(problem) + # build the campfire client + campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id) + + # post the issue to the campfire room + campy.speak "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}" + end +end \ No newline at end of file -- libgit2 0.21.2