getresponse 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -104,4 +104,35 @@ Get campaign domain
104
104
  Set campaign domain
105
105
 
106
106
  domain = account.domains.first
107
- campaign.domain = domain
107
+ campaign.domain = domain
108
+
109
+ Get campaign messages
110
+
111
+ # with campaign
112
+ # campaign - existing campaign
113
+ messages = campaign.messages
114
+ newsletters = campaign.messages(:type => "newsletter")
115
+
116
+ Get message contents
117
+
118
+ # with message
119
+ # message - existing messsage
120
+ message.contents["plain"]
121
+ message.contents["html"]
122
+
123
+ Get stats of message
124
+
125
+ # message - existing message
126
+ message.stats
127
+
128
+ Delete message
129
+
130
+ # message - existing message
131
+ message.destroy
132
+
133
+ Get/set campaign's postal address
134
+
135
+ # campaign_one - existing campaign
136
+ # campaign_two - existing campaign
137
+ postal_address = campaign_one.postal_address
138
+ campaign_two.postal_address = postal_address
data/lib/api.rb ADDED
@@ -0,0 +1 @@
1
+ API_KEY='d333e12e5019b6940127e82b499d75a5'
data/lib/get_response.rb CHANGED
@@ -53,4 +53,7 @@ GetResponse.autoload :ContactProxy, "get_response/contact_proxy"
53
53
  GetResponse.autoload :FromField, "get_response/from_field"
54
54
  GetResponse.autoload :FromFieldsProxy, "get_response/from_fields_proxy"
55
55
  GetResponse.autoload :Domain, "get_response/domain"
56
- GetResponse.autoload :DomainProxy, "get_response/domain_proxy"
56
+ GetResponse.autoload :DomainProxy, "get_response/domain_proxy"
57
+ GetResponse.autoload :MessageProxy, "get_response/message_proxy"
58
+ GetResponse.autoload :Newsletter, "get_response/newsletter"
59
+ GetResponse.autoload :FollowUp, "get_response/follow_up"
@@ -49,6 +49,41 @@ module GetResponse
49
49
  new_domain
50
50
  end
51
51
 
52
+
53
+ # Get messages assigned to this campaign. Optionally conditions <tt>Hash</tt> can be passed, for
54
+ # example to get campaign messages which are newsletters only.
55
+ # Example:
56
+ # @campaign.messages
57
+ # @campaign.messages(:type => "newsletter")
58
+ #
59
+ # returns:: [GetResponse::Message]
60
+ def messages(conditions = {})
61
+ conditions[:campaigns]= [@id]
62
+ @message_proxy = MessageProxy.new @connection
63
+ @message_proxy.all(conditions)
64
+ end
65
+
66
+
67
+ # Get campaign's postal address and and postal design (formatting). Postal address is returned
68
+ # as <tt>Hash</tt> instance.
69
+ #
70
+ # returns:: Hash
71
+ def postal_address
72
+ @connection.send_request("get_campaign_postal_address", "campaign" => @id)["result"]
73
+ end
74
+
75
+
76
+ # Set postal address and postal design (formatting) in campaign. If something goes wrong
77
+ # exception <tt>GetResponse::GetResponseError</tt>.
78
+ #
79
+ # postal_address_hash:: Hash
80
+ # returns:: Hash
81
+ def postal_address=(postal_address_hash)
82
+ params = {"campaign" => @id}.merge(postal_address_hash)
83
+ result = @connection.send_request("set_campaign_postal_address", params)["result"]
84
+ result if result["updated"].to_i == 1
85
+ end
86
+
52
87
  end
53
88
 
54
89
  end
@@ -0,0 +1,27 @@
1
+ module GetResponse
2
+
3
+ class FollowUp < Message
4
+
5
+ attr_reader :day_of_cycle
6
+
7
+ # Delete follow up message.
8
+ def destroy
9
+ response = @connection.send_request("delete_follow_up", :message => @id)["result"]
10
+ response["deleted"].to_i == 1
11
+ end
12
+
13
+
14
+ # Method sets a day of cycle for follow-up. Passed value must be integer number. There can't be
15
+ # more than one follow-up for day.
16
+ #
17
+ # value:: Fixnum
18
+ def day_of_cycle=(value)
19
+ params = {:message => @id, :day_of_cycle => value}
20
+ response = @connection.send_request("set_follow_up_cycle", params)["result"]
21
+ @day_of_cycle = value.to_i if response["updated"].to_i == 1
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
@@ -2,15 +2,36 @@ module GetResponse
2
2
 
3
3
  # Class representa a message in GetResponse
4
4
  class Message
5
- attr_reader :id, :type, :subject, :day_of_cycle, :flags, :created_on
5
+ attr_reader :id, :type, :subject, :flags, :created_on
6
6
 
7
- def initialize(params)
7
+ def initialize(params, connection)
8
8
  @id = params["id"]
9
9
  @type = params["type"]
10
10
  @subject = params["subject"]
11
11
  @day_of_cycle = params["day_of_cycle"]
12
12
  @flags = params["flags"] || []
13
13
  @created_on = params["created_on"]
14
+ @connection = connection
15
+ end
16
+
17
+
18
+ # Content of message. Every message has two kinds of content: plain and html. Method returns
19
+ # <tt>Hash</tt> instance with keys <tt>"plain"</tt> and <tt>"html"</tt>.
20
+ #
21
+ # returns:: Hash
22
+ def contents
23
+ resp = @connection.send_request("get_message_contents", :message => @id)
24
+ resp["result"]
25
+ end
26
+
27
+
28
+ # Stats of message. Method returns <tt>Hash</tt> instance where hey is a date and value is
29
+ # set of data.
30
+ #
31
+ # returns:: Hash
32
+ def stats
33
+ resp = @connection.send_request("get_message_stats", :message => @id)
34
+ resp["result"]
14
35
  end
15
36
  end
16
37
  end
@@ -0,0 +1,45 @@
1
+ module GetResponse
2
+
3
+ # Proxy class for message related operations.
4
+ class MessageProxy
5
+
6
+ def initialize(connection)
7
+ @connection = connection
8
+ end
9
+
10
+
11
+ # Get all messages from account. <tt>Hash</tt> with conditions can be optionally passed as
12
+ # parameter.
13
+ # Example:
14
+ # @message_proxy.all
15
+ # => [<GetResponse::Message ...>, <GetResponse::Message ...>]
16
+ # @message_proxy.all(:campaigns => ["my_campaign_id"]
17
+ # => [<GetResponse::Message ...>, <GetResponse::Message ...>]
18
+ #
19
+ # conditions:: Hash, empty by default
20
+ # returns:: Array of GetResponse::Message
21
+ def all(conditions = {})
22
+ response = @connection.send_request("get_messages", conditions)
23
+
24
+ response["result"].inject([]) do |messages, resp|
25
+ messages << message_ancestor_object(resp)
26
+ # messages << Message.new(resp[1].merge("id" => resp[0]), @connection)
27
+ end
28
+ end
29
+
30
+
31
+ protected
32
+
33
+
34
+ def message_ancestor_object(response)
35
+ case response[1]["type"]
36
+ when "newsletter"
37
+ Newsletter.new(response[1].merge("id" => response[0]), @connection)
38
+ when "follow-up"
39
+ FollowUp.new(response[1].merge("id" => response[0]), @connection)
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,15 @@
1
+ module GetResponse
2
+
3
+ class Newsletter < Message
4
+
5
+ # Delete newsletter. You can delete only newsletters that have send_on date in future. If you try
6
+ # to delete exception will be raised.
7
+ def destroy
8
+ resp = @connection.send_request("delete_newsletter", :message => @id)["result"]
9
+ resp["deleted"].to_i == 1
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
metadata CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
7
+ - 4
8
+ version: "0.4"
10
9
  platform: ruby
11
10
  authors:
12
11
  - Sebastian Nowak
@@ -14,7 +13,7 @@ autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
15
 
17
- date: 2011-03-06 00:00:00 +01:00
16
+ date: 2011-06-12 00:00:00 +02:00
18
17
  default_executable:
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
@@ -69,15 +68,19 @@ files:
69
68
  - lib/get_response/from_field.rb
70
69
  - lib/get_response/domain_proxy.rb
71
70
  - lib/get_response/contact_proxy.rb
71
+ - lib/get_response/message_proxy.rb
72
+ - lib/get_response/newsletter.rb
72
73
  - lib/get_response/account.rb
73
74
  - lib/get_response/contact.rb
74
75
  - lib/get_response/campaign_proxy.rb
75
76
  - lib/get_response/campaign.rb
76
77
  - lib/get_response/message.rb
77
78
  - lib/get_response/connection.rb
79
+ - lib/get_response/follow_up.rb
78
80
  - lib/get_response/from_fields_proxy.rb
79
81
  - lib/get_response/domain.rb
80
82
  - lib/get_response/get_response_error.rb
83
+ - lib/api.rb
81
84
  - README.rdoc
82
85
  has_rdoc: true
83
86
  homepage: http://dev.getresponse.com