hominid 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.textile +125 -40
- data/Rakefile +45 -16
- data/VERSION +1 -0
- data/hominid.gemspec +26 -19
- data/hominid.yml.tpl +1 -0
- data/lib/hominid.rb +33 -244
- data/lib/hominid/base.rb +85 -0
- data/lib/hominid/campaign.rb +172 -0
- data/lib/hominid/helper.rb +45 -0
- data/lib/hominid/list.rb +150 -0
- data/lib/hominid/webhook.rb +131 -0
- data/tasks/rails/hominid.rake +22 -0
- data/test/hominid_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +30 -17
- data/VERSION.yml +0 -4
- data/init.rb +0 -1
- data/install.rb +0 -4
- data/pkg/hominid-1.2.1.gem +0 -0
- data/rails/init.rb +0 -1
- data/spec/hominid_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -3
- data/uninstall.rb +0 -1
@@ -0,0 +1,131 @@
|
|
1
|
+
module Hominid
|
2
|
+
|
3
|
+
class Webhook < Base
|
4
|
+
# Expects a hash of POST data generated from Mailchimp:
|
5
|
+
#
|
6
|
+
# "type": "unsubscribe",
|
7
|
+
# "fired_at": "2009-03-26 21:54:00",
|
8
|
+
# "data[email]": "sample@emailaddress.com"
|
9
|
+
#
|
10
|
+
# Simple Usage:
|
11
|
+
#
|
12
|
+
# h = Hominid::Webhook.new(params)
|
13
|
+
#
|
14
|
+
# Sample params from Mailchimp webhook:
|
15
|
+
# params => { "type" => "subscribe",
|
16
|
+
# "fired_at" => "2009-03-26 21:35:57",
|
17
|
+
# "data" => { "id" => "8a25ff1d98",
|
18
|
+
# "list_id" => "8a25ff1d98",
|
19
|
+
# "email" => "api@mailchimp.com",
|
20
|
+
# "email_type" => "html",
|
21
|
+
# "merges" => {"EMAIL" => "api@mailchimp.com",
|
22
|
+
# "FNAME" => "Brian",
|
23
|
+
# "LNAME" => "Getting",
|
24
|
+
# "INTERESTS" => "Group1,Group2"},
|
25
|
+
# "ip_opt" => "10.20.10.30",
|
26
|
+
# "ip_signup" => "10.20.10.30" }}
|
27
|
+
#
|
28
|
+
# Returns an object with the following methods (NOTE: Not all methods are available
|
29
|
+
# for all event types. Refer to http://www.mailchimp.com/api/webhooks/ for information
|
30
|
+
# on what data will be available for each event):
|
31
|
+
#
|
32
|
+
# h.event <= (String) The event that fired the request. Possible events are:
|
33
|
+
# "subscribe", "unsubscribe", "profile", "upemail", "cleaned"
|
34
|
+
# h.fired_at <= (Datetime) When the webhook request was fired.
|
35
|
+
# h.id <= (String) The ID of the webhook request.
|
36
|
+
# h.list_id <= (String) The ID of the list that generated the request.
|
37
|
+
# h.email <= (String) The email address of the subscriber that generated the request.
|
38
|
+
# h.email_type <= (String) The email type of the subscriber that generated the request.
|
39
|
+
# h.first_name <= (String) The first name of the subscriber (if available).
|
40
|
+
# h.last_name <= (String) The first name of the subscriber (if available).
|
41
|
+
# h.interests <= (Array) An array of the interest groups.
|
42
|
+
# h.ip_opt <= (String) The opt in IP address.
|
43
|
+
# h.ip_signup <= (String) The signup IP address.
|
44
|
+
#
|
45
|
+
|
46
|
+
attr_reader :request
|
47
|
+
|
48
|
+
def initialize(*args)
|
49
|
+
post_data = args.last
|
50
|
+
raise HominidError.new('Please provide the POST data from a Mailchimp webhook request.') unless post_data.is_a?(Hash)
|
51
|
+
post_data.merge!({"event" => "#{post_data.delete('type')}"})
|
52
|
+
@request = hash_to_object(post_data)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def email
|
57
|
+
self.request.data.email if self.request.data.email
|
58
|
+
end
|
59
|
+
|
60
|
+
def email_type
|
61
|
+
self.request.data.email_type if self.request.data.email_type
|
62
|
+
end
|
63
|
+
|
64
|
+
def event
|
65
|
+
self.request.event if self.request.event
|
66
|
+
end
|
67
|
+
|
68
|
+
def fired_at
|
69
|
+
self.request.fired_at.to_datetime if self.request.fired_at
|
70
|
+
end
|
71
|
+
|
72
|
+
def first_name
|
73
|
+
self.request.data.merges.fname if self.request.data.merges.fname
|
74
|
+
end
|
75
|
+
|
76
|
+
def last_name
|
77
|
+
self.request.data.merges.lname if self.request.data.merges.lname
|
78
|
+
end
|
79
|
+
|
80
|
+
def id
|
81
|
+
self.request.data.id if self.request.data.id
|
82
|
+
end
|
83
|
+
|
84
|
+
def interests
|
85
|
+
self.request.data.merges.interests.split(',') if self.request.data.merges.interests
|
86
|
+
end
|
87
|
+
|
88
|
+
def ip_opt
|
89
|
+
self.request.data.ip_opt if self.request.data.ip_opt
|
90
|
+
end
|
91
|
+
|
92
|
+
def ip_signup
|
93
|
+
self.request.data.ip_signup if self.request.data.ip_signup
|
94
|
+
end
|
95
|
+
|
96
|
+
def list_id
|
97
|
+
self.request.data.list_id if self.request.data.list_id
|
98
|
+
end
|
99
|
+
|
100
|
+
def new_email
|
101
|
+
self.request.data.new_email if self.request.data.new_email
|
102
|
+
end
|
103
|
+
|
104
|
+
def old_email
|
105
|
+
self.request.data.old_email if self.request.data.old_email
|
106
|
+
end
|
107
|
+
|
108
|
+
def reason
|
109
|
+
self.request.data.reason if self.request.data.reason
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def hash_to_object(object)
|
115
|
+
return case object
|
116
|
+
when Hash
|
117
|
+
object = object.clone
|
118
|
+
object.each do |key, value|
|
119
|
+
object[key.downcase] = hash_to_object(value)
|
120
|
+
end
|
121
|
+
OpenStruct.new(object)
|
122
|
+
when Array
|
123
|
+
object = object.clone
|
124
|
+
object.map! { |i| hash_to_object(i) }
|
125
|
+
else
|
126
|
+
object
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
namespace :hominid do
|
3
|
+
# Task to create the config file
|
4
|
+
desc "Generate a Hominid config file"
|
5
|
+
task :config => :environment do |t|
|
6
|
+
require 'fileutils'
|
7
|
+
if defined?(Rails.root)
|
8
|
+
config_file = File.join(Rails.root, 'config', 'hominid.yml')
|
9
|
+
template_file = File.join(File.dirname(__FILE__), '..', '..', 'hominid.yml.tpl')
|
10
|
+
unless File.exists? config_file
|
11
|
+
FileUtils.cp(
|
12
|
+
File.join(File.dirname(__FILE__), '..', '..', 'hominid.yml.tpl'),
|
13
|
+
File.join(Rails.root, 'config', 'hominid.yml')
|
14
|
+
)
|
15
|
+
puts 'Please edit config/hominid.yml to your needs.'
|
16
|
+
else
|
17
|
+
puts 'We left your existing config/hominid.yml untouched.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,43 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hominid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Getting
|
8
|
+
- "Michael Str\xC3\xBCder"
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-10-
|
13
|
+
date: 2009-10-30 00:00:00 -07:00
|
13
14
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: shoulda
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
description: Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.
|
17
27
|
email: brian@terra-firma-design.com
|
18
28
|
executables: []
|
19
29
|
|
20
30
|
extensions: []
|
21
31
|
|
22
32
|
extra_rdoc_files:
|
33
|
+
- LICENSE
|
23
34
|
- README.textile
|
24
35
|
files:
|
25
|
-
-
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
26
38
|
- README.textile
|
27
39
|
- Rakefile
|
28
|
-
- VERSION
|
40
|
+
- VERSION
|
29
41
|
- hominid.gemspec
|
30
42
|
- hominid.yml.tpl
|
31
|
-
- init.rb
|
32
|
-
- install.rb
|
33
43
|
- lib/hominid.rb
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
44
|
+
- lib/hominid/base.rb
|
45
|
+
- lib/hominid/campaign.rb
|
46
|
+
- lib/hominid/helper.rb
|
47
|
+
- lib/hominid/list.rb
|
48
|
+
- lib/hominid/webhook.rb
|
49
|
+
- tasks/rails/hominid.rake
|
50
|
+
- test/hominid_test.rb
|
51
|
+
- test/test_helper.rb
|
39
52
|
has_rdoc: true
|
40
|
-
homepage: http://
|
53
|
+
homepage: http://github.com/bgetting/hominid
|
41
54
|
licenses: []
|
42
55
|
|
43
56
|
post_install_message:
|
@@ -65,5 +78,5 @@ signing_key:
|
|
65
78
|
specification_version: 3
|
66
79
|
summary: Hominid is a Ruby gem for interacting with the Mailchimp API.
|
67
80
|
test_files:
|
68
|
-
-
|
69
|
-
-
|
81
|
+
- test/hominid_test.rb
|
82
|
+
- test/test_helper.rb
|
data/VERSION.yml
DELETED
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/rails/init"
|
data/install.rb
DELETED
data/pkg/hominid-1.2.1.gem
DELETED
Binary file
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'hominid'
|
data/spec/hominid_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
describe Hominid do
|
4
|
-
before do
|
5
|
-
api_key = ENV['MAIL_CHIMP_API_KEY']
|
6
|
-
raise "You must set the MAIL_CHIMP_API_KEY environment variable to test" if api_key.empty?
|
7
|
-
@hominid = Hominid.new(:api_key => api_key)
|
8
|
-
@list_id = ENV['MAIL_CHIMP_TEST_LIST_ID']
|
9
|
-
raise "You must set the MAIL_CHIMP_TEST_LIST_ID environment variable to test" if @list_id.empty?
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#subscribe" do
|
13
|
-
context "when not supplying a double-opt-in argument" do
|
14
|
-
it "should not blow up" do
|
15
|
-
proc {
|
16
|
-
@hominid.subscribe(@list_id, Faker::Internet.email)
|
17
|
-
}.should_not raise_error
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#call" do
|
23
|
-
it "should raise HominidError on failure" do
|
24
|
-
proc {
|
25
|
-
Hominid.new.send(:call, 'bogusApi')
|
26
|
-
}.should raise_error(HominidError)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/uninstall.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Uninstall hook code here
|