rack_monkey_party 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/support/credentials.rb
19
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@rack_monkey_party --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ env: MCAPI_KEY=1234 MCAPI_LIST_NAME=testing
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack_monkey_party.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ gem 'growl'
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dan Pickett
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # RackMonkeyParty
2
+
3
+ [![Build Status](https://secure.travis-ci.org/EnlightSolutions/rack_monkey_party.png)](http://travis-ci.org/EnlightSolutions/rack_monkey_party)
4
+
5
+ A rack endpoint for adding people to a mailchimp list
6
+
7
+ ## Installation and configuration
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rack_monkey_party'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack_monkey_party
20
+
21
+ Configure mailchimp parameters
22
+
23
+ ```ruby
24
+ MonkeyParty.api_key = 'an_api_key'
25
+ MonkeyParty.data_center = 'us1'
26
+ MonkeyParty.default_list = 'Your List Name'
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Perform a post to the app with a JSON-based, subscriber payload
32
+
33
+ ```ruby
34
+ post "/", { "subscriber" => {"email" => "user@example.com" }}
35
+ ```
36
+
37
+ If the request successfully processes,
38
+ you should receive a 201 (created) response.
39
+ This means that the email address was successfully added to the desired list
40
+
41
+ If something went wrong you should receive a 421 (unprocessable entity).
42
+ You will also receive the error message received from MailChimp.
43
+
44
+ ```javascript
45
+ {
46
+ email: "bademail",
47
+ error: {
48
+ message: "Invalid Email Address: bademail",
49
+ code: "502"
50
+ }
51
+ }
52
+ ```
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
62
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ end
10
+
11
+ task default: :spec
12
+ rescue LoadError
13
+ puts "RSpec is not installed"
14
+ end
15
+
@@ -0,0 +1,8 @@
1
+ require "monkey_party/rack/version"
2
+ require "monkey_party/rack/app"
3
+
4
+ module MonkeyParty
5
+ module Rack
6
+ end
7
+ end
8
+
@@ -0,0 +1,72 @@
1
+ require 'rack/request'
2
+ require 'rack/response'
3
+ require 'json'
4
+
5
+ module MonkeyParty
6
+ module Rack
7
+ class App
8
+ def call(env)
9
+ @env = env
10
+ body, content_type = nil, nil
11
+ if request.params["subscriber"]
12
+ @results = MonkeyParty.list.create_subscribers([subscriber])
13
+ if results[0].valid?
14
+ @status = 201
15
+ else
16
+ @status = 421
17
+ end
18
+ else
19
+ @status = 412
20
+ end
21
+
22
+ if request.path =~ /.json$/
23
+ body = results[0].to_h.to_json
24
+ content_type = "application/json"
25
+ else
26
+ body = html_body
27
+ content_type = "text/html"
28
+ end
29
+
30
+ ::Rack::Response.new(body || [], status, {
31
+ "Content-Type" => content_type
32
+ }).finish
33
+ end
34
+
35
+ protected
36
+ def status
37
+ @status
38
+ end
39
+
40
+ def results
41
+ @results
42
+ end
43
+
44
+ def html_body
45
+ body = nil
46
+ if status == 201
47
+ body = "<p>Thank you! You'll hear from us soon!</p>"
48
+ else
49
+ body = "<p>Something Went Wrong!</p>"
50
+ if results && results[0] && results[0].error
51
+ body += "<p>#{results[0].error.message}</p>"
52
+
53
+ end
54
+ end
55
+
56
+ if request.referrer && request.referrer != ''
57
+ body += "<p><a href=\"#{request.referrer}\">Go Back</a></p>"
58
+ end
59
+ end
60
+
61
+ def subscriber
62
+ @subscriber = MonkeyParty::Subscriber.new(
63
+ request.params["subscriber"].delete("email"),
64
+ request.params["subscriber"])
65
+ end
66
+
67
+ def request
68
+ @request = ::Rack::Request.new(@env)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,6 @@
1
+ module MonkeyParty
2
+ module Rack
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
6
+
@@ -0,0 +1,39 @@
1
+ require "monkey_party"
2
+ require "rack"
3
+ require "monkey_party/rack"
4
+
5
+ module MonkeyParty
6
+ class Exception < Exception; end;
7
+ class ListNotFound < Exception; end;
8
+ class ListNotSet < Exception; end;
9
+
10
+ def self.list_name=(list_name)
11
+ @list_name = list_name
12
+ end
13
+
14
+ def self.list_name
15
+ @list_name || ENV["MCAPI_LIST_NAME"]
16
+ end
17
+
18
+ def self.list
19
+ raise MonkeyParty::ListNotSet if list_name.nil?
20
+ if list_map[list_name.downcase]
21
+ list_map[list_name.downcase]
22
+ else
23
+ raise MonkeyParty::ListNotFound
24
+ end
25
+ end
26
+
27
+ def self.list_map
28
+ @list_map ||= account_lists.inject({}) do |map, list|
29
+ map[list.name.downcase] = list
30
+ map
31
+ end
32
+ end
33
+
34
+ protected
35
+ def self.account_lists
36
+ MonkeyParty::List.all
37
+ end
38
+ end
39
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/monkey_party/rack/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Pickett"]
6
+ gem.email = ["dpickett@enlightsolutions.com"]
7
+ gem.description = %q{A rack endpoint for adding subscribers to an email list}
8
+ gem.summary = %q{A rack endpoint for adding subscribers to an email list: uses the monkey_party web wrapper }
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rack_monkey_party"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MonkeyParty::Rack::VERSION
17
+
18
+ gem.add_dependency "rack"
19
+ gem.add_dependency "monkey_party"
20
+ gem.add_dependency "json"
21
+
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec"
24
+ gem.add_development_dependency "rack-test"
25
+ gem.add_development_dependency "fakeweb"
26
+ gem.add_development_dependency "vcr"
27
+ gem.add_development_dependency "guard-rspec"
28
+ gem.add_development_dependency 'mocha'
29
+ end
30
+
@@ -0,0 +1,76 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&method=lists
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 20:45:16 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '938'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <struct key="0" type="array">
38
+
39
+ <id type="string">6ed27effda</id>
40
+
41
+ <web_id type="integer">47457</web_id>
42
+
43
+ <name type="string">Testing</name>
44
+
45
+ <date_created type="string">2012-03-11 03:00:40</date_created>
46
+
47
+ <member_count type="double">1</member_count>
48
+
49
+ <unsubscribe_count type="double">0</unsubscribe_count>
50
+
51
+ <cleaned_count type="double">0</cleaned_count>
52
+
53
+ <email_type_option type="boolean" />
54
+
55
+ <default_from_name type="string">Launchware</default_from_name>
56
+
57
+ <default_from_email type="string">dan.pickett+test@launchware.com</default_from_email>
58
+
59
+ <default_subject type="string">test</default_subject>
60
+
61
+ <default_language type="string">en</default_language>
62
+
63
+ <list_rating type="double">0</list_rating>
64
+
65
+ <member_count_since_send type="double">2</member_count_since_send>
66
+
67
+ <unsubscribe_count_since_send type="double">1</unsubscribe_count_since_send>
68
+
69
+ <cleaned_count_since_send type="double">0</cleaned_count_since_send>
70
+
71
+ </struct>
72
+
73
+ </MCAPI>'
74
+ http_version: '1.1'
75
+ recorded_at: Sun, 11 Mar 2012 20:45:16 GMT
76
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,119 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&method=lists
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 20:27:18 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '938'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <struct key="0" type="array">
38
+
39
+ <id type="string">6ed27effda</id>
40
+
41
+ <web_id type="integer">47457</web_id>
42
+
43
+ <name type="string">Testing</name>
44
+
45
+ <date_created type="string">2012-03-11 03:00:40</date_created>
46
+
47
+ <member_count type="double">1</member_count>
48
+
49
+ <unsubscribe_count type="double">0</unsubscribe_count>
50
+
51
+ <cleaned_count type="double">0</cleaned_count>
52
+
53
+ <email_type_option type="boolean" />
54
+
55
+ <default_from_name type="string">Launchware</default_from_name>
56
+
57
+ <default_from_email type="string">dan.pickett+test@launchware.com</default_from_email>
58
+
59
+ <default_subject type="string">test</default_subject>
60
+
61
+ <default_language type="string">en</default_language>
62
+
63
+ <list_rating type="double">0</list_rating>
64
+
65
+ <member_count_since_send type="double">2</member_count_since_send>
66
+
67
+ <unsubscribe_count_since_send type="double">1</unsubscribe_count_since_send>
68
+
69
+ <cleaned_count_since_send type="double">0</cleaned_count_since_send>
70
+
71
+ </struct>
72
+
73
+ </MCAPI>'
74
+ http_version: '1.1'
75
+ recorded_at: Sun, 11 Mar 2012 20:27:18 GMT
76
+ - request:
77
+ method: get
78
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40anexample.com
79
+ body:
80
+ encoding: US-ASCII
81
+ string: ''
82
+ headers:
83
+ connection:
84
+ - close
85
+ response:
86
+ status:
87
+ code: 200
88
+ message: OK
89
+ headers:
90
+ server:
91
+ - nginx/0.7.65
92
+ date:
93
+ - Sun, 11 Mar 2012 20:27:19 GMT
94
+ content-type:
95
+ - application/xml
96
+ connection:
97
+ - close
98
+ vary:
99
+ - Accept-Encoding
100
+ x-powered-by:
101
+ - PHP/5.3.2
102
+ set-cookie:
103
+ - _AVESTA_ENVIRONMENT=prod; path=/
104
+ content-length:
105
+ - '145'
106
+ body:
107
+ encoding: US-ASCII
108
+ string: ! '<MCAPI type="array">
109
+
110
+ <success_count type="integer">1</success_count>
111
+
112
+ <error_count type="integer">0</error_count>
113
+
114
+ <errors type="array" />
115
+
116
+ </MCAPI>'
117
+ http_version: '1.1'
118
+ recorded_at: Sun, 11 Mar 2012 20:27:19 GMT
119
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40anexample.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 20:27:21 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '145'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <success_count type="integer">1</success_count>
38
+
39
+ <error_count type="integer">0</error_count>
40
+
41
+ <errors type="array" />
42
+
43
+ </MCAPI>'
44
+ http_version: '1.1'
45
+ recorded_at: Sun, 11 Mar 2012 20:27:21 GMT
46
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40anexample.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 18 Mar 2012 19:47:08 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '145'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <success_count type="integer">1</success_count>
38
+
39
+ <error_count type="integer">0</error_count>
40
+
41
+ <errors type="array" />
42
+
43
+ </MCAPI>'
44
+ http_version: '1.1'
45
+ recorded_at: Sun, 18 Mar 2012 19:47:08 GMT
46
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40anexample.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 18 Mar 2012 19:22:03 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.3
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '145'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <success_count type="integer">1</success_count>
38
+
39
+ <error_count type="integer">0</error_count>
40
+
41
+ <errors type="array" />
42
+
43
+ </MCAPI>'
44
+ http_version: '1.1'
45
+ recorded_at: Sun, 18 Mar 2012 19:22:03 GMT
46
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=bademail
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 20:27:21 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '354'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <success_count type="integer">0</success_count>
38
+
39
+ <error_count type="integer">1</error_count>
40
+
41
+ <errors type="array">
42
+
43
+ <struct key="0" type="array">
44
+
45
+ <code type="integer">502</code>
46
+
47
+ <message type="string">Invalid Email Address: bademail</message>
48
+
49
+ <row type="array">
50
+
51
+ <EMAIL type="string">bademail</EMAIL>
52
+
53
+ </row>
54
+
55
+ </struct>
56
+
57
+ </errors>
58
+
59
+ </MCAPI>'
60
+ http_version: '1.1'
61
+ recorded_at: Sun, 11 Mar 2012 20:27:21 GMT
62
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=bademail
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 20:27:22 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '354'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <success_count type="integer">0</success_count>
38
+
39
+ <error_count type="integer">1</error_count>
40
+
41
+ <errors type="array">
42
+
43
+ <struct key="0" type="array">
44
+
45
+ <code type="integer">502</code>
46
+
47
+ <message type="string">Invalid Email Address: bademail</message>
48
+
49
+ <row type="array">
50
+
51
+ <EMAIL type="string">bademail</EMAIL>
52
+
53
+ </row>
54
+
55
+ </struct>
56
+
57
+ </errors>
58
+
59
+ </MCAPI>'
60
+ http_version: '1.1'
61
+ recorded_at: Sun, 11 Mar 2012 20:27:22 GMT
62
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ #this is really an integration test because it actually hits the mailchimp api
4
+ describe MonkeyParty::Rack::App, :vcr do
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ MonkeyParty::Rack::App.new
9
+ end
10
+
11
+ let(:email) { "auser@anexample.com" }
12
+
13
+ describe "when a subscriber isn't specified" do
14
+ it "returns a precondition not met" do
15
+ post "/"
16
+ last_response.status.should eql(412)
17
+ end
18
+ end
19
+
20
+ describe "when a proper subscriber is posted" do
21
+ it "returns a succcessful response" do
22
+ do_post
23
+ last_response.status.should eql(201)
24
+ end
25
+
26
+ it "returns the email in the body" do
27
+ do_post
28
+ last_response.body.should =~ /#{Regexp.escape(email)}/
29
+ end
30
+ end
31
+
32
+ describe "when an invalid subscriber is posted" do
33
+ let(:email) { "bademail" }
34
+
35
+ it "returns a 412 unprecessable entity" do
36
+ do_post
37
+ last_response.status.should eql(421)
38
+ end
39
+
40
+ it "returns the error in the body" do
41
+ do_post
42
+ last_response.body.should =~ /invalid/i
43
+ end
44
+ end
45
+
46
+ describe "when a user requests json" do
47
+ it "responds with json" do
48
+ do_post
49
+ last_response.content_type.should eql("application/json")
50
+ end
51
+ end
52
+
53
+ describe "when a user requests html" do
54
+ it "responds with html" do
55
+ do_post("html")
56
+ last_response.content_type.should eql("text/html")
57
+ end
58
+ end
59
+
60
+ def do_post(format = "json")
61
+ post "/post.#{format}", { "subscriber" => {"email" => email}}
62
+ end
63
+ end
64
+
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe MonkeyParty, :vcr do
4
+ it "retains a key value pair of lists" do
5
+ MonkeyParty.list_map.should_not eql({})
6
+ MonkeyParty.list_map.keys.should include("testing")
7
+ end
8
+
9
+ let(:new_list_name) { "some_list" }
10
+
11
+ it "allows for the setting of a list name" do
12
+ retain_old_list do
13
+ MonkeyParty.list_name = new_list_name
14
+ MonkeyParty.list_name.should eql(new_list_name)
15
+ end
16
+ end
17
+
18
+ describe "the list" do
19
+ it "raises an exception if the list is not found" do
20
+ retain_old_list do
21
+ MonkeyParty.list_name = "something nonexistant"
22
+ lambda { MonkeyParty.list }.should raise_error(MonkeyParty::ListNotFound)
23
+ end
24
+ end
25
+
26
+ it "raises an exception if the list is nil" do
27
+ retain_old_list do
28
+ MonkeyParty.stubs(:list_name).returns(nil)
29
+ lambda { MonkeyParty.list }.should raise_error(MonkeyParty::ListNotSet)
30
+ end
31
+ end
32
+ it "returns a monkey party list" do
33
+ retain_old_list do
34
+ MonkeyParty.list_name = 'testing'
35
+ MonkeyParty.list.should be_kind_of(MonkeyParty::List)
36
+ end
37
+ end
38
+ end
39
+
40
+ def retain_old_list(&block)
41
+ old_list = MonkeyParty.list_name.nil? ? nil : MonkeyParty.list_name.dup
42
+ yield
43
+ MonkeyParty.list_name = old_list
44
+ end
45
+ end
46
+
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+
3
+ require "mocha"
4
+ require 'rack/test'
5
+
6
+ require 'rack_monkey_party'
7
+
8
+ Dir[File.dirname(__FILE__) + "/support/*.rb"].each{|f| require f }
9
+
10
+ RSpec.configure do |c|
11
+ # so we can use `:vcr` rather than `:vcr => true`;
12
+ # in RSpec 3 this will no longer be necessary.
13
+ c.treat_symbols_as_metadata_keys_with_true_values = true
14
+ c.mock_with :mocha
15
+ end
16
+
@@ -0,0 +1,4 @@
1
+ MonkeyParty.api_key = '<your api key>'
2
+ MonkeyParty.data_center = 'us1'
3
+ MonkeyParty.list_name = '<your list name>'
4
+
@@ -0,0 +1,31 @@
1
+ require 'vcr'
2
+
3
+ mailchimp_matcher = lambda do |request_1, request_2|
4
+ uri_1 = URI(request_1.uri)
5
+ uri_2 = URI(request_2.uri)
6
+ api_key_phrase = /apikey=[^\&]*/
7
+
8
+ params_match = uri_1.query.gsub(api_key_phrase, "") == uri_2.query.gsub(api_key_phrase, "")
9
+ hosts_match = uri_1.host.gsub(/^us\d\./, "") == uri_2.host.gsub(/^us\d\./, "")
10
+ [
11
+ params_match,
12
+ hosts_match
13
+ ]
14
+ end
15
+
16
+ VCR.configure do |c|
17
+ c.cassette_library_dir = 'spec/cassettes'
18
+ c.hook_into :fakeweb
19
+ c.configure_rspec_metadata!
20
+ c.register_request_matcher :mailchimp_matcher do |req1, req2|
21
+ mailchimp_matcher.call(req1, req2)
22
+ end
23
+
24
+ c.default_cassette_options = {
25
+ :match_requests_on => [:method, :mailchimp_matcher],
26
+ :record => :new_episodes
27
+ }
28
+
29
+ c.filter_sensitive_data('<API KEY>') { MonkeyParty.api_key }
30
+ end
31
+
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_monkey_party
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Pickett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &2152019480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152019480
25
+ - !ruby/object:Gem::Dependency
26
+ name: monkey_party
27
+ requirement: &2152062060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152062060
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &2152059520 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2152059520
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2152057460 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152057460
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &2152102400 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152102400
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: &2152101640 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2152101640
80
+ - !ruby/object:Gem::Dependency
81
+ name: fakeweb
82
+ requirement: &2152100800 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2152100800
91
+ - !ruby/object:Gem::Dependency
92
+ name: vcr
93
+ requirement: &2152099900 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2152099900
102
+ - !ruby/object:Gem::Dependency
103
+ name: guard-rspec
104
+ requirement: &2152098800 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2152098800
113
+ - !ruby/object:Gem::Dependency
114
+ name: mocha
115
+ requirement: &2152097100 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *2152097100
124
+ description: A rack endpoint for adding subscribers to an email list
125
+ email:
126
+ - dpickett@enlightsolutions.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - .gitignore
132
+ - .rspec
133
+ - .rvmrc
134
+ - .travis.yml
135
+ - Gemfile
136
+ - Guardfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - lib/monkey_party/rack.rb
141
+ - lib/monkey_party/rack/app.rb
142
+ - lib/monkey_party/rack/version.rb
143
+ - lib/rack_monkey_party.rb
144
+ - rack_monkey_party.gemspec
145
+ - spec/cassettes/MonkeyParty/retains_a_key_value_pair_of_lists.yml
146
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_proper_subscriber_is_posted/returns_a_succcessful_response.yml
147
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_proper_subscriber_is_posted/returns_the_email_in_the_body.yml
148
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_user_requests_html/responds_with_html.yml
149
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_user_requests_json/responds_with_json.yml
150
+ - spec/cassettes/MonkeyParty_Rack_App/when_an_invalid_subscriber_is_posted/returns_a_412_unprecessable_entity.yml
151
+ - spec/cassettes/MonkeyParty_Rack_App/when_an_invalid_subscriber_is_posted/returns_the_error_in_the_body.yml
152
+ - spec/monkey_party/rack/app_spec.rb
153
+ - spec/rack_monkey_party_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/support/credentials.rb.example
156
+ - spec/support/vcr.rb
157
+ homepage: ''
158
+ licenses: []
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ segments:
170
+ - 0
171
+ hash: -2880476506234398934
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ segments:
179
+ - 0
180
+ hash: -2880476506234398934
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 1.8.17
184
+ signing_key:
185
+ specification_version: 3
186
+ summary: ! 'A rack endpoint for adding subscribers to an email list: uses the monkey_party
187
+ web wrapper'
188
+ test_files:
189
+ - spec/cassettes/MonkeyParty/retains_a_key_value_pair_of_lists.yml
190
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_proper_subscriber_is_posted/returns_a_succcessful_response.yml
191
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_proper_subscriber_is_posted/returns_the_email_in_the_body.yml
192
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_user_requests_html/responds_with_html.yml
193
+ - spec/cassettes/MonkeyParty_Rack_App/when_a_user_requests_json/responds_with_json.yml
194
+ - spec/cassettes/MonkeyParty_Rack_App/when_an_invalid_subscriber_is_posted/returns_a_412_unprecessable_entity.yml
195
+ - spec/cassettes/MonkeyParty_Rack_App/when_an_invalid_subscriber_is_posted/returns_the_error_in_the_body.yml
196
+ - spec/monkey_party/rack/app_spec.rb
197
+ - spec/rack_monkey_party_spec.rb
198
+ - spec/spec_helper.rb
199
+ - spec/support/credentials.rb.example
200
+ - spec/support/vcr.rb