getresponse 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -39
- data/lib/get_response.rb +3 -1
- data/lib/get_response/account.rb +1 -1
- data/lib/get_response/campaign.rb +12 -1
- data/lib/get_response/campaign_proxy.rb +23 -0
- data/lib/get_response/connection.rb +11 -69
- data/lib/get_response/contact.rb +7 -33
- data/lib/get_response/contact_proxy.rb +38 -0
- metadata +20 -8
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
== GetResponse
|
2
2
|
|
3
|
-
Wrapper for GetResponse API
|
3
|
+
Wrapper for GetResponse API.
|
4
|
+
Class interfaces from version 0.2 has changed breaking backward compatibility.
|
5
|
+
Be sure to check changes before update.
|
4
6
|
|
5
7
|
== Usage
|
6
8
|
|
@@ -9,42 +11,25 @@ Test connection to GetResponse API.
|
|
9
11
|
gr_connection = GetResponse::Connection.new("my_secret_api")
|
10
12
|
gr_connection.ping
|
11
13
|
|
12
|
-
Get info about account
|
14
|
+
Get info about account:
|
13
15
|
|
14
|
-
gr_connection.
|
16
|
+
gr_connection.account
|
15
17
|
|
16
|
-
Get
|
18
|
+
Get your active campaigns.
|
17
19
|
|
18
|
-
|
19
|
-
gr_connection.get_campaings(:name.is_eq => "My campaing name")
|
20
|
-
|
21
|
-
# get campaings with other name than "My campaing name"
|
22
|
-
gr_connection.get_campaings(:name.is_not_eq => "My campaing name")
|
23
|
-
|
24
|
-
# get campaings with name like "signup" and with from_email with domain "mybiz.xx"
|
25
|
-
gr_connection.get_campaigns(:name.contain => "%signup%", :from_email.contain => "%mybiz.xx"
|
26
|
-
|
27
|
-
Get single campaign
|
28
|
-
|
29
|
-
gr_connection.get_campaign(123456)
|
30
|
-
=> <#GetResponse::Campaign ... >
|
31
|
-
|
32
|
-
gr_connection.get_campaign(bad_id)
|
33
|
-
=> nil
|
20
|
+
gr_connection.campaigns.all
|
34
21
|
|
35
22
|
You can operate on your contacts quite the same way as on ActiveRecord objects. Before any operation
|
36
23
|
on contacts you must connect to API.
|
37
24
|
|
38
25
|
Get all contacts:
|
39
26
|
|
40
|
-
|
41
|
-
GetResponse::Connection.instance("my_secret_api_key")
|
42
|
-
GetResponse::Contact.find_all
|
27
|
+
gr_connection.contacts.all
|
43
28
|
|
44
29
|
Create new contact:
|
45
30
|
|
46
31
|
# with connection
|
47
|
-
|
32
|
+
gr_connection.contacts.create("name" => "John Doe", "email" => "john.d@somewhere.com",
|
48
33
|
"campaign" => "campaignId", "customs" => { "source" => "mainpage" })
|
49
34
|
|
50
35
|
Update your contact:
|
@@ -53,6 +38,10 @@ Update your contact:
|
|
53
38
|
# contact - existing contact
|
54
39
|
contact.update("name" => "John Thenewname")
|
55
40
|
|
41
|
+
# or
|
42
|
+
contact.name = "John Thenewname"
|
43
|
+
contact.save
|
44
|
+
|
56
45
|
Delete contact:
|
57
46
|
|
58
47
|
# with connection
|
@@ -77,18 +66,4 @@ Set contact cycle
|
|
77
66
|
|
78
67
|
# with connection
|
79
68
|
# contact - existing contact
|
80
|
-
contact.set_cycle(5)
|
81
|
-
|
82
|
-
Get messages in account:
|
83
|
-
|
84
|
-
# get messages assigned to campaign with "N3i" ID
|
85
|
-
gr_connection.get_messages(:campaigns => ["N3i"])
|
86
|
-
|
87
|
-
# get messages with newsletter type
|
88
|
-
gr_connection.get_messages(:type => "newsletter")
|
89
|
-
|
90
|
-
# get messages from from campaigns with name like "my_biz"
|
91
|
-
gr_connection.get_messages(:get_campaigns => { :name.contain => "%my_biz%" })
|
92
|
-
|
93
|
-
# get one messages identifier by <tt>id</tt>
|
94
|
-
gr_connection.get_message("some_id")
|
69
|
+
contact.set_cycle(5)
|
data/lib/get_response.rb
CHANGED
@@ -47,4 +47,6 @@ GetResponse.autoload :Account, "get_response/account"
|
|
47
47
|
GetResponse.autoload :Campaign, "get_response/campaign"
|
48
48
|
GetResponse.autoload :Connection, "get_response/connection"
|
49
49
|
GetResponse.autoload :Contact, "get_response/contact"
|
50
|
-
GetResponse.autoload :Message, "get_response/message"
|
50
|
+
GetResponse.autoload :Message, "get_response/message"
|
51
|
+
GetResponse.autoload :CampaignProxy, "get_response/campaign_proxy"
|
52
|
+
GetResponse.autoload :ContactProxy, "get_response/contact_proxy"
|
data/lib/get_response/account.rb
CHANGED
@@ -5,14 +5,25 @@ module GetResponse
|
|
5
5
|
attr_reader :id, :name, :from_name, :from_email, :reply_to_email, :created_on
|
6
6
|
|
7
7
|
|
8
|
-
def initialize(params)
|
8
|
+
def initialize(params, connection)
|
9
9
|
@id = params["id"]
|
10
10
|
@name = params["name"]
|
11
11
|
@from_name = params["from_name"]
|
12
12
|
@from_email = params["from_email"]
|
13
13
|
@reply_to_email = params["reply_to_email"]
|
14
14
|
@created_on = params["created_on"]
|
15
|
+
@connection = connection
|
15
16
|
end
|
17
|
+
|
18
|
+
|
19
|
+
# Get all contacts assigned to this campaign.
|
20
|
+
#
|
21
|
+
# returns:: [GetResponse::Contact]
|
22
|
+
def contacts
|
23
|
+
@contact_proxy = ContactProxy.new(@connection)
|
24
|
+
@contact_proxy.all(:campaigns => [@id])
|
25
|
+
end
|
26
|
+
|
16
27
|
end
|
17
28
|
|
18
29
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GetResponse
|
2
|
+
|
3
|
+
# Proxy class for campaign operations.
|
4
|
+
class CampaignProxy
|
5
|
+
|
6
|
+
def initialize(connection)
|
7
|
+
@connection = connection
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Get all campaigns from account.
|
12
|
+
#
|
13
|
+
# returns:: Array of GetResponse::Campaign
|
14
|
+
def all
|
15
|
+
response = @connection.send_request("get_campaigns", {})["result"]
|
16
|
+
response.inject([]) do |campaigns, resp|
|
17
|
+
campaigns << Campaign.new(resp[1].merge("id" => resp[0]), @connection)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -8,20 +8,11 @@ module GetResponse
|
|
8
8
|
|
9
9
|
attr_reader :api_key
|
10
10
|
|
11
|
-
|
12
|
-
private_class_method :new
|
13
|
-
|
14
|
-
|
15
11
|
def initialize(api_key)
|
16
12
|
@api_key = api_key
|
17
13
|
end
|
18
14
|
|
19
15
|
|
20
|
-
def self.instance(api_key = "")
|
21
|
-
@@instance ||= new(api_key)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
16
|
# Test connection with API.
|
26
17
|
#
|
27
18
|
# returns:: Boolean
|
@@ -31,78 +22,28 @@ module GetResponse
|
|
31
22
|
end
|
32
23
|
|
33
24
|
|
34
|
-
# Get basic info about your account
|
25
|
+
# Get basic info about your account.
|
35
26
|
#
|
36
27
|
# returns:: GetResponse::Account
|
37
|
-
def
|
28
|
+
def account
|
38
29
|
resp = self.send_request("get_account_info")
|
39
30
|
GetResponse::Account.new(resp["result"])
|
40
31
|
end
|
41
32
|
|
42
33
|
|
43
|
-
#
|
44
|
-
# More info about operators http://dev.getresponse.com/api-doc/#operators
|
45
|
-
#
|
46
|
-
# gr_connection.get_campaings
|
47
|
-
#
|
48
|
-
# Get list of all active campaigns with name "my_campaign" and from_email is from domain "mybiz.xx"
|
49
|
-
#
|
50
|
-
# gr_connection.get_campaings(:name.is_eq => "my_campaign", :from_email.contain => "%mybiz.xx")
|
51
|
-
#
|
52
|
-
# get_campaings(:name.eq => "my name")
|
53
|
-
def get_campaigns(conditions = {})
|
54
|
-
req_cond = build_conditions(conditions)
|
55
|
-
|
56
|
-
response = send_request("get_campaigns", req_cond)["result"]
|
57
|
-
response.inject([]) do |campaings, resp|
|
58
|
-
campaings << Campaign.new(resp[1].merge("id" => resp[0]))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# Get single campaign using <tt>campaign_id</tt>.
|
64
|
-
#
|
65
|
-
# campaign_id:: Integer || String
|
66
|
-
#
|
67
|
-
# returns:: GetResponse::Campaign || nil
|
68
|
-
def get_campaign(campaign_id)
|
69
|
-
result = self.get_campaigns(:id.is_eq => campaign_id)
|
70
|
-
result.first
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
# TODO: untested!
|
75
|
-
# Get messages in account.
|
76
|
-
# Conditions:
|
77
|
-
# * campaigns / get_campaigns (optional) – Search only in given campaigns. Uses OR logic.
|
78
|
-
# If those params are not given search, is performed in all campaigns in the account.
|
79
|
-
# Check IDs in conditions for detailed explanation.
|
80
|
-
# * type (optional) – Use newsletter or follow-up to narrow down search results to specific
|
81
|
-
# message types.
|
82
|
-
# * subject (optional) – Use text operators to narrow down search results to specific message subjects.
|
83
|
-
#
|
84
|
-
# conditions:: Hash
|
34
|
+
# Method returns proxy to execute all campaign related operations.
|
85
35
|
#
|
86
|
-
# returns::
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
response = send_request("get_messages", req_cond)["result"]
|
91
|
-
response.inject([]) do |messages, resp|
|
92
|
-
messages << Message.new(resp[1].merge("id" => resp[0]))
|
93
|
-
end
|
36
|
+
# returns:: GetResponse::CampaignProxy
|
37
|
+
def campaigns
|
38
|
+
@campaign_proxy ||= GetResponse::CampaignProxy.new(self)
|
94
39
|
end
|
95
40
|
|
96
41
|
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# message_id:: Integer || String
|
42
|
+
# Method returns proxy to execute all contact related operations.
|
100
43
|
#
|
101
|
-
# returns::
|
102
|
-
def
|
103
|
-
|
104
|
-
return nil if response.empty?
|
105
|
-
Message.new(response[message_id].merge("id" => message_id))
|
44
|
+
# returns:: GetResponse::ContactProxy
|
45
|
+
def contacts
|
46
|
+
@contact_proxy ||= GetResponse::ContactProxy.new(self)
|
106
47
|
end
|
107
48
|
|
108
49
|
|
@@ -121,6 +62,7 @@ module GetResponse
|
|
121
62
|
resp = Net::HTTP.start(uri.host, uri.port) do |conn|
|
122
63
|
conn.post("/", request_params)
|
123
64
|
end
|
65
|
+
raise GetResponseError.new("API key verification failed") if resp.code.to_i == 403
|
124
66
|
response = JSON.parse(resp.body)
|
125
67
|
if response["error"]
|
126
68
|
raise GetResponse::GetResponseError.new(response["error"])
|
data/lib/get_response/contact.rb
CHANGED
@@ -6,7 +6,7 @@ module GetResponse
|
|
6
6
|
attr_reader :id
|
7
7
|
|
8
8
|
|
9
|
-
def initialize(params)
|
9
|
+
def initialize(params, connection)
|
10
10
|
@campaign = params["campaign"]
|
11
11
|
@name = params["name"]
|
12
12
|
@email = params["email"]
|
@@ -14,31 +14,7 @@ module GetResponse
|
|
14
14
|
@ip = params["ip"]
|
15
15
|
@customs = parse_customs(params["customs"])
|
16
16
|
@id = params["id"]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# Add contact to the list. Method raises an exception <tt>GetResponseError</tt> if contact can't
|
21
|
-
# be added (bad email syntax for example).
|
22
|
-
# Example:
|
23
|
-
# GetResponse::Contact.create("email" => "john@doe.org", "name => "John D.", "campaign" => "N67")
|
24
|
-
#
|
25
|
-
# params:: Hash - attributes for new contact
|
26
|
-
# returns:: Boolean - true if contact queued for create
|
27
|
-
def self.create(params)
|
28
|
-
contact = Contact.new(params)
|
29
|
-
contact.save
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
# Find all contacts associated with GetResponse account
|
34
|
-
#
|
35
|
-
# returns:: [Contact]
|
36
|
-
def self.find_all
|
37
|
-
response = GetResponse::Connection.instance.send_request("get_contacts", {})
|
38
|
-
|
39
|
-
response["result"].inject([]) do |contacts, resp|
|
40
|
-
contacts << Contact.new(resp[1].merge("id" => resp[0]))
|
41
|
-
end
|
17
|
+
@connection = connection
|
42
18
|
end
|
43
19
|
|
44
20
|
|
@@ -47,9 +23,7 @@ module GetResponse
|
|
47
23
|
#
|
48
24
|
# returns:: Boolean
|
49
25
|
def save
|
50
|
-
|
51
|
-
|
52
|
-
result = connection.send_request(:add_contact, self.attributes)
|
26
|
+
result = @connection.send_request(:add_contact, self.attributes)
|
53
27
|
result["error"].nil?
|
54
28
|
end
|
55
29
|
|
@@ -80,7 +54,7 @@ module GetResponse
|
|
80
54
|
def destroy
|
81
55
|
raise GetResponse::GetResponseError.new("Can't delete contact without id") unless @id
|
82
56
|
|
83
|
-
resp =
|
57
|
+
resp = @connection.send_request("delete_contact", { "contact" => @id })
|
84
58
|
resp["result"]["deleted"].to_i == 1
|
85
59
|
end
|
86
60
|
|
@@ -104,7 +78,7 @@ module GetResponse
|
|
104
78
|
# returns:: Boolean
|
105
79
|
def move(new_campaign_id)
|
106
80
|
param = { "contact" => @id, "campaign" => new_campaign_id }
|
107
|
-
result =
|
81
|
+
result = @connection.send_request("move_contact", param)
|
108
82
|
result["result"]["updated"].to_i == 1
|
109
83
|
end
|
110
84
|
|
@@ -114,7 +88,7 @@ module GetResponse
|
|
114
88
|
# returns:: Hash
|
115
89
|
def geoip
|
116
90
|
param = { "contact" => @id }
|
117
|
-
|
91
|
+
@connection.send_request("get_contact_geoip", param)["result"]
|
118
92
|
end
|
119
93
|
|
120
94
|
|
@@ -125,7 +99,7 @@ module GetResponse
|
|
125
99
|
# returns:: true
|
126
100
|
def set_cycle(value)
|
127
101
|
param = { "contact" => @id, "cycle_day" => value }
|
128
|
-
|
102
|
+
@connection.send_request("set_contact_cycle", param)["result"]["updated"].to_i == 1
|
129
103
|
end
|
130
104
|
|
131
105
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GetResponse
|
2
|
+
|
3
|
+
# Proxy class for contact related operations.
|
4
|
+
class ContactProxy
|
5
|
+
|
6
|
+
def initialize(connection)
|
7
|
+
@connection = connection
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Get all contacts from account. Conditions could be passed to method. Returned contacts
|
12
|
+
# will be limited to passed conditions eg. to certain campaign. For more examples of conditions
|
13
|
+
# visit: http://dev.getresponse.com/api-doc/#get_contacts
|
14
|
+
# Example:
|
15
|
+
# @contact_proxy.all(:campaigns => ["my_campaign_id"])
|
16
|
+
#
|
17
|
+
# returns:: Array of GetResponse::Contact
|
18
|
+
def all(conditions = {})
|
19
|
+
response = @connection.send_request("get_contacts", conditions)
|
20
|
+
|
21
|
+
response["result"].inject([]) do |contacts, resp|
|
22
|
+
contacts << Contact.new(resp[1].merge("id" => resp[0]), @connection)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Create new contact. Method can raise <tt>GetResponseError</tt>.
|
28
|
+
#
|
29
|
+
# returns:: GetResponse::Contact
|
30
|
+
def create(attrs)
|
31
|
+
contact = GetResponse::Contact.new(attrs, @connection)
|
32
|
+
contact.save
|
33
|
+
contact
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getresponse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.1.1
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sebastian Nowak
|
@@ -14,16 +14,18 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-29 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ~>
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
27
29
|
segments:
|
28
30
|
- 1
|
29
31
|
- 4
|
@@ -34,9 +36,11 @@ dependencies:
|
|
34
36
|
name: json_pure
|
35
37
|
prerelease: false
|
36
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
37
40
|
requirements:
|
38
41
|
- - ~>
|
39
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
40
44
|
segments:
|
41
45
|
- 1
|
42
46
|
- 4
|
@@ -47,9 +51,11 @@ dependencies:
|
|
47
51
|
name: rr
|
48
52
|
prerelease: false
|
49
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
50
55
|
requirements:
|
51
56
|
- - ~>
|
52
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 15
|
53
59
|
segments:
|
54
60
|
- 1
|
55
61
|
- 0
|
@@ -65,13 +71,15 @@ extensions: []
|
|
65
71
|
extra_rdoc_files: []
|
66
72
|
|
67
73
|
files:
|
68
|
-
- lib/get_response.rb
|
69
74
|
- lib/get_response/account.rb
|
70
|
-
- lib/get_response/contact.rb
|
71
75
|
- lib/get_response/campaign.rb
|
72
|
-
- lib/get_response/
|
76
|
+
- lib/get_response/campaign_proxy.rb
|
73
77
|
- lib/get_response/connection.rb
|
78
|
+
- lib/get_response/contact.rb
|
79
|
+
- lib/get_response/contact_proxy.rb
|
74
80
|
- lib/get_response/get_response_error.rb
|
81
|
+
- lib/get_response/message.rb
|
82
|
+
- lib/get_response.rb
|
75
83
|
- README.rdoc
|
76
84
|
has_rdoc: true
|
77
85
|
homepage: http://dev.getresponse.com
|
@@ -83,16 +91,20 @@ rdoc_options: []
|
|
83
91
|
require_paths:
|
84
92
|
- lib
|
85
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
86
95
|
requirements:
|
87
96
|
- - ">="
|
88
97
|
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
89
99
|
segments:
|
90
100
|
- 0
|
91
101
|
version: "0"
|
92
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
93
104
|
requirements:
|
94
105
|
- - ">="
|
95
106
|
- !ruby/object:Gem::Version
|
107
|
+
hash: 17
|
96
108
|
segments:
|
97
109
|
- 1
|
98
110
|
- 3
|
@@ -101,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
113
|
requirements: []
|
102
114
|
|
103
115
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.7
|
105
117
|
signing_key:
|
106
118
|
specification_version: 3
|
107
119
|
summary: Ruby wrapper for GetResponse API
|