chimp_mailer 0.1.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Small Spark Pty Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ 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.
data/README.markdown ADDED
@@ -0,0 +1,23 @@
1
+ # ChimpMailer
2
+
3
+ Currently a thin wrapper around the MailChimp API.
4
+
5
+ Will eventually be expanded to integrate into Rails in many awesome ways.
6
+
7
+ ## Installation
8
+
9
+ `gem install chimp_mailer`
10
+
11
+ ## Example
12
+
13
+ In your environment.rb:
14
+
15
+ `MailChimp.settings = { :api_key => 'YOUR API KEY HERE' }`
16
+
17
+ Then you can call any MailChimp API method like so:
18
+
19
+ `MailChimp.campaign_schedule(:cid => 'afd3245', :schedule_time => '2010-06-21 12:30:00')`
20
+
21
+ ---
22
+
23
+ Copyright (c) 2010 Small Spark Pty Ltd, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Test the chimp_mailer plugin.'
9
+ Spec::Rake::SpecTask.new do |t|
10
+ t.spec_opts = ['--options', File.join(File.dirname(__FILE__), %w(spec spec.opts))]
11
+ end
12
+
13
+ desc 'Generate documentation for the chimp_mailer plugin.'
14
+ Rake::RDocTask.new(:rdoc) do |rdoc|
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = 'ChimpMailer'
17
+ rdoc.options << '--line-numbers' << '--inline-source'
18
+ rdoc.rdoc_files.include('README')
19
+ rdoc.rdoc_files.include('lib/**/*.rb')
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+ require 'active_support'
4
+
5
+ class MailChimpError < Exception; end
6
+
7
+ class MailChimp
8
+ @@api_key = ''
9
+ @@api_version = '1.2'
10
+ @@datacenter = 'us1'
11
+ @@default_options = {:output => :json}
12
+ @@url = "http://#{@@datacenter}.api.mailchimp.com/#{@@api_version}/"
13
+
14
+ def self.settings=(settings)
15
+ settings.each do |key, value|
16
+ class_variable_set("@@#{key}".to_sym, value)
17
+ if key == 'api_key'
18
+ @@datacenter = @@api_key.split('-').last
19
+ end
20
+ end
21
+ @@url = "http://#{@@datacenter}.api.mailchimp.com/#{@@api_version}/"
22
+ @@default_options = {:apikey => @@api_key, :output => :json}
23
+ end
24
+
25
+ def self.method_missing(name, *args)
26
+ options = args.last.class == Hash ? args.last : {}
27
+ options.merge!(@@default_options)
28
+ options[:method] = name.to_s.camelize(:lower)
29
+
30
+ raw_response = RestClient.get("#{@@url}?#{options.to_query}", :accept => :json)
31
+
32
+ response = ActiveSupport::JSON.decode(raw_response) if response.class == String
33
+ if response.class == Array
34
+ response.each { |x| x.symbolize_keys }
35
+ elsif response.class == Hash
36
+ response.symbolize_keys!
37
+ raise MailChimpError, "(#{response[:code] ? response[:code] : 'no code'}) #{response[:error]}" if response[:error]
38
+ end
39
+
40
+ return response
41
+ end
42
+
43
+ def self.log=(logger)
44
+ RestClient.log = logger
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'MailChimp' do
4
+ it 'should perform an API call' do
5
+ RestClient.expects(:get).with('http://us1.api.mailchimp.com/1.2/?cid=afd3245&method=campaignSchedule&output=json&schedule_time=2010-06-21+12%3A30%3A00', :accept => :json).once.returns(true)
6
+ MailChimp.campaign_schedule(:cid => 'afd3245', :schedule_time => '2010-06-21 12:30:00')
7
+ end
8
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'chimp_mailer'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with :mocha
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chimp_mailer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Small Spark
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-17 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: weary
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 7
30
+ - 2
31
+ version: 0.7.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: A Ruby library for interacting with the MailChimp API.
47
+ email: contact@smallspark.com.au
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - MIT-LICENSE
56
+ - Rakefile
57
+ - README.markdown
58
+ - lib/chimp_mailer.rb
59
+ - spec/spec.opts
60
+ - spec/spec_helper.rb
61
+ - spec/chimp_mailer_spec.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/smallspark/chimp_mailer
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A Ruby library for interacting with the MailChimp API.
92
+ test_files:
93
+ - spec/spec_helper.rb
94
+ - spec/chimp_mailer_spec.rb