lib/flapjack/gateways/api/contact_methods.rb in flapjack-0.7.28 vs lib/flapjack/gateways/api/contact_methods.rb in flapjack-0.7.29
- old
+ new
@@ -95,12 +95,15 @@
# Returns all the contacts
# https://github.com/flpjck/flapjack/wiki/API#wiki-get_contacts
app.get '/contacts' do
content_type :json
-
- Flapjack::Data::Contact.all(:redis => redis).to_json
+ "[" +
+ Flapjack::Data::Contact.all(:redis => redis).map do |contact|
+ contact.to_json
+ end.join(',') +
+ "]"
end
# Returns the core information about the specified contact
# https://github.com/flpjck/flapjack/wiki/API#wiki-get_contacts_id
app.get '/contacts/:contact_id' do
@@ -231,22 +234,39 @@
app.put('/contacts/:contact_id/media/:id') do
content_type :json
contact = find_contact(params[:contact_id])
errors = []
- if params[:address].nil?
- errors << "no address for '#{params[:id]}' media"
- end
- halt err(403, *errors) unless errors.empty?
+ if 'pagerduty'.eql?(params[:id])
+ errors = [:service_key, :subdomain, :username, :password].inject([]) do |memo, pdp|
+ memo << "no #{pdp.to_s} for 'pagerduty' media" if params[pdp].nil?
+ memo
+ end
- contact.set_address_for_media(params[:id], params[:address])
- contact.set_interval_for_media(params[:id], params[:interval])
- contact.set_rollup_threshold_for_media(params[:id], params[:rollup_threshold])
+ halt err(403, *errors) unless errors.empty?
- {'address' => contact.media[params[:id]],
- 'interval' => contact.media_intervals[params[:id]],
- 'rollup_threshold' => contact.media_rollup_thresholds[params[:id]]}.to_json
+ contact.set_pagerduty_credentials('service_key' => params[:service_key],
+ 'subdomain' => params[:subdomain],
+ 'username' => params[:username],
+ 'password' => params[:password])
+
+ contact.pagerduty_credentials.to_json
+ else
+ if params[:address].nil?
+ errors << "no address for '#{params[:id]}' media"
+ end
+
+ halt err(403, *errors) unless errors.empty?
+
+ contact.set_address_for_media(params[:id], params[:address])
+ contact.set_interval_for_media(params[:id], params[:interval])
+ contact.set_rollup_threshold_for_media(params[:id], params[:rollup_threshold])
+
+ {'address' => contact.media[params[:id]],
+ 'interval' => contact.media_intervals[params[:id]],
+ 'rollup_threshold' => contact.media_rollup_thresholds[params[:id]]}.to_json
+ end
end
# delete a media of a contact
app.delete('/contacts/:contact_id/media/:id') do
contact = find_contact(params[:contact_id])