aweber 1.0.0

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.
Files changed (73) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +28 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +45 -0
  5. data/Rakefile +9 -0
  6. data/aweber.gemspec +55 -0
  7. data/examples/with_access_token.rb +17 -0
  8. data/examples/your_account.rb +26 -0
  9. data/lib/aweber.rb +67 -0
  10. data/lib/aweber/base.rb +49 -0
  11. data/lib/aweber/collection.rb +110 -0
  12. data/lib/aweber/oauth.rb +69 -0
  13. data/lib/aweber/resource.rb +93 -0
  14. data/lib/aweber/resources.rb +14 -0
  15. data/lib/aweber/resources/account.rb +14 -0
  16. data/lib/aweber/resources/broadcast.rb +29 -0
  17. data/lib/aweber/resources/click.rb +13 -0
  18. data/lib/aweber/resources/followup.rb +24 -0
  19. data/lib/aweber/resources/integration.rb +8 -0
  20. data/lib/aweber/resources/link.rb +12 -0
  21. data/lib/aweber/resources/list.rb +86 -0
  22. data/lib/aweber/resources/message.rb +20 -0
  23. data/lib/aweber/resources/open.rb +10 -0
  24. data/lib/aweber/resources/subscriber.rb +26 -0
  25. data/lib/aweber/resources/tracked_event.rb +13 -0
  26. data/lib/aweber/resources/web_form.rb +14 -0
  27. data/lib/aweber/resources/web_form_split_test.rb +11 -0
  28. data/lib/aweber/resources/web_form_split_test_component.rb +20 -0
  29. data/spec/base_spec.rb +23 -0
  30. data/spec/collection_spec.rb +40 -0
  31. data/spec/fixtures/account.json +8 -0
  32. data/spec/fixtures/accounts.json +13 -0
  33. data/spec/fixtures/campaign.json +23 -0
  34. data/spec/fixtures/campaigns.json +106 -0
  35. data/spec/fixtures/click.json +9 -0
  36. data/spec/fixtures/clicks.json +14 -0
  37. data/spec/fixtures/integration.json +8 -0
  38. data/spec/fixtures/integrations.json +45 -0
  39. data/spec/fixtures/link.json +10 -0
  40. data/spec/fixtures/links.json +75 -0
  41. data/spec/fixtures/list.json +11 -0
  42. data/spec/fixtures/lists.json +38 -0
  43. data/spec/fixtures/message.json +12 -0
  44. data/spec/fixtures/messages.json +29 -0
  45. data/spec/fixtures/open.json +8 -0
  46. data/spec/fixtures/opens.json +21 -0
  47. data/spec/fixtures/subscriber.json +16 -0
  48. data/spec/fixtures/subscribers.json +69 -0
  49. data/spec/fixtures/tracked_event.json +8 -0
  50. data/spec/fixtures/tracked_events.json +21 -0
  51. data/spec/fixtures/web_form.json +14 -0
  52. data/spec/fixtures/web_form_split_test.json +9 -0
  53. data/spec/fixtures/web_form_split_test_component.json +16 -0
  54. data/spec/fixtures/web_form_split_test_components.json +37 -0
  55. data/spec/fixtures/web_form_split_tests.json +41 -0
  56. data/spec/fixtures/web_forms.json +229 -0
  57. data/spec/oauth_spec.rb +96 -0
  58. data/spec/resource_spec.rb +61 -0
  59. data/spec/resources/account_spec.rb +13 -0
  60. data/spec/resources/campaign_spec.rb +14 -0
  61. data/spec/resources/click_spec.rb +14 -0
  62. data/spec/resources/integration_spec.rb +13 -0
  63. data/spec/resources/link_spec.rb +15 -0
  64. data/spec/resources/list_spec.rb +26 -0
  65. data/spec/resources/message_spec.rb +17 -0
  66. data/spec/resources/open_spec.rb +13 -0
  67. data/spec/resources/subscriber_spec.rb +25 -0
  68. data/spec/resources/tracked_event_spec.rb +14 -0
  69. data/spec/resources/web_form_spec.rb +19 -0
  70. data/spec/resources/web_form_split_test_component_spec.rb +20 -0
  71. data/spec/resources/web_form_split_test_spec.rb +14 -0
  72. data/spec/spec_helper.rb +52 -0
  73. metadata +247 -0
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AWeber::OAuth do
4
+
5
+ it "initialize with consumer token and secret" do
6
+ aweber = AWeber::OAuth.new('token', 'secret')
7
+ aweber.consumer.key.should == 'token'
8
+ aweber.consumer.secret.should == 'secret'
9
+ end
10
+
11
+ it "should create a consumer" do
12
+ OAuth::Consumer.should_receive(:new).with('token', 'secret', {
13
+ :site => AWeber.auth_endpoint,
14
+ :request_token_path => "/1.0/oauth/request_token",
15
+ :authorize_path => "/1.0/oauth/authorize",
16
+ :access_token_path => "/1.0/oauth/access_token",
17
+ :scheme => :query_string
18
+ })
19
+
20
+ AWeber::OAuth.new('token', 'secret').consumer
21
+ end
22
+
23
+ it "should set the request token path to /1.0/oauth/request_token" do
24
+ aweber = AWeber::OAuth.new('token', 'secret')
25
+ aweber.consumer.request_token_path.should == "/1.0/oauth/request_token"
26
+ end
27
+
28
+ it "should set the authorize path to /1.0/oauth/authorize" do
29
+ aweber = AWeber::OAuth.new('token', 'secret')
30
+ aweber.consumer.authorize_path.should == "/1.0/oauth/authorize"
31
+ end
32
+
33
+ it "should set the access token path to /1.0/oauth/access_token" do
34
+ aweber = AWeber::OAuth.new('token', 'secret')
35
+ aweber.consumer.access_token_path.should == "/1.0/oauth/access_token"
36
+ end
37
+
38
+ it "should get a request token from the consumer" do
39
+ consumer = double('oauth consumer')
40
+ rtoken = double('request token')
41
+ consumer.stub(:get_request_token) { rtoken }
42
+ OAuth::Consumer.stub(:new) { consumer }
43
+
44
+ aweber = AWeber::OAuth.new('token', 'secret')
45
+ aweber.request_token.should == rtoken
46
+ end
47
+
48
+ it "should set the callback url" do
49
+ oauth = AWeber::OAuth.new('token', 'secret', :callback_url => "http://example.com")
50
+ oauth.callback_url.should == "http://example.com"
51
+ end
52
+
53
+ it "should be able to authorize with a verifier code" do
54
+ consumer = double('oauth consumer')
55
+ rtoken = double('request token')
56
+ atoken = double('access token', :token => 'fake', :secret => 'fake')
57
+
58
+ consumer.stub(:get_request_token) { rtoken }
59
+ rtoken.stub(:get_access_token) { atoken }
60
+ OAuth::Consumer.stub(:new) { consumer }
61
+ OAuth::AccessToken.stub(:new) { atoken }
62
+
63
+ rtoken.should_receive(:get_access_token).with({ :oauth_verifier => 'fake' })
64
+ aweber = AWeber::OAuth.new('token', 'secret')
65
+ aweber.authorize_with_verifier('fake')
66
+ aweber.access_token.should == atoken
67
+ end
68
+
69
+ it "should able to create access tokens from access token key and secret" do
70
+ aweber = AWeber::OAuth.new('token', 'secret')
71
+ aweber.authorize_with_access('atoken', 'asecret')
72
+
73
+ aweber.access_token.should be_an OAuth::AccessToken
74
+ aweber.access_token.token.should == 'atoken'
75
+ aweber.access_token.secret.should == 'asecret'
76
+ end
77
+
78
+ it "should delegate get to access token" do
79
+ atoken = double('access token')
80
+ aweber = AWeber::OAuth.new('token', 'secret')
81
+ aweber.stub(:access_token) { atoken }
82
+
83
+ atoken.should_receive(:get).and_return(nil)
84
+ aweber.get("/foo")
85
+ end
86
+
87
+ it "should delegate post to access token" do
88
+ atoken = double('access token')
89
+ aweber = AWeber::OAuth.new('token', 'secret')
90
+ aweber.stub(:access_token) { atoken }
91
+
92
+ atoken.should_receive(:post).and_return(nil)
93
+ aweber.post("/foo")
94
+ end
95
+
96
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class FakeResource < AWeber::Resource
4
+ attr_accessor :foo
5
+ alias_attribute :bar, :foo
6
+ has_many :lists
7
+ end
8
+
9
+ describe AWeber::Resource do
10
+
11
+ before :each do
12
+ @oauth = AWeber::OAuth.new("token", "secret")
13
+ @aweber = AWeber::Base.new(@oauth)
14
+ end
15
+
16
+ it "should alias attributes" do
17
+ fake = FakeResource.new(@aweber)
18
+ fake.foo = "abc"
19
+ fake.bar.should == "abc"
20
+ end
21
+
22
+ it "should create collections" do
23
+ @aweber.stub(:expand) { "https://api.aweber.com/1.0/accounts/1/lists" }
24
+ fake = FakeResource.new(@aweber)
25
+ fake.lists.should be_an AWeber::Collection
26
+ end
27
+
28
+ it "should have the standard resource attributes" do
29
+ fake = FakeResource.new(@aweber)
30
+ fake.should respond_to :id
31
+ fake.should respond_to :http_etag
32
+ fake.should respond_to :self_link
33
+ fake.should respond_to :resource_type_link
34
+ end
35
+
36
+ it "should be creatable from data" do
37
+ fake = FakeResource.new @aweber, :id => 1, :http_etag => "a1b2c3",
38
+ :self_link => "foo", :resource_type_link => "bar"
39
+ fake.id.should == 1
40
+ fake.http_etag.should == "a1b2c3"
41
+ fake.self_link.should == "foo"
42
+ fake.resource_type_link.should == "bar"
43
+ end
44
+
45
+ it "should have simpler aliases for the standard attributes" do
46
+ fake = FakeResource.new @aweber, :id => 1, :http_etag => "a1b2c3",
47
+ :self_link => "foo", :resource_type_link => "bar"
48
+ fake.etag.should == "a1b2c3"
49
+ fake.link.should == "foo"
50
+ fake.resource_type.should == "bar"
51
+ end
52
+
53
+ it "should be comparable to other resources based on id" do
54
+ fake1 = FakeResource.new @aweber, :id => 1
55
+ fake2 = FakeResource.new @aweber, :id => 1
56
+ fake3 = FakeResource.new @aweber, :id => 2
57
+ fake1.should == fake2
58
+ fake1.should_not == fake3
59
+ end
60
+
61
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Account do
4
+ include BaseObjects
5
+ subject { aweber.account }
6
+
7
+ it { should respond_to :id }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :self_link }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :lists_collection_link }
12
+ it { should respond_to :integrations_collection_link }
13
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "AWeber::Resources::Campaign" do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047] }
6
+
7
+ it { should respond_to :click_tracking_enabled }
8
+ it { should respond_to :content_type }
9
+ it { should respond_to :spam_assassin_score }
10
+ it { should respond_to :subject }
11
+ it { should respond_to :total_spam_complaints }
12
+ it { should respond_to :total_undelivered }
13
+ it { should respond_to :total_unsubscribes }
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Click do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047].links[136340].clicks[129530] }
6
+
7
+ it { should respond_to :event_time }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :is_earliest }
11
+ it { should respond_to :resource_type_link }
12
+ it { should respond_to :self_link }
13
+ it { should respond_to :subscriber_link }
14
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Integration do
4
+ include BaseObjects
5
+ subject { aweber.account.integrations[8076] }
6
+
7
+ it { should respond_to :http_etag }
8
+ it { should respond_to :id }
9
+ it { should respond_to :login }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :self_link }
12
+ it { should respond_to :service_name }
13
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Link do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047].links[136340] }
6
+
7
+ it { should respond_to :clicks_collection_link }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :self_link }
12
+ it { should respond_to :total_clicks }
13
+ it { should respond_to :total_unique_clicks }
14
+ it { should respond_to :url }
15
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Message do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1] }
6
+
7
+ it { should respond_to :campaigns_collection_link }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :name }
11
+ it { should respond_to :resource_type_link }
12
+ it { should respond_to :self_link }
13
+ it { should respond_to :subscribers_collection_link }
14
+ it { should respond_to :web_form_split_tests_collection_link }
15
+ it { should respond_to :web_forms_collection_link }
16
+ it { should respond_to :broadcasts }
17
+ it { should respond_to :followups }
18
+
19
+ it "should should have a collection of broadcasts" do
20
+ subject.broadcasts.map { |id, b| b.self_link }.all? { |b| b =~ /b\d+$/ }.should be_true
21
+ end
22
+
23
+ it "should should have a collection of followups" do
24
+ subject.followups.map { |id, f| f.self_link }.all? { |f| f =~ /f\d+$/ }.should be_true
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Message do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047].messages[11839] }
6
+
7
+ it { should respond_to :event_time }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :self_link }
12
+ it { should respond_to :last_opened }
13
+ it { should respond_to :opens_collection_link }
14
+ it { should respond_to :subscriber_link }
15
+ it { should respond_to :total_opens }
16
+ it { should respond_to :tracked_events_collection_link }
17
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Open do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047].messages[11839].opens[11721] }
6
+
7
+ it { should respond_to :event_time }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :self_link }
12
+ it { should respond_to :subscriber_link }
13
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::Subscriber do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].subscribers[50723026] }
6
+
7
+ it { should respond_to :ad_tracking }
8
+ it { should respond_to :email }
9
+ it { should respond_to :http_etag }
10
+ it { should respond_to :id }
11
+ it { should respond_to :ip_address }
12
+ it { should respond_to :is_verified }
13
+ it { should respond_to :last_followup_sent_at }
14
+ it { should respond_to :last_followup_sent_link }
15
+ it { should respond_to :misc_notes }
16
+ it { should respond_to :name }
17
+ it { should respond_to :resource_type_link }
18
+ it { should respond_to :self_link }
19
+ it { should respond_to :status }
20
+ it { should respond_to :subscribed_at }
21
+ it { should respond_to :subscription_method }
22
+ it { should respond_to :subscription_url }
23
+ it { should respond_to :unsubscribed_at }
24
+ it { should respond_to :verified_at }
25
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::TrackedEvent do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].campaigns[50000047].messages[11839].tracked_events[11839] }
6
+
7
+ it { should respond_to :event_time }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :resource_type_link }
11
+ it { should respond_to :self_link }
12
+ it { should respond_to :subscriber_link }
13
+ it { should respond_to :type }
14
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::WebForm do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].web_forms[1911952229] }
6
+
7
+ it { should respond_to :conversion_percentage }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :is_active }
11
+ it { should respond_to :name }
12
+ it { should respond_to :resource_type_link }
13
+ it { should respond_to :self_link }
14
+ it { should respond_to :total_displays }
15
+ it { should respond_to :total_submissions }
16
+ it { should respond_to :total_unique_displays }
17
+ it { should respond_to :type }
18
+ it { should respond_to :unique_conversion_percentage }
19
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::WebFormSplitTestComponent do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].web_form_split_tests[1242668124].components["612763163-513600765"] }
6
+
7
+ it { should respond_to :conversion_percentage }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :is_active }
11
+ it { should respond_to :name }
12
+ it { should respond_to :resource_type_link }
13
+ it { should respond_to :self_link }
14
+ it { should respond_to :total_displays }
15
+ it { should respond_to :total_submissions }
16
+ it { should respond_to :type }
17
+ it { should respond_to :unique_conversion_percentage }
18
+ it { should respond_to :web_form_link }
19
+ it { should respond_to :weight }
20
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe AWeber::Resources::WebFormSplitTest do
4
+ include BaseObjects
5
+ subject { aweber.account.lists[1].web_form_split_tests[1242668124] }
6
+
7
+ it { should respond_to :components_collection_link }
8
+ it { should respond_to :http_etag }
9
+ it { should respond_to :id }
10
+ it { should respond_to :is_active }
11
+ it { should respond_to :name }
12
+ it { should respond_to :resource_type_link }
13
+ it { should respond_to :self_link }
14
+ end
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ require "aweber"
4
+ require "fakeweb"
5
+ require 'rspec'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ def aweber_url(url)
10
+ url =~ /https/ ? url : File.join(AWeber.api_endpoint, "1.0", url)
11
+ end
12
+
13
+ def route(method, uri, response)
14
+ FakeWeb.register_uri(method, uri, :body => response)
15
+ end
16
+
17
+ def fixture(filename)
18
+ return "" if filename.empty?
19
+ path = File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
20
+ File.read(path).gsub /\s/, ''
21
+ end
22
+
23
+ def stub_get(uri, response)
24
+ route(:get, uri, fixture(response))
25
+ end
26
+
27
+ module BaseObjects
28
+ def oauth
29
+ @oauth ||= AWeber::OAuth.new("token", "secret")
30
+ end
31
+
32
+ def aweber
33
+ @aweber ||= AWeber::Base.new(oauth)
34
+ end
35
+ end
36
+
37
+ route :any, "https://auth.aweber.com/1.0/request_token", "oauth_token=fake&oauth_token_secret=fake"
38
+ route :any, "https://auth.aweber.com/1.0/access_token", "oauth_token=fake&oauth_token_secret=fake"
39
+
40
+ route :get, %r[/accounts\?], fixture("accounts.json")
41
+ route :get, %r[/accounts/\d+/lists\?], fixture("lists.json")
42
+ route :get, %r[/accounts/\d+/lists/\d+/subscribers\?], fixture("subscribers.json")
43
+ route :get, %r[/accounts/\d+/lists/\d+/web_forms\?], fixture("web_forms.json")
44
+ route :get, %r[/accounts/\d+/lists/\d+/web_form_split_tests\?], fixture("web_form_split_tests.json")
45
+ route :get, %r[/accounts/\d+/lists/\d+/web_form_split_tests/\d+/components\?], fixture("web_form_split_test_components.json")
46
+ route :get, %r[/accounts/\d+/integrations\?], fixture("integrations.json")
47
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns\?], fixture("campaigns.json")
48
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/links\?], fixture("links.json")
49
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/links/\d+/clicks\?], fixture("clicks.json")
50
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages\?], fixture("messages.json")
51
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/opens\?], fixture("opens.json")
52
+ route :get, %r[/accounts/\d+/lists/\d+/campaigns/[\d\w]+/messages/\d+/tracked_events\?], fixture("tracked_events.json")