lib/list.rb in createsend-0.1.0 vs lib/list.rb in createsend-0.1.1
- old
+ new
@@ -118,9 +118,54 @@
:ConfirmedOptIn => confirmed_opt_in,
:ConfirmationSuccessPage => confirmation_success_page }.to_json }
response = CreateSend.put "/lists/#{list_id}.json", options
end
+ # Please note: Any webhook-related methods below are not yet supported in production.
+ # The gem version will be bumped when these are released in production.
+
+ # Gets the webhooks for this list.
+ def webhooks
+ response = get "webhooks"
+ response.map{|item| Hashie::Mash.new(item)}
+ end
+
+ # Creates a new webhook for the specified events (an array of strings).
+ # Valid events are "Subscribe", "Unsubscribe", "Bounce", "Spam", and
+ # "SubscriberUpdate". Valid payload formats are "json", and "xml".
+ def create_webhook(events, url, payload_format)
+ options = { :body => {
+ :Events => events,
+ :Url => url,
+ :PayloadFormat => payload_format }.to_json }
+ response = post "webhooks", options
+ response.parsed_response
+ end
+
+ # Tests that a post can be made to the endpoint specified for the webhook
+ # identified by webhook_id.
+ def test_webhook(webhook_id)
+ response = get "webhooks/#{webhook_id}/test"
+ true # An exception will be raised if any error occurs
+ end
+
+ # Deletes a webhook associated with this list.
+ def delete_webhook(webhook_id)
+ response = CreateSend.delete "/lists/#{list_id}/webhooks/#{webhook_id}.json", {}
+ end
+
+ # Activates a webhook associated with this list.
+ def activate_webhook(webhook_id)
+ options = { :body => '' }
+ response = put "webhooks/#{webhook_id}/activate", options
+ end
+
+ # De-activates a webhook associated with this list.
+ def deactivate_webhook(webhook_id)
+ options = { :body => '' }
+ response = put "webhooks/#{webhook_id}/deactivate", options
+ end
+
private
def get(action, options = {})
CreateSend.get uri_for(action), options
end
\ No newline at end of file