monkey_party 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +16 -2
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE +4 -2
  8. data/README.md +44 -0
  9. data/Rakefile +7 -56
  10. data/lib/monkey_party/base.rb +8 -4
  11. data/lib/monkey_party/error.rb +1 -0
  12. data/lib/monkey_party/list.rb +6 -5
  13. data/lib/monkey_party/subscriber.rb +1 -0
  14. data/lib/monkey_party/version.rb +4 -0
  15. data/lib/monkey_party.rb +26 -7
  16. data/monkey_party.gemspec +20 -80
  17. data/spec/cassettes/MonkeyParty_List/subscribing/handles_errors_gracefully.yml +135 -0
  18. data/spec/cassettes/MonkeyParty_List/subscribing/subscribes_someone_successfully.yml +205 -0
  19. data/spec/cassettes/MonkeyParty_List/unsubscribing/should_have_valid_subscribers.yml +205 -0
  20. data/spec/monkey_party/list_spec.rb +43 -0
  21. data/spec/monkey_party/subscriber_spec.rb +12 -0
  22. data/spec/spec_helper.rb +14 -0
  23. data/spec/support/credentials.rb.example +3 -0
  24. data/spec/support/vcr.rb +28 -0
  25. metadata +124 -117
  26. data/README.rdoc +0 -26
  27. data/VERSION.yml +0 -5
  28. data/features/create_and_add_api_key.feature +0 -21
  29. data/features/list_subscribe.feature +0 -13
  30. data/features/list_unsubscribe.feature +0 -14
  31. data/features/step_definitions/create_and_add_api_key_steps.rb +0 -45
  32. data/features/step_definitions/list_steps.rb +0 -17
  33. data/features/step_definitions/list_unsubscribe_steps.rb +0 -17
  34. data/features/support/env.rb +0 -4
  35. data/features/support/mailchimp/account.rb +0 -8
  36. data/features/support/mailchimp/account.yml.example +0 -2
  37. data/features/support/mailchimp/cleaner.rb +0 -3
  38. data/lib/monkey_party/account.rb +0 -48
  39. data/test/fixtures/batch_subscribe_failed.xml +0 -28
  40. data/test/fixtures/batch_subscribe_successful.xml +0 -12
  41. data/test/fixtures/batch_unsubscribe_failed.xml +0 -19
  42. data/test/fixtures/batch_unsubscribe_successful.xml +0 -12
  43. data/test/fixtures/lists_failed.xml +0 -11
  44. data/test/fixtures/lists_successful.xml +0 -16
  45. data/test/fixtures/login_failed.xml +0 -11
  46. data/test/fixtures/login_successful.xml +0 -8
  47. data/test/monkey_party/account_test.rb +0 -91
  48. data/test/monkey_party/error_test.rb +0 -18
  49. data/test/monkey_party/list_test.rb +0 -173
  50. data/test/monkey_party/subscriber_test.rb +0 -44
  51. data/test/test_helper.rb +0 -31
data/.gitignore CHANGED
@@ -1,6 +1,20 @@
1
- *.sw?
2
- .DS_Store
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
3
9
  coverage
4
10
  rdoc
11
+ doc/
12
+ lib/bundler/man
5
13
  pkg
6
14
  features/support/mailchimp/account.yml
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ spec/support/credentials.rb
20
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@monkey_party --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ env: MCAPI_KEY=1234
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 monkey_party.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'growl'
8
+ gem 'pry'
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 CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 Dan Pickett
1
+ Copyright (c) 2012 Dan Pickett
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # MonkeyParty
2
+
3
+ [![Build Status](https://secure.travis-ci.org/dpickett/monkey_party.png)](http://travis-ci.org/dpickett/monkey_party)
4
+
5
+ An extremely young API for interacting with the MailChimp API
6
+
7
+ Currently only supports
8
+
9
+ * adding api keys
10
+ * finding lists by name
11
+ * batch subscribing
12
+ * unsubscribing
13
+
14
+ Uses the excellent HTTParty and HappyMapper tools and is well tested
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'monkey_party'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install monkey_party
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ list = MonkeyParty::List.find_by_name("list_name")
34
+ list.create_subscribers([MonkeyParty::Subscriber.new("user@example.com")])
35
+ ```
36
+
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,63 +1,14 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
1
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "monkey_party"
8
- gem.summary = %Q{mailchimp wrapper}
9
- gem.email = "dpickett@enlightsolutions.com"
10
- gem.homepage = "http://github.com/dpickett/monkey_party"
11
- gem.authors = ["Dan Pickett"]
12
- gem.add_dependency("httparty", ">= 0.5.2")
13
- gem.add_dependency("happymapper", ">= 0.3.0")
14
- gem.add_dependency("configatron", ">= 2.6.3")
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- rescue LoadError
18
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
- end
2
+ require 'rspec/core/rake_task'
20
3
 
21
- begin
22
- require 'cucumber'
23
- require 'cucumber/rake/task'
24
-
25
- Cucumber::Rake::Task.new(:cucumber) do |t|
26
- t.cucumber_opts = "--format pretty" # Any valid command line option can go here.
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new do |t|
27
6
  end
28
7
 
8
+ task default: :spec
29
9
  rescue LoadError
30
- puts "Cucumber not installed. You will not be able to run features"
31
- end
32
-
33
- require 'rake/rdoctask'
34
- Rake::RDocTask.new do |rdoc|
35
- rdoc.rdoc_dir = 'rdoc'
36
- rdoc.title = 'monkey_party'
37
- rdoc.options << '--line-numbers' << '--inline-source'
38
- rdoc.rdoc_files.include('README*')
39
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ puts "RSpec is not installed"
40
11
  end
41
12
 
42
- require 'rake/testtask'
43
- Rake::TestTask.new(:test) do |test|
44
- test.libs << 'lib' << 'test'
45
- test.pattern = 'test/**/*_test.rb'
46
- test.verbose = false
47
- end
48
-
49
- begin
50
- require 'rcov/rcovtask'
51
- Rcov::RcovTask.new do |test|
52
- test.libs << 'test'
53
- test.pattern = 'test/**/*_test.rb'
54
- test.verbose = true
55
- end
56
- rescue LoadError
57
- task :rcov do
58
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
59
- end
60
- end
61
-
62
-
63
- task :default => :test
13
+ #!/usr/bin/env rake
14
+ require "bundler/gem_tasks"
@@ -1,15 +1,13 @@
1
- require "ruby-debug"
2
1
  module MonkeyParty
3
2
  class Base
4
3
  include HTTParty
5
- base_uri 'http://api.mailchimp.com/1.2/'
6
4
  default_params :output => "xml"
7
5
 
8
6
  def initialize(attrs = {})
9
7
  attrs.each{ |key, value| self.send("#{key}=", value) }
10
8
  end
11
9
 
12
- class << self
10
+ class << self
13
11
  def get(path, options = {})
14
12
  #fix the format because Mail Chimp doesn't pass the proper header
15
13
  options[:format] = :xml
@@ -22,9 +20,15 @@ module MonkeyParty
22
20
  end
23
21
 
24
22
  def api_key
25
- configatron.mailchimp.api_key
23
+ MonkeyParty.api_key
26
24
  end
27
25
 
26
+ def default_options
27
+ {
28
+ :base_uri => "http://#{MonkeyParty.data_center}.api.mailchimp.com/1.2"
29
+ }
30
+ end
28
31
  end
29
32
  end
30
33
  end
34
+
@@ -7,3 +7,4 @@ module MonkeyParty
7
7
  element :code, Integer
8
8
  end
9
9
  end
10
+
@@ -23,14 +23,14 @@ module MonkeyParty
23
23
  index += 1
24
24
  end
25
25
 
26
- response = self.class.get("", :query => {
26
+ response = self.class.get("/", :query => {
27
27
  :apikey => self.class.api_key,
28
28
  :id => self.id,
29
29
  :method => "listBatchSubscribe",
30
30
  }.merge(options).merge(batch_hash))
31
31
 
32
32
  #response[1] is the error count
33
- if !response["MCAPI"].nil? && response["MCAPI"][1] > 0
33
+ if !response["MCAPI"].nil? &&
34
34
  attach_errors_to_subscribers(array_of_subscribers, response.body)
35
35
  end
36
36
 
@@ -50,13 +50,13 @@ module MonkeyParty
50
50
  batch_hash["emails[#{index}]"] = s.email
51
51
  end
52
52
 
53
- response = self.class.get("", :query => {
53
+ response = self.class.get("/", :query => {
54
54
  :apikey => self.class.api_key,
55
55
  :id => self.id,
56
56
  :method => "listBatchUnsubscribe"
57
57
  }.merge(options).merge(batch_hash))
58
58
 
59
- if !response["MCAPI"].nil? && response["MCAPI"][1] > 0
59
+ if !response["MCAPI"].nil?
60
60
  attach_errors_to_subscribers(array_of_unsubscribers, response.body)
61
61
  end
62
62
 
@@ -65,7 +65,7 @@ module MonkeyParty
65
65
 
66
66
  class << self
67
67
  def all
68
- response = get("", :query => {
68
+ response = get("/", :query => {
69
69
  :apikey => api_key,
70
70
  :method => "lists"
71
71
  })
@@ -97,3 +97,4 @@ module MonkeyParty
97
97
  end
98
98
  end
99
99
  end
100
+
@@ -28,3 +28,4 @@ module MonkeyParty
28
28
  end
29
29
  end
30
30
  end
31
+
@@ -0,0 +1,4 @@
1
+ module MonkeyParty
2
+ VERSION = "0.3.0"
3
+ end
4
+
data/lib/monkey_party.rb CHANGED
@@ -1,14 +1,33 @@
1
- require "rubygems"
2
- require "httparty"
3
- require "happymapper"
1
+ require "monkey_party/version"
4
2
 
5
- require "configatron"
3
+ module MonkeyParty
4
+ def self.api_key=(api_key)
5
+ @api_key = api_key
6
+ end
6
7
 
7
- require "monkey_party/error"
8
+ def self.api_key
9
+ @api_key || ENV["MCAPI_KEY"]
10
+ end
11
+
12
+ def self.data_center=(data_center)
13
+ @data_center = data_center
14
+ end
15
+
16
+ def self.data_center
17
+ @data_center || default_data_center
18
+ end
19
+
20
+ def self.data_center
21
+ "us1"
22
+ end
23
+ end
24
+
25
+ require "httparty"
26
+ require "happymapper"
8
27
 
9
28
  require "monkey_party/base"
10
29
 
11
- require "monkey_party/subscriber"
12
- require "monkey_party/account"
13
30
  require "monkey_party/list"
31
+ require "monkey_party/error"
32
+ require "monkey_party/subscriber"
14
33
 
data/monkey_party.gemspec CHANGED
@@ -1,87 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/monkey_party/version', __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{monkey_party}
8
- s.version = "0.2.0"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Pickett"]
6
+ gem.email = ["dan.pickett@launchware.com"]
7
+ gem.description = %q{A web wrapper for mailchimp}
8
+ gem.summary = %q{A web wrapper for mailchimp}
9
+ gem.homepage = ""
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dan Pickett"]
12
- s.date = %q{2010-06-07}
13
- s.email = %q{dpickett@enlightsolutions.com}
14
- s.extra_rdoc_files = [
15
- "LICENSE",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "LICENSE",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION.yml",
24
- "features/create_and_add_api_key.feature",
25
- "features/list_subscribe.feature",
26
- "features/list_unsubscribe.feature",
27
- "features/step_definitions/create_and_add_api_key_steps.rb",
28
- "features/step_definitions/list_steps.rb",
29
- "features/step_definitions/list_unsubscribe_steps.rb",
30
- "features/support/env.rb",
31
- "features/support/mailchimp/account.rb",
32
- "features/support/mailchimp/account.yml.example",
33
- "features/support/mailchimp/cleaner.rb",
34
- "lib/monkey_party.rb",
35
- "lib/monkey_party/account.rb",
36
- "lib/monkey_party/base.rb",
37
- "lib/monkey_party/error.rb",
38
- "lib/monkey_party/list.rb",
39
- "lib/monkey_party/subscriber.rb",
40
- "monkey_party.gemspec",
41
- "test/fixtures/batch_subscribe_failed.xml",
42
- "test/fixtures/batch_subscribe_successful.xml",
43
- "test/fixtures/batch_unsubscribe_failed.xml",
44
- "test/fixtures/batch_unsubscribe_successful.xml",
45
- "test/fixtures/lists_failed.xml",
46
- "test/fixtures/lists_successful.xml",
47
- "test/fixtures/login_failed.xml",
48
- "test/fixtures/login_successful.xml",
49
- "test/monkey_party/account_test.rb",
50
- "test/monkey_party/error_test.rb",
51
- "test/monkey_party/list_test.rb",
52
- "test/monkey_party/subscriber_test.rb",
53
- "test/test_helper.rb"
54
- ]
55
- s.homepage = %q{http://github.com/dpickett/monkey_party}
56
- s.rdoc_options = ["--charset=UTF-8"]
57
- s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.7}
59
- s.summary = %q{mailchimp wrapper}
60
- s.test_files = [
61
- "test/monkey_party/account_test.rb",
62
- "test/monkey_party/error_test.rb",
63
- "test/monkey_party/list_test.rb",
64
- "test/monkey_party/subscriber_test.rb",
65
- "test/test_helper.rb"
66
- ]
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 = "monkey_party"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MonkeyParty::VERSION
67
17
 
68
- if s.respond_to? :specification_version then
69
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
- s.specification_version = 3
18
+ gem.add_dependency "httparty"
19
+ gem.add_dependency "happymapper", "0.4.0"
71
20
 
72
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
73
- s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
74
- s.add_runtime_dependency(%q<happymapper>, [">= 0.3.0"])
75
- s.add_runtime_dependency(%q<configatron>, [">= 2.6.3"])
76
- else
77
- s.add_dependency(%q<httparty>, [">= 0.5.2"])
78
- s.add_dependency(%q<happymapper>, [">= 0.3.0"])
79
- s.add_dependency(%q<configatron>, [">= 2.6.3"])
80
- end
81
- else
82
- s.add_dependency(%q<httparty>, [">= 0.5.2"])
83
- s.add_dependency(%q<happymapper>, [">= 0.3.0"])
84
- s.add_dependency(%q<configatron>, [">= 2.6.3"])
85
- end
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "fakeweb"
24
+ gem.add_development_dependency "vcr"
25
+ gem.add_development_dependency "guard-rspec"
86
26
  end
87
27
 
@@ -0,0 +1,135 @@
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 03:00:56 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">0</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">0</member_count_since_send>
66
+
67
+ <unsubscribe_count_since_send type="double">0</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 03:00:56 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]=badEmail
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 03:00:56 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
+ - '354'
106
+ body:
107
+ encoding: US-ASCII
108
+ string: ! '<MCAPI type="array">
109
+
110
+ <success_count type="integer">0</success_count>
111
+
112
+ <error_count type="integer">1</error_count>
113
+
114
+ <errors type="array">
115
+
116
+ <struct key="0" type="array">
117
+
118
+ <code type="integer">502</code>
119
+
120
+ <message type="string">Invalid Email Address: badEmail</message>
121
+
122
+ <row type="array">
123
+
124
+ <EMAIL type="string">badEmail</EMAIL>
125
+
126
+ </row>
127
+
128
+ </struct>
129
+
130
+ </errors>
131
+
132
+ </MCAPI>'
133
+ http_version: '1.1'
134
+ recorded_at: Sun, 11 Mar 2012 03:00:56 GMT
135
+ recorded_with: VCR 2.0.0