hominid 2.2.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ #gem "json"
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.5.2"
10
+ gem "mocha", ">= 0.9.10"
11
+ gem "rcov", ">= 0.9.9"
12
+ gem "shoulda", ">= 2.11.3"
13
+ end
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mocha (0.9.10)
10
+ rake
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ shoulda (2.11.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.5.2)
21
+ mocha (>= 0.9.10)
22
+ rcov (>= 0.9.9)
23
+ shoulda (>= 2.11.3)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Brian Getting
1
+ Copyright (c) 2010 Brian Getting
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,114 +1,55 @@
1
1
  = Hominid
2
2
 
3
- Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp[http://eepurl.com/ew8J] email marketing service API ({version 1.2}[http://www.mailchimp.com/api/1.2/]).
4
-
5
- == Installation
6
-
7
- sudo gem install hominid
3
+ Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp[http://eepurl.com/ew8J] API.
8
4
 
9
5
  == Requirements
10
6
 
11
- You will need a Mailchimp[http://eepurl.com/ew8J] account. Once you have your Mailchimp account set up, you will need to {generate an API key}[http://admin.mailchimp.com/account/api/] in order to get started using Hominid.
12
-
13
- == Usage
14
-
15
- Hominid is intended to be a complete Ruby wrapper for working with the Mailchimp API. As of release 2.0.2, all methods available from the Mailchimp API (Version 1.2) are available. Please note in order to use some methods you will need to have {A.I.M. Reports}[https://admin.mailchimp.com/account/addons] installed on your Mailchimp account.
16
-
17
- You will need to pass your Mailchimp API key to get started:
18
-
19
- h = Hominid::Base.new({:api_key => API_KEY})
20
-
21
- You can also pass in any other config options that you would like to change from the defaults. Take a look at Hominid::Base to see what the default values are.
22
-
23
- Once you have created a Hominid object, you can begin interacting with the Mailchimp account that your API key is associated with.
24
-
25
- === Working with Lists
26
-
27
- We have provided some finder methods to make working with your mailing lists easier:
28
-
29
- lists = h.lists
30
- list = h.find_list_by_name("Mailing List Name")
31
- list = h.find_list_by_id("List ID")
32
- list = h.find_list_by_web_id("List Web ID")</code></pre>
33
-
34
- There are also finders for easily getting at List ID's, which are required for nearly all the list methods:
35
-
36
- list_id = h.find_list_id_by_name("Mailing List Name")
37
- list_id_ = h.find_list_id_by_web_id("List Web ID")
38
-
39
- This means that you can _(for example)_ subscribe someone to a particular mailing list:
7
+ You will need a {Mailchimp}[http://eepurl.com/ew8J] account. Once you have your Mailchimp account set up, you will need to {generate an API key}[http://admin.mailchimp.com/account/api/] in order to get started using Hominid.
40
8
 
41
- h.subscribe(h.find_list_id_by_name("Mailing List Name"), "email@domain.com", {:FNAME => "Bob", :LNAME => "Smith"}, {:email_type => 'html'})
42
-
43
- Or to update a subscriber to a particular list:
44
-
45
- h.update_member(h.find_list_id_by_name("Mailing List Name"), "old_email@domain.com", {:EMAIL => "new_email_@domain.com"}, 'html')
46
-
47
- Take a look at Hominid::List to see the methods that are available for interacting with your lists.
48
-
49
- === Working with Campaigns
50
-
51
- We have provided some finder methods to make working with your campaigns easier:
52
-
53
- campaigns = h.campaigns
54
- campaigns = h.find_campaigns_by_list_name("Mailing List Name")
55
- campaigns = h.find_campaigns_by_list_id("Mailing List ID")
56
- campaigns = h.find_campaigns_by_type("regular")
57
- campaign = h.find_campaign_by_id("Campaign ID")
58
- campaign = h.find_campaign_by_title("Campaign Title")
59
-
60
- To create a new campaign, use the +create_campaign+ method:
61
-
62
- new_campaign = h.create_campaign(...)
63
-
64
- Take a look at Hominid::Campaign to see the methods that are available for interacting with your campaigns.
65
-
66
- === Mailchimp Helper Methods
67
-
68
- There are a series of helper methods that are also made available with the Hominid gem. For example, to retrieve information about the Mailchimp account associated with your API key, simply:
69
-
70
- account_details_ = h.account_details
9
+ == Installation
71
10
 
72
- In this case, the +account_details+ object can be accessed like:
11
+ (sudo) gem install hominid
73
12
 
74
- account_details.contact.company
75
- account_details.orders
13
+ == Usage
76
14
 
77
- Take a look at Hominid::Helper to see the helper methods that are available.
15
+ Please refer to the {Mailchimp API Documentation}[http://www.mailchimp.com/api/1.3/] for information about what methods are available, the arguments that can be passed to each method, and the output that the API will return. Start by creating a Hominid object:
78
16
 
79
- === Mailchimp Security Methods
17
+ h = Hominid::API.new('your_api_key')
80
18
 
81
- There are a couple of security methods that are also made available with the Hominid gem. These are primarily used for dealing with API keys, and require your Mailchimp account username and password:
19
+ You can then run any of the methods that you find in the {Mailchimp API Documentation}[http://www.mailchimp.com/api/1.3/] against it. Simply convert the names to the more Ruby-like underscored versions. You do not need to pass your api_key to each method, as that is done automatically for you:
82
20
 
83
- h.api_keys('username', 'password')
21
+ h.get_account_details
22
+ h.lists
23
+ h.campaign_create('regular', {:list_id => 'list_id', ...}, {:html => 'Campaign HTML content', ...})
24
+ h.template_add('template_name', 'Template HTML Code')
25
+
26
+ The {Mailchimp API}[http://www.mailchimp.com/api/1.3/] now supports pagination for some methods, so certain methods will have the following response:
84
27
 
85
- Take a look at Hominid::Security to see the security methods that are available.
28
+ h.lists['total'] => 4
29
+ h.lists['data'] => outputs an array of your mailing lists
30
+ h.lists['data'].first => {"id" => "XXXXXXX", "web_id" => 1234567, "name" => "My Mailing List", ...}
86
31
 
87
- == Contributors
32
+ Please note that as of version 3.0.0 Hominid no longer includes support for the {Mailchimp Export API}[http://www.mailchimp.com/api/export/].
88
33
 
89
- Hominid is maintained by {Brian Getting}[http://terra-firma-design.com]. A very special thank-you to {Michael Strüder}[http://github.com/mikezter] for all of his hard work. Also, Hominid wouldn't be anywhere near as awesome as it is today without fantastic contributions and inspiration from:
34
+ == Examples
90
35
 
91
- * {Alan Harper}[http://github.com/aussiegeek]
92
- * {Will}[http://github.com/willinfront]
93
- * {Ben Woosley}[http://github.com/Empact]
94
- * {banker}[http://github.com/banker]
95
- * {Kristoffer Renholm}[http://github.com/renholm]
96
- * {Wiktor Schmidt}[http://github.com/netguru]
97
- * {ron}[http://github.com/ron]
98
- * {Matthew Carlson}[http://mandarinsoda.com/]
99
- * {Kelly Mahan}[http://digimedia.com/]
100
- * {C.G. Brown}[http://www.projectlocker.com/]
101
- * {Bill Abney}[http://github.com/babney]
102
- * {David Rice}[http://github.com/davidjrice]
36
+ Hominid includes some finder methods for campaigns (see Hominid::Campaign) and lists (see Hominid::List) to help with finding each of these resources:
103
37
 
104
- == Note on Patches/Pull Requests
38
+ h.find_list_by_name('my_mailing_list')
39
+ h.find_list_id_by_name('my_mailing_list')
40
+ h.find_campaigns_by_list_name('my_mailing_list')
105
41
 
106
- 1. Fork the project.
107
- 2. Make your feature addition or bug fix.
108
- 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
109
- 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
110
- 5. Send me a pull request. Bonus points for topic branches.
42
+ == Contributing to hominid
43
+
44
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
45
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
46
+ * Fork the project
47
+ * Start a feature/bugfix branch
48
+ * Commit and push until you are happy with your contribution
49
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
50
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
111
51
 
112
52
  == Copyright
113
53
 
114
- Copyright (c) 2009 Brian Getting. See LICENSE for details.
54
+ Copyright (c) 2010 Brian Getting. See LICENSE.txt for further details.
55
+
data/Rakefile CHANGED
@@ -1,59 +1,49 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
2
10
  require 'rake'
3
11
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "hominid"
8
- gem.summary = %Q{Hominid is a Ruby gem for interacting with the Mailchimp API.}
9
- gem.description = %Q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.}
10
- gem.email = "brian@terra-firma-design.com"
11
- gem.homepage = "http://github.com/bgetting/hominid"
12
- gem.authors = ["Brian Getting", "Michael Strüder"]
13
- gem.add_dependency 'json', '>=1.2.0'
14
- gem.add_development_dependency 'jeweler'
15
- gem.add_development_dependency 'shoulda'
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "hominid"
16
+ gem.homepage = "http://github.com/bgetting/hominid"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Hominid is a Ruby wrapper for the Mailchimp API}
19
+ gem.description = %Q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.}
20
+ gem.email = "brian@terra-firma-design.com"
21
+ gem.authors = ["Brian Getting"]
20
22
  end
23
+ Jeweler::RubygemsDotOrgTasks.new
21
24
 
22
25
  require 'rake/testtask'
23
26
  Rake::TestTask.new(:test) do |test|
24
27
  test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/*_test.rb'
28
+ test.pattern = 'test/**/test_*.rb'
26
29
  test.verbose = true
27
30
  end
28
31
 
29
- begin
30
- require 'rcov/rcovtask'
31
- Rcov::RcovTask.new do |test|
32
- test.libs << 'test'
33
- test.pattern = 'test/**/*_test.rb'
34
- test.verbose = true
35
- end
36
- rescue LoadError
37
- task :rcov do
38
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
- end
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
40
37
  end
41
38
 
42
- task :test => :check_dependencies
43
-
44
39
  task :default => :test
45
40
 
46
41
  require 'rake/rdoctask'
47
42
  Rake::RDocTask.new do |rdoc|
48
- if File.exist?('VERSION')
49
- version = File.read('VERSION')
50
- else
51
- version = ""
52
- end
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
44
 
54
45
  rdoc.rdoc_dir = 'rdoc'
55
46
  rdoc.title = "hominid #{version}"
56
47
  rdoc.rdoc_files.include('README*')
57
48
  rdoc.rdoc_files.include('lib/**/*.rb')
58
49
  end
59
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 3.0.1
@@ -1,45 +1,44 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hominid}
8
- s.version = "2.2.0"
8
+ s.version = "3.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Brian Getting", "Michael Str\303\274der"]
12
- s.date = %q{2010-09-28}
11
+ s.authors = ["Brian Getting"]
12
+ s.date = %q{2010-12-20}
13
13
  s.description = %q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.}
14
14
  s.email = %q{brian@terra-firma-design.com}
15
15
  s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "hominid.gemspec",
26
- "lib/hominid.rb",
27
- "lib/hominid/base.rb",
28
- "lib/hominid/campaign.rb",
29
- "lib/hominid/helper.rb",
30
- "lib/hominid/list.rb",
31
- "lib/hominid/security.rb",
32
- "test/hominid_test.rb",
33
- "test/test_helper.rb"
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "hominid.gemspec",
27
+ "lib/hominid.rb",
28
+ "lib/hominid/campaign.rb",
29
+ "lib/hominid/list.rb",
30
+ "lib/hominid/security.rb",
31
+ "test/helper.rb",
32
+ "test/test_hominid.rb"
34
33
  ]
35
34
  s.homepage = %q{http://github.com/bgetting/hominid}
36
- s.rdoc_options = ["--charset=UTF-8"]
35
+ s.licenses = ["MIT"]
37
36
  s.require_paths = ["lib"]
38
37
  s.rubygems_version = %q{1.3.7}
39
- s.summary = %q{Hominid is a Ruby gem for interacting with the Mailchimp API.}
38
+ s.summary = %q{Hominid is a Ruby wrapper for the Mailchimp API}
40
39
  s.test_files = [
41
- "test/hominid_test.rb",
42
- "test/test_helper.rb"
40
+ "test/helper.rb",
41
+ "test/test_hominid.rb"
43
42
  ]
44
43
 
45
44
  if s.respond_to? :specification_version then
@@ -47,18 +46,24 @@ Gem::Specification.new do |s|
47
46
  s.specification_version = 3
48
47
 
49
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
51
- s.add_development_dependency(%q<jeweler>, [">= 0"])
52
- s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<mocha>, [">= 0.9.10"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0.9.9"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
53
54
  else
54
- s.add_dependency(%q<json>, [">= 1.2.0"])
55
- s.add_dependency(%q<jeweler>, [">= 0"])
56
- s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<mocha>, [">= 0.9.10"])
58
+ s.add_dependency(%q<rcov>, [">= 0.9.9"])
59
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
57
60
  end
58
61
  else
59
- s.add_dependency(%q<json>, [">= 1.2.0"])
60
- s.add_dependency(%q<jeweler>, [">= 0"])
61
- s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<mocha>, [">= 0.9.10"])
65
+ s.add_dependency(%q<rcov>, [">= 0.9.9"])
66
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
62
67
  end
63
68
  end
64
69
 
@@ -1,40 +1,65 @@
1
- require 'json'
1
+ # TODO: Write tests (include mocks for API calls) -- refer to Koala testing for mocks.
2
+ require 'openssl'
2
3
  require 'xmlrpc/client'
3
- require 'ostruct'
4
+
5
+ require 'hominid/campaign'
6
+ require 'hominid/list'
7
+ require 'hominid/security'
4
8
 
5
9
  module Hominid
10
+ class API
11
+ # Blank Slate
12
+ instance_methods.each do |m|
13
+ undef_method m unless m.to_s =~ /^__|object_id|method_missing|respond_to?|to_s|inspect/
14
+ end
15
+
16
+ include Hominid::Campaign
17
+ include Hominid::List
18
+ include Hominid::Security
19
+
20
+ # MailChimp API Documentation: http://www.mailchimp.com/api/1.3/
21
+ MAILCHIMP_API_VERSION = "1.3"
6
22
 
7
- class StandardError < ::StandardError
8
- end
23
+ # Initialize with an API key and config options
24
+ def initialize(api_key, config = {})
25
+ raise ArgumentError.new('Your Mailchimp API key appears to be malformed') unless api_key.include?('-')
26
+ dc = api_key.split('-').last
27
+ defaults = {
28
+ :api_version => MAILCHIMP_API_VERSION,
29
+ :secure => false,
30
+ :timeout => nil
31
+ }
32
+ @config = defaults.merge(config).freeze
33
+ protocol = @config[:secure] ? 'https' : 'http'
34
+ @api_key = api_key
35
+ @chimpApi = XMLRPC::Client.new2("#{protocol}://#{dc}.api.mailchimp.com/#{MAILCHIMP_API_VERSION}/", nil, config[:timeout])
36
+ end
9
37
 
38
+ def method_missing(api_method, *args) # :nodoc:
39
+ @chimpApi.call(api_method.to_s.camelize_api_method_name, @api_key, *args)
40
+ rescue XMLRPC::FaultException => error
41
+ super if error.faultCode == -32601
42
+ raise APIError.new(error)
43
+ end
44
+
45
+ def respond_to?(api_method)
46
+ @chimpApi.call(api_method, @api_key)
47
+ rescue XMLRPC::FaultException => error
48
+ error.faultCode == -32601 ? false : true
49
+ end
50
+
51
+ end
52
+
10
53
  class APIError < StandardError
11
54
  def initialize(error)
12
55
  super("<#{error.faultCode}> #{error.message}")
13
56
  end
14
57
  end
15
-
16
- class CampaignError < APIError
17
- end
18
-
19
- class ListError < APIError
20
- end
21
-
22
- class UserError < APIError
23
- end
24
-
25
- class ValidationError < APIError
26
- end
27
58
 
28
- class CommunicationError < StandardError
29
- def initialize(message)
30
- super(message)
31
- end
32
- end
33
-
34
59
  end
35
60
 
36
- require 'hominid/campaign'
37
- require 'hominid/helper'
38
- require 'hominid/list'
39
- require 'hominid/security'
40
- require 'hominid/base'
61
+ class String
62
+ def camelize_api_method_name
63
+ self.to_s[0].chr.downcase + self.gsub(/(?:^|_)(.)/) { $1.upcase }[1..self.size]
64
+ end
65
+ end