createsend 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ createsend (0.1.0)
5
+ hashie (~> 0.4.0)
6
+ httparty (~> 0.6.1)
7
+ json
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ crack (0.1.8)
13
+ fakeweb (1.3.0)
14
+ hashie (0.4.0)
15
+ httparty (0.6.1)
16
+ crack (= 0.1.8)
17
+ jnunemaker-matchy (0.4.0)
18
+ json (1.4.6)
19
+ mocha (0.9.10)
20
+ rake
21
+ rake (0.8.7)
22
+ shoulda (2.11.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ createsend!
29
+ fakeweb (~> 1.3)
30
+ hashie (~> 0.4.0)
31
+ httparty (~> 0.6.1)
32
+ jnunemaker-matchy (~> 0.4.0)
33
+ json
34
+ mocha (~> 0.9)
35
+ shoulda (~> 2.11)
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.add_development_dependency('jnunemaker-matchy', '~> 0.4.0')
9
9
  s.add_development_dependency('mocha', '~> 0.9')
10
10
  s.add_development_dependency('shoulda', '~> 2.11')
11
+ s.add_runtime_dependency('json')
11
12
  s.add_runtime_dependency('hashie', '~> 0.4.0')
12
13
  s.add_runtime_dependency('httparty', '~> 0.6.1')
13
14
  s.name = "createsend"
@@ -43,7 +43,7 @@ class Unavailable < StandardError; end
43
43
  class CreateSend
44
44
  include HTTParty
45
45
 
46
- VER = "0.1.0" unless defined?(CreateSend::VER)
46
+ VER = "0.1.1" unless defined?(CreateSend::VER)
47
47
  headers({ 'User-Agent' => "createsend-ruby-#{CreateSend::VER}", 'Content-Type' => 'application/json' })
48
48
  base_uri CreateSendOptions['base_uri']
49
49
  basic_auth CreateSendOptions['api_key'], 'x'
@@ -120,6 +120,51 @@ class List
120
120
  response = CreateSend.put "/lists/#{list_id}.json", options
121
121
  end
122
122
 
123
+ # Please note: Any webhook-related methods below are not yet supported in production.
124
+ # The gem version will be bumped when these are released in production.
125
+
126
+ # Gets the webhooks for this list.
127
+ def webhooks
128
+ response = get "webhooks"
129
+ response.map{|item| Hashie::Mash.new(item)}
130
+ end
131
+
132
+ # Creates a new webhook for the specified events (an array of strings).
133
+ # Valid events are "Subscribe", "Unsubscribe", "Bounce", "Spam", and
134
+ # "SubscriberUpdate". Valid payload formats are "json", and "xml".
135
+ def create_webhook(events, url, payload_format)
136
+ options = { :body => {
137
+ :Events => events,
138
+ :Url => url,
139
+ :PayloadFormat => payload_format }.to_json }
140
+ response = post "webhooks", options
141
+ response.parsed_response
142
+ end
143
+
144
+ # Tests that a post can be made to the endpoint specified for the webhook
145
+ # identified by webhook_id.
146
+ def test_webhook(webhook_id)
147
+ response = get "webhooks/#{webhook_id}/test"
148
+ true # An exception will be raised if any error occurs
149
+ end
150
+
151
+ # Deletes a webhook associated with this list.
152
+ def delete_webhook(webhook_id)
153
+ response = CreateSend.delete "/lists/#{list_id}/webhooks/#{webhook_id}.json", {}
154
+ end
155
+
156
+ # Activates a webhook associated with this list.
157
+ def activate_webhook(webhook_id)
158
+ options = { :body => '' }
159
+ response = put "webhooks/#{webhook_id}/activate", options
160
+ end
161
+
162
+ # De-activates a webhook associated with this list.
163
+ def deactivate_webhook(webhook_id)
164
+ options = { :body => '' }
165
+ response = put "webhooks/#{webhook_id}/deactivate", options
166
+ end
167
+
123
168
  private
124
169
 
125
170
  def get(action, options = {})
@@ -0,0 +1 @@
1
+ "6a783d359bd44ef62c6ca0d3eda4412a"
@@ -0,0 +1,21 @@
1
+ [
2
+ {
3
+ "WebhookID": "943678317049bc13",
4
+ "Events": [
5
+ "Bounce",
6
+ "Spam"
7
+ ],
8
+ "Url": "http://www.postbin.org/d9w8ud9wud9w",
9
+ "Status": "Active",
10
+ "PayloadFormat": "Json"
11
+ },
12
+ {
13
+ "WebhookID": "ee1b3864e5ca6161",
14
+ "Events": [
15
+ "Subscribe"
16
+ ],
17
+ "Url": "http://www.postbin.org/hiuhiu2h2u",
18
+ "Status": "Active",
19
+ "PayloadFormat": "Xml"
20
+ }
21
+ ]
@@ -143,5 +143,47 @@ class ListTest < Test::Unit::TestCase
143
143
  res.Results.first.CustomFields.size.should == 0
144
144
  end
145
145
 
146
+ should "get the webhooks for a list" do
147
+ stub_get(@api_key, "lists/#{@list.list_id}/webhooks.json", "list_webhooks.json")
148
+ hooks = @list.webhooks
149
+ hooks.size.should == 2
150
+ hooks.first.WebhookID.should == "943678317049bc13"
151
+ hooks.first.Events.size.should == 2
152
+ hooks.first.Events.first.should == "Bounce"
153
+ hooks.first.Url.should == "http://www.postbin.org/d9w8ud9wud9w"
154
+ hooks.first.Status.should == "Active"
155
+ hooks.first.PayloadFormat.should == "Json"
156
+ end
157
+
158
+ should "create a webhook for a list" do
159
+ stub_post(@api_key, "lists/#{@list.list_id}/webhooks.json", "create_list_webhook.json")
160
+ webhook_id = @list.create_webhook ["Unsubscribe", "Spam"], "http://example.com/unsub", "json"
161
+ webhook_id.should == "6a783d359bd44ef62c6ca0d3eda4412a"
162
+ end
163
+
164
+ should "test a webhook for a list" do
165
+ webhook_id = "jiuweoiwueoiwueowiueo"
166
+ stub_get(@api_key, "lists/#{@list.list_id}/webhooks/#{webhook_id}/test.json", nil)
167
+ @list.test_webhook webhook_id
168
+ end
169
+
170
+ should "delete a webhook for a list" do
171
+ webhook_id = "jiuweoiwueoiwueowiueo"
172
+ stub_delete(@api_key, "lists/#{@list.list_id}/webhooks/#{webhook_id}.json", nil)
173
+ @list.delete_webhook webhook_id
174
+ end
175
+
176
+ should "activate a webhook for a list" do
177
+ webhook_id = "jiuweoiwueoiwueowiueo"
178
+ stub_put(@api_key, "lists/#{@list.list_id}/webhooks/#{webhook_id}/activate.json", nil)
179
+ @list.activate_webhook webhook_id
180
+ end
181
+
182
+ should "de-activate a webhook for a list" do
183
+ webhook_id = "jiuweoiwueoiwueowiueo"
184
+ stub_put(@api_key, "lists/#{@list.list_id}/webhooks/#{webhook_id}/deactivate.json", nil)
185
+ @list.deactivate_webhook webhook_id
186
+ end
187
+
146
188
  end
147
189
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: createsend
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Dennes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-25 00:00:00 +11:00
18
+ date: 2010-12-15 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,20 @@ dependencies:
81
81
  version_requirements: *id004
82
82
  - !ruby/object:Gem::Dependency
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ type: :runtime
93
+ prerelease: false
94
+ name: json
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ requirement: &id006 !ruby/object:Gem::Requirement
84
98
  none: false
85
99
  requirements:
86
100
  - - ~>
@@ -94,9 +108,9 @@ dependencies:
94
108
  type: :runtime
95
109
  prerelease: false
96
110
  name: hashie
97
- version_requirements: *id005
111
+ version_requirements: *id006
98
112
  - !ruby/object:Gem::Dependency
99
- requirement: &id006 !ruby/object:Gem::Requirement
113
+ requirement: &id007 !ruby/object:Gem::Requirement
100
114
  none: false
101
115
  requirements:
102
116
  - - ~>
@@ -110,7 +124,7 @@ dependencies:
110
124
  type: :runtime
111
125
  prerelease: false
112
126
  name: httparty
113
- version_requirements: *id006
127
+ version_requirements: *id007
114
128
  description: A library which implements the complete functionality of v3 of the createsend API.
115
129
  email:
116
130
  - jdennes@gmail.com
@@ -123,6 +137,7 @@ extra_rdoc_files: []
123
137
  files:
124
138
  - .gitignore
125
139
  - Gemfile
140
+ - Gemfile.lock
126
141
  - LICENSE
127
142
  - README.md
128
143
  - Rakefile
@@ -157,6 +172,7 @@ files:
157
172
  - test/fixtures/create_client.json
158
173
  - test/fixtures/create_custom_field.json
159
174
  - test/fixtures/create_list.json
175
+ - test/fixtures/create_list_webhook.json
160
176
  - test/fixtures/create_segment.json
161
177
  - test/fixtures/create_template.json
162
178
  - test/fixtures/custom_api_error.json
@@ -166,6 +182,7 @@ files:
166
182
  - test/fixtures/import_subscribers_partial_success.json
167
183
  - test/fixtures/list_details.json
168
184
  - test/fixtures/list_stats.json
185
+ - test/fixtures/list_webhooks.json
169
186
  - test/fixtures/lists.json
170
187
  - test/fixtures/segment_details.json
171
188
  - test/fixtures/segment_subscribers.json
@@ -242,6 +259,7 @@ test_files:
242
259
  - test/fixtures/create_client.json
243
260
  - test/fixtures/create_custom_field.json
244
261
  - test/fixtures/create_list.json
262
+ - test/fixtures/create_list_webhook.json
245
263
  - test/fixtures/create_segment.json
246
264
  - test/fixtures/create_template.json
247
265
  - test/fixtures/custom_api_error.json
@@ -251,6 +269,7 @@ test_files:
251
269
  - test/fixtures/import_subscribers_partial_success.json
252
270
  - test/fixtures/list_details.json
253
271
  - test/fixtures/list_stats.json
272
+ - test/fixtures/list_webhooks.json
254
273
  - test/fixtures/lists.json
255
274
  - test/fixtures/segment_details.json
256
275
  - test/fixtures/segment_subscribers.json