aweber 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ GEM
23
23
  yard (0.6.4)
24
24
 
25
25
  PLATFORMS
26
+ java
26
27
  ruby
27
28
 
28
29
  DEPENDENCIES
data/LICENSE CHANGED
@@ -1,20 +1,25 @@
1
- Copyright (c) 2010 AWeber Communications, Inc.
1
+ Copyright (c) 2010-2011, AWeber Communications, Inc.
2
+ All rights reserved.
2
3
 
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:
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of AWeber Communications, Inc. nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
10
14
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL AWEBER COMMUNICATIONS, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13
25
 
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.
@@ -109,4 +109,4 @@ h2. Note on Patches/Pull Requests
109
109
 
110
110
  h2. Copyright
111
111
 
112
- Copyright (c) 2010 AWeber Communications, Inc. See LICENSE for more detail.
112
+ Copyright (c) 2010-2011 AWeber Communications, Inc. See LICENSE for more detail.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "aweber"
4
- s.version = "1.2.0"
4
+ s.version = "1.3.0"
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.summary = "Ruby interface to AWeber's API"
7
7
  s.description = "Ruby interface to AWeber's API"
@@ -13,6 +13,7 @@ module AWeber
13
13
  :clicks => :Click,
14
14
  :links => :Link,
15
15
  :lists => :List,
16
+ :custom_fields => :CustomField,
16
17
  :campaigns => :Campaign,
17
18
  :messages => :Message,
18
19
  :opens => :Open,
@@ -20,7 +20,7 @@ module AWeber
20
20
  end
21
21
 
22
22
  def post(uri, body={})
23
- oauth.post(uri, body)
23
+ oauth.post(expand(uri), body)
24
24
  end
25
25
 
26
26
  def put(uri, body={})
@@ -58,6 +58,19 @@ module AWeber
58
58
 
59
59
  self.class.new(client, @klass, response)
60
60
  end
61
+
62
+ def create(attrs={})
63
+ params = attrs.merge("ws.op" => "create")
64
+ response = client.post(path, params)
65
+
66
+ return false unless response.is_a? Net::HTTPCreated
67
+
68
+ response = JSON.parse(response.body)
69
+ resource = get(response["location"]).merge(:parent => self)
70
+ resource = @klass.new(client, resource)
71
+
72
+ self[resource.id] = resource
73
+ end
61
74
 
62
75
  def [](id)
63
76
  @entries[id] ||= fetch_entry(id)
@@ -137,7 +137,7 @@ module AWeber
137
137
  end
138
138
 
139
139
  def inspect
140
- %(#<AWeber::Resources::#{self.class} id="#{id}" />)
140
+ %(#<#{self.class} id="#{id}" />)
141
141
  end
142
142
 
143
143
  private
@@ -4,6 +4,7 @@ require "aweber/resources/click"
4
4
  require "aweber/resources/followup"
5
5
  require "aweber/resources/link"
6
6
  require "aweber/resources/list"
7
+ require "aweber/resources/custom_field"
7
8
  require "aweber/resources/campaign"
8
9
  require "aweber/resources/message"
9
10
  require "aweber/resources/open"
@@ -12,8 +12,10 @@ module AWeber
12
12
  api_attr :subscribers_collection_link
13
13
  api_attr :web_forms_collection_link
14
14
  api_attr :web_form_split_tests_collection_link
15
+ api_attr :custom_fields_collection_link
15
16
 
16
17
  has_many :campaigns
18
+ has_many :custom_fields
17
19
  has_many :subscribers
18
20
  has_many :web_forms
19
21
  has_many :web_form_split_tests
@@ -1,10 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe AWeber::Collection do
4
- before :each do
4
+ before do
5
5
  @oauth = AWeber::OAuth.new("token", "secret")
6
6
  @aweber = AWeber::Base.new(@oauth)
7
- data = JSON.parse(fixture("lists.json"))
7
+ data = JSON.parse(fixture("lists.json")).merge(:parent => @aweber.account)
8
8
  @lists = AWeber::Collection.new(@aweber, AWeber::Resources::List, data)
9
9
  end
10
10
 
@@ -38,7 +38,7 @@ describe AWeber::Collection do
38
38
  end
39
39
 
40
40
  it "should have a path to its collection alone" do
41
- @lists.path.should == "/lists"
41
+ @lists.path.should == "/accounts/1/lists"
42
42
  end
43
43
 
44
44
  it "should create resource with itself as a parent" do
@@ -76,4 +76,26 @@ describe AWeber::Collection do
76
76
  @collection.search(:name => "default123456").parent.should be @collection.parent
77
77
  end
78
78
  end
79
+
80
+ describe "when creating" do
81
+ let(:params) {{ "ws.op" => "create", :name => "foo" }}
82
+
83
+ it "should set the operation to 'create'" do
84
+ @aweber.should_receive(:post).with(@lists.path, params)
85
+ @lists.create(:name => "foo")
86
+ end
87
+
88
+ it "should return false if the create failed" do
89
+ @oauth.should_receive(:post).and_return(nil)
90
+ @lists.create(:name => "foo").should == false
91
+ end
92
+
93
+ it "should return the new object if the create succeeded" do
94
+ @lists.create(:name => "foo").should be_an AWeber::Resource
95
+ end
96
+
97
+ it "should have the collection as a parent" do
98
+ @lists.create(:name => "foo").parent.should == @lists
99
+ end
100
+ end
79
101
  end
@@ -0,0 +1,8 @@
1
+ {
2
+ "http_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
3
+ "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1/custom_fields/1",
4
+ "resource_type_link": "https://api.aweber.com/1.0/#custom_field",
5
+ "id": 1,
6
+ "name": "Signature",
7
+ "is_subscriber_updateable": "false"
8
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "total_size": 2,
3
+ "start": 0,
4
+ "resource_type_link": "https://api.aweber.com/1.0/#custom_fields",
5
+ "entries": [
6
+ {
7
+ "http_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
8
+ "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1/custom_fields/1",
9
+ "resource_type_link": "https://api.aweber.com/1.0/#custom_field",
10
+ "id": 1,
11
+ "name": "Signature",
12
+ "is_subscriber_updateable": "false"
13
+ },
14
+ {
15
+ "http_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
16
+ "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1/custom_fields/2",
17
+ "resource_type_link": "https://api.aweber.com/1.0/#custom_field",
18
+ "id": 2,
19
+ "name": "logourl",
20
+ "is_subscriber_updateable": "false"
21
+ }
22
+ ]
23
+ }
@@ -7,5 +7,6 @@
7
7
  "http_etag": "\"0aaa38a50287df08ccb74c7f13fca8679aab688a-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
8
8
  "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679",
9
9
  "resource_type_link": "https://api.aweber.com/1.0/#list",
10
- "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/web_forms"
10
+ "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/web_forms",
11
+ "custom_fields_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/custom_fields"
11
12
  }
@@ -11,7 +11,8 @@
11
11
  "http_etag": "\"4ab41e60d14ea138a4522b3d2896942b7335c13c - ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
12
12
  "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1553018",
13
13
  "resource_type_link": "https://api.aweber.com/1.0/#list",
14
- "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1553018/web_forms"
14
+ "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1553018/web_forms",
15
+ "custom_fields_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1553018/custom_fields"
15
16
  },
16
17
  {
17
18
  "campaigns_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550685/campaigns",
@@ -22,7 +23,8 @@
22
23
  "http_etag": "\"685c00e3983add5e4efb5ca3bc7294e247f6e9fe - ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
23
24
  "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1550685",
24
25
  "resource_type_link": "https://api.aweber.com/1.0/#list",
25
- "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550685/web_forms"
26
+ "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550685/web_forms",
27
+ "custom_fields_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550685/custom_fields"
26
28
  },
27
29
  {
28
30
  "campaigns_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/campaigns",
@@ -33,6 +35,7 @@
33
35
  "http_etag": "\"0aaa38a50287df08ccb74c7f13fca8679aab688a - ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
34
36
  "self_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679",
35
37
  "resource_type_link": "https://api.aweber.com/1.0/#list",
36
- "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/web_forms"
38
+ "web_forms_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/web_forms",
39
+ "custom_fields_collection_link": "https://api.aweber.com/1.0/accounts/1/lists/1550679/custom_fields"
37
40
  }]
38
41
  }
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::CustomField do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].custom_fields[1] }
6
+
7
+ its(:path) { should == "/accounts/1/lists/1/custom_fields/1" }
8
+
9
+ it { should respond_to :name }
10
+ it { should respond_to :is_subscriber_updateable }
11
+ it { should respond_to :is_subscriber_updateable? }
12
+ end
@@ -11,8 +11,8 @@ def aweber_url(url)
11
11
  url =~ /https/ ? url : File.join(AWeber.api_endpoint, "1.0", url)
12
12
  end
13
13
 
14
- def route(method, uri, response)
15
- FakeWeb.register_uri(method, uri, :body => response)
14
+ def route(method, uri, body="", opts={})
15
+ FakeWeb.register_uri(method, uri, opts.merge(:body => body))
16
16
  end
17
17
 
18
18
  def fixture(filename)
@@ -40,6 +40,9 @@ route :any, "https://auth.aweber.com/1.0/access_token", "oauth_token=fake&oauth
40
40
 
41
41
  route :get, %r[/accounts\?], fixture("accounts.json")
42
42
  route :get, %r[/accounts/\d+/lists\?], fixture("lists.json")
43
+ route :get, %r[/accounts/\d+/lists/\d+\?], fixture("list.json")
44
+ route :get, %r[/accounts/\d+/lists/\d+/custom_fields\?], fixture("custom_fields.json")
45
+ route :get, %r[/accounts/\d+/lists/\d+/custom_fields/\d+\?], fixture("custom_field.json")
43
46
  route :get, %r[/accounts/\d+/lists/\d+/subscribers\?], fixture("subscribers.json")
44
47
  route :get, %r[/accounts/\d+/lists/\d+/web_forms\?], fixture("web_forms.json")
45
48
  route :get, %r[/accounts/\d+/lists/\d+/web_form_split_tests\?], fixture("web_form_split_tests.json")
@@ -52,4 +55,5 @@ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages\?], fixture("m
52
55
  route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/opens\?], fixture("opens.json")
53
56
  route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/tracked_events\?], fixture("tracked_events.json")
54
57
 
55
- route :post, %r[/accounts/\d+/lists/\d+/subscribers/\d+], "201 Created"
58
+ route :post, %r[/accounts/\d+/lists\?], %[{"location":"https://api.aweber.com/1.0/accounts/1/lists/1550679"}], :status => ["201", "Created"]
59
+ route :post, %r[/accounts/\d+/lists/\d+/subscribers/\d+], "201 Created", :status => ["201", "Created"]
@@ -0,0 +1,46 @@
1
+ module SpecRouting
2
+ def self.included(base)
3
+ SpecRouting.setup_fixtures
4
+ end
5
+
6
+ class << self
7
+ def get(uri, &block)
8
+ FakeWeb.register_uri(:get, uri, :body => block.call)
9
+ end
10
+
11
+ def any(uri, &block)
12
+ FakeWeb.register_uri(:any, uri, :body => block.call)
13
+ end
14
+
15
+ def resource(name)
16
+ fixture(name, "resources")
17
+ end
18
+
19
+ def fixture(name, subdir="")
20
+ fixtures = Pathname.new(File.dirname(__FILE__) + "/fixtures/#{subdir}")
21
+ fixtures += "#{name}.json"
22
+ fixtures.read.gsub(/[\s\n]/, '')
23
+ end
24
+
25
+ def setup_fixtures
26
+ any("https://auth.aweber.com/1.0/request_token") { "oauth_token=fake&oauth_token_secret=fake" }
27
+ any("https://auth.aweber.com/1.0/access_token") { "oauth_token=fake&oauth_token_secret=fake" }
28
+
29
+ get(%r[/cars]) { fixture(:cars) }
30
+
31
+ get(%r[/accounts\?]) { resource(:accounts) }
32
+ get(%r[/accounts/\d+/integrations\?]) { resource(:integrations) }
33
+ get(%r[/accounts/\d+/lists\?]) { resource(:lists) }
34
+ get(%r[/accounts/\d+/lists/\d+/subscribers\?]) { resource(:subscribers) }
35
+ get(%r[/accounts/\d+/lists/\d+/web_forms\?]) { resource(:web_forms) }
36
+ get(%r[/accounts/\d+/lists/\d+/web_form_split_tests\?]) { resource(:web_form_split_tests) }
37
+ get(%r[/accounts/\d+/lists/\d+/web_form_split_tests/\d+/components\?]) { resource(:web_form_split_test_components) }
38
+ get(%r[/accounts/\d+/lists/\d+/campaigns\?]) { resource(:campaigns) }
39
+ get(%r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/links\?]) { resource(:links) }
40
+ get(%r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/links/\d+/clicks\?]) { resource(:clicks) }
41
+ get(%r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages\?]) { resource(:messages) }
42
+ get(%r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/opens\?]) { resource(:opens) }
43
+ get(%r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/tracked_events\?]) { resource(:tracked_events) }
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - AWeber Communications, Inc.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-16 00:00:00 -04:00
17
+ date: 2011-04-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -132,6 +132,8 @@ files:
132
132
  - spec/fixtures/campaigns.json
133
133
  - spec/fixtures/click.json
134
134
  - spec/fixtures/clicks.json
135
+ - spec/fixtures/custom_field.json
136
+ - spec/fixtures/custom_fields.json
135
137
  - spec/fixtures/integration.json
136
138
  - spec/fixtures/integrations.json
137
139
  - spec/fixtures/link.json
@@ -157,6 +159,7 @@ files:
157
159
  - spec/resources/account_spec.rb
158
160
  - spec/resources/campaign_spec.rb
159
161
  - spec/resources/click_spec.rb
162
+ - spec/resources/custom_field_spec.rb
160
163
  - spec/resources/integration_spec.rb
161
164
  - spec/resources/link_spec.rb
162
165
  - spec/resources/list_spec.rb
@@ -169,6 +172,7 @@ files:
169
172
  - spec/resources/web_form_split_test_spec.rb
170
173
  - spec/spec_helper.rb
171
174
  - spec/support/fake_classes.rb
175
+ - spec/support/spec_routing.rb
172
176
  has_rdoc: true
173
177
  homepage: http://github.com/aweber/AWeber-API-Ruby-Library
174
178
  licenses: []
@@ -210,6 +214,8 @@ test_files:
210
214
  - spec/fixtures/campaigns.json
211
215
  - spec/fixtures/click.json
212
216
  - spec/fixtures/clicks.json
217
+ - spec/fixtures/custom_field.json
218
+ - spec/fixtures/custom_fields.json
213
219
  - spec/fixtures/integration.json
214
220
  - spec/fixtures/integrations.json
215
221
  - spec/fixtures/link.json
@@ -235,6 +241,7 @@ test_files:
235
241
  - spec/resources/account_spec.rb
236
242
  - spec/resources/campaign_spec.rb
237
243
  - spec/resources/click_spec.rb
244
+ - spec/resources/custom_field_spec.rb
238
245
  - spec/resources/integration_spec.rb
239
246
  - spec/resources/link_spec.rb
240
247
  - spec/resources/list_spec.rb
@@ -247,3 +254,4 @@ test_files:
247
254
  - spec/resources/web_form_split_test_spec.rb
248
255
  - spec/spec_helper.rb
249
256
  - spec/support/fake_classes.rb
257
+ - spec/support/spec_routing.rb