chubasaweber 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +17 -0
  6. data/README.textile +65 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/aweber.gemspec +53 -0
  10. data/chubasaweber.gemspec +144 -0
  11. data/examples/with_access_token.rb +17 -0
  12. data/examples/your_account.rb +26 -0
  13. data/lib/aweber.rb +66 -0
  14. data/lib/aweber/base.rb +57 -0
  15. data/lib/aweber/collection.rb +110 -0
  16. data/lib/aweber/oauth.rb +69 -0
  17. data/lib/aweber/resource.rb +131 -0
  18. data/lib/aweber/resources.rb +14 -0
  19. data/lib/aweber/resources/account.rb +14 -0
  20. data/lib/aweber/resources/broadcast.rb +29 -0
  21. data/lib/aweber/resources/click.rb +13 -0
  22. data/lib/aweber/resources/followup.rb +24 -0
  23. data/lib/aweber/resources/integration.rb +8 -0
  24. data/lib/aweber/resources/link.rb +12 -0
  25. data/lib/aweber/resources/list.rb +86 -0
  26. data/lib/aweber/resources/message.rb +20 -0
  27. data/lib/aweber/resources/open.rb +10 -0
  28. data/lib/aweber/resources/subscriber.rb +28 -0
  29. data/lib/aweber/resources/tracked_event.rb +13 -0
  30. data/lib/aweber/resources/web_form.rb +14 -0
  31. data/lib/aweber/resources/web_form_split_test.rb +11 -0
  32. data/lib/aweber/resources/web_form_split_test_component.rb +20 -0
  33. data/lib/chubasaweber.rb +66 -0
  34. data/spec/base_spec.rb +23 -0
  35. data/spec/collection_spec.rb +40 -0
  36. data/spec/fixtures/account.json +8 -0
  37. data/spec/fixtures/accounts.json +13 -0
  38. data/spec/fixtures/campaign.json +23 -0
  39. data/spec/fixtures/campaigns.json +106 -0
  40. data/spec/fixtures/click.json +9 -0
  41. data/spec/fixtures/clicks.json +14 -0
  42. data/spec/fixtures/integration.json +8 -0
  43. data/spec/fixtures/integrations.json +45 -0
  44. data/spec/fixtures/link.json +10 -0
  45. data/spec/fixtures/links.json +75 -0
  46. data/spec/fixtures/list.json +11 -0
  47. data/spec/fixtures/lists.json +38 -0
  48. data/spec/fixtures/message.json +12 -0
  49. data/spec/fixtures/messages.json +29 -0
  50. data/spec/fixtures/open.json +8 -0
  51. data/spec/fixtures/opens.json +21 -0
  52. data/spec/fixtures/subscriber.json +16 -0
  53. data/spec/fixtures/subscribers.json +69 -0
  54. data/spec/fixtures/tracked_event.json +8 -0
  55. data/spec/fixtures/tracked_events.json +21 -0
  56. data/spec/fixtures/web_form.json +14 -0
  57. data/spec/fixtures/web_form_split_test.json +9 -0
  58. data/spec/fixtures/web_form_split_test_component.json +16 -0
  59. data/spec/fixtures/web_form_split_test_components.json +37 -0
  60. data/spec/fixtures/web_form_split_tests.json +41 -0
  61. data/spec/fixtures/web_forms.json +229 -0
  62. data/spec/oauth_spec.rb +96 -0
  63. data/spec/resource_spec.rb +80 -0
  64. data/spec/resources/account_spec.rb +13 -0
  65. data/spec/resources/campaign_spec.rb +14 -0
  66. data/spec/resources/click_spec.rb +14 -0
  67. data/spec/resources/integration_spec.rb +13 -0
  68. data/spec/resources/link_spec.rb +15 -0
  69. data/spec/resources/list_spec.rb +26 -0
  70. data/spec/resources/message_spec.rb +17 -0
  71. data/spec/resources/open_spec.rb +13 -0
  72. data/spec/resources/subscriber_spec.rb +33 -0
  73. data/spec/resources/tracked_event_spec.rb +14 -0
  74. data/spec/resources/web_form_spec.rb +19 -0
  75. data/spec/resources/web_form_split_test_component_spec.rb +20 -0
  76. data/spec/resources/web_form_split_test_spec.rb +14 -0
  77. data/spec/spec_helper.rb +52 -0
  78. data/test/helper.rb +10 -0
  79. data/test/test_chubasaweber.rb +7 -0
  80. metadata +181 -0
@@ -0,0 +1,24 @@
1
+ module AWeber
2
+ module Resources
3
+ class Followup < Resource
4
+ api_attr :click_tracking_enabled
5
+ api_attr :content_type
6
+ api_attr :message_interval
7
+ api_attr :message_number
8
+ api_attr :spam_assassin_score
9
+ api_attr :subject
10
+ api_attr :total_clicked
11
+ api_attr :total_opened
12
+ api_attr :total_sent
13
+ api_attr :total_spam_complaints
14
+ api_attr :total_undelivered
15
+ api_attr :total_unsubscribes
16
+
17
+ api_attr :links_collection_link
18
+ api_attr :messages_collection_link
19
+
20
+ has_many :links
21
+ has_many :messages
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ module AWeber
2
+ module Resources
3
+ class Integration < Resource
4
+ api_attr :login
5
+ api_attr :service_name
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module AWeber
2
+ module Resources
3
+ class Link < Resource
4
+ api_attr :total_clicks
5
+ api_attr :total_unique_clicks
6
+ api_attr :url
7
+ api_attr :clicks_collection_link
8
+
9
+ has_many :clicks
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,86 @@
1
+ module AWeber
2
+ module Resources
3
+ class List < Resource
4
+ FOLLOWUP_TYPE_LINK = File.join(AWeber.api_url, "#followup_campaign")
5
+ BROADCAST_TYPE_LINK = File.join(AWeber.api_url, "#broadcast_campaign")
6
+
7
+ api_attr :name
8
+
9
+ api_attr :campaigns_collection_link
10
+ api_attr :subscribers_collection_link
11
+ api_attr :web_forms_collection_link
12
+ api_attr :web_form_split_tests_collection_link
13
+
14
+ has_many :subscribers
15
+ has_many :web_forms
16
+ has_many :web_form_split_tests
17
+
18
+ def initialize(*args)
19
+ super(*args)
20
+ @campaigns = {}
21
+ @followups = nil
22
+ @broadcasts = nil
23
+ end
24
+
25
+ def campaigns
26
+ return @campaigns unless @campaigns == {}
27
+ create_followups
28
+ create_broadcasts
29
+ populate_campaigns
30
+ @campaigns
31
+ end
32
+
33
+ def broadcasts
34
+ campaigns if @broadcasts.nil?
35
+ @broadcasts
36
+ end
37
+
38
+ def followups
39
+ campaigns if @followups.nil?
40
+ @followups
41
+ end
42
+
43
+ private
44
+
45
+ def create_followups
46
+ followups = _entries.select { |entry| is_followup? entry }
47
+ @followups = Collection.new(client, Followup, {
48
+ "entries" => followups,
49
+ "total_size" => followups.length,
50
+ "resource_type_link" => FOLLOWUP_TYPE_LINK
51
+ })
52
+ end
53
+
54
+ def create_broadcasts
55
+ broadcasts = _entries.select { |entry| is_broadcast? entry }
56
+ @broadcasts = Collection.new(client, Broadcast, {
57
+ "entries" => broadcasts,
58
+ "total_size" => broadcasts.length,
59
+ "resource_type_link" => BROADCAST_TYPE_LINK
60
+ })
61
+ end
62
+
63
+ def populate_campaigns
64
+ @followups.each { |id, followup| @campaigns[id] = followup }
65
+ @broadcasts.each { |id, broadcast| @campaigns[id] = broadcast }
66
+ end
67
+
68
+ def is_followup?(entry)
69
+ entry["resource_type_link"].split("#").last =~ /^followup/
70
+ end
71
+
72
+ def is_broadcast?(entry)
73
+ entry["resource_type_link"].split("#").last =~ /^broadcast/
74
+ end
75
+
76
+ def _campaigns
77
+ @_campaigns ||= client.get(@campaigns_collection_link)
78
+ end
79
+
80
+ def _entries
81
+ _campaigns["entries"]
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,20 @@
1
+ module AWeber
2
+ module Resources
3
+ class Message < Resource
4
+ api_attr :event_time
5
+ api_attr :last_opened
6
+ api_attr :total_opens
7
+
8
+ api_attr :subscriber_link
9
+ api_attr :tracked_events_collection_link
10
+ api_attr :opens_collection_link
11
+
12
+ has_one :subscriber
13
+
14
+ has_many :tracked_events
15
+ has_many :opens
16
+
17
+ alias_attribute :events, :tracked_events
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module AWeber
2
+ module Resources
3
+ class Open < Resource
4
+ api_attr :event_time
5
+ api_attr :subscriber_link
6
+
7
+ has_one :subscriber
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module AWeber
2
+ module Resources
3
+ class Subscriber < Resource
4
+ api_attr :name, :writable => true
5
+ api_attr :misc_notes, :writable => true
6
+ api_attr :email, :writable => true
7
+ api_attr :status, :writable => true
8
+ api_attr :custom_fields, :writable => true
9
+ api_attr :ad_tracking, :writable => true
10
+ api_attr :last_followup_message_number_sent, :writable => true
11
+
12
+ api_attr :ip_address
13
+ api_attr :is_verified
14
+ api_attr :last_followup_sent_at
15
+ api_attr :subscribed_at
16
+ api_attr :subscription_method
17
+ api_attr :subscription_url
18
+ api_attr :unsubscribed_at
19
+ api_attr :verified_at
20
+ api_attr :last_followup_sent_link
21
+
22
+ has_one :last_followup_sent
23
+
24
+ alias_attribute :is_verified?, :is_verified
25
+ alias_attribute :notes, :misc_notes
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module AWeber
2
+ module Resources
3
+ class TrackedEvent < Resource
4
+ api_attr :event_time
5
+ api_attr :type
6
+ api_attr :subscriber_link
7
+
8
+ has_one :subscriber
9
+
10
+ alias_attribute :time, :event_time
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module AWeber
2
+ module Resources
3
+ class WebForm < Resource
4
+ api_attr :conversion_percentage
5
+ api_attr :is_active
6
+ api_attr :name
7
+ api_attr :total_displays
8
+ api_attr :total_submissions
9
+ api_attr :total_unique_displays
10
+ api_attr :type
11
+ api_attr :unique_conversion_percentage
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module AWeber
2
+ module Resources
3
+ class WebFormSplitTest < Resource
4
+ api_attr :components_collection_link
5
+ api_attr :is_active
6
+ api_attr :name
7
+
8
+ has_many :components
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module AWeber
2
+ module Resources
3
+ class WebFormSplitTestComponent < Resource
4
+ api_attr :conversion_percentage
5
+ api_attr :is_active
6
+ api_attr :name
7
+ api_attr :total_displays
8
+ api_attr :total_submissions
9
+ api_attr :total_unique_displays
10
+ api_attr :type
11
+ api_attr :unique_conversion_percentage
12
+ api_attr :web_form_link
13
+ api_attr :weight
14
+
15
+ has_one :web_form
16
+
17
+ alias_attribute :is_active?, :is_active
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,66 @@
1
+ require "forwardable"
2
+ require "oauth"
3
+
4
+ module AWeber
5
+ API_VERSION = "1.0".freeze
6
+ AUTH_VERSION = "1.0".freeze
7
+
8
+ # Used for +has_many+ and +has_one+ relationships.
9
+ #
10
+ INFLECTIONS = {
11
+ :accounts => :Account,
12
+ :clicks => :Click,
13
+ :links => :Link,
14
+ :lists => :List,
15
+ :messages => :Message,
16
+ :opens => :Open,
17
+ :subscribers => :Subscriber,
18
+ :tracked_events => :TrackedEvent,
19
+ :integrations => :Integration,
20
+ :web_forms => :WebForm,
21
+ :components => :WebFormSplitTestComponent,
22
+ :web_form_split_tests => :WebFormSplitTest,
23
+ :last_followup_sents => :Followup
24
+ }
25
+
26
+ class << self
27
+ # @param [String] Base URL of the API server
28
+ #
29
+ attr_accessor :api_endpoint
30
+
31
+ # @param [String] Base URL of the Auth server
32
+ #
33
+ attr_accessor :auth_endpoint
34
+
35
+ def api_url
36
+ File.join api_endpoint, API_VERSION
37
+ end
38
+
39
+ def auth_url
40
+ File.join auth_endpoint, AUTH_VERSION
41
+ end
42
+
43
+ # Retrieves the Resource class based on the
44
+ # +INFLECTIONS+ map and +name+.
45
+ #
46
+ # @param [Symbol] name Collection name
47
+ #
48
+ def get_class(name)
49
+ Resources.const_get(INFLECTIONS[name])
50
+ end
51
+ end
52
+
53
+ @api_endpoint = "https://api.aweber.com"
54
+ @auth_endpoint = "https://auth.aweber.com"
55
+
56
+ class OAuthError < Exception; end
57
+ class NotFoundError < Exception; end
58
+ class UnknownRequestError < Exception; end
59
+ end
60
+
61
+ $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
62
+ require "aweber/oauth"
63
+ require "aweber/base"
64
+ require "aweber/resource"
65
+ require "aweber/resources"
66
+ require "aweber/collection"
data/spec/base_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AWeber::Base do
4
+ before :each do
5
+ @oauth = AWeber::OAuth.new("token", "secret")
6
+ @aweber = AWeber::Base.new(@oauth)
7
+ end
8
+
9
+ it "should have an account" do
10
+ @aweber.account.should be_an AWeber::Resources::Account
11
+ end
12
+
13
+ it "should expand uris to full paths" do
14
+ resp = @oauth.get("https://api.aweber.com/1.0/accounts")
15
+ @oauth.should_receive(:get).with("https://api.aweber.com/1.0/accounts").and_return(resp)
16
+ @aweber.account
17
+ end
18
+
19
+ it "should delegate to the oauth object" do
20
+ @oauth.should_receive(:get).with("https://api.aweber.com/1.0/foo")
21
+ @aweber.send(:get, "/foo")
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AWeber::Collection do
4
+
5
+ before :each do
6
+ @oauth = AWeber::OAuth.new("token", "secret")
7
+ @aweber = AWeber::Base.new(@oauth)
8
+ data = ActiveSupport::JSON.decode(fixture("lists.json"))
9
+ @lists = AWeber::Collection.new(@aweber, AWeber::Resources::List, data)
10
+ end
11
+
12
+ it "should create classes from the one passed into initialize" do
13
+ @lists[1].should be_an AWeber::Resources::List
14
+ end
15
+
16
+ it "should be iterable" do
17
+ @lists.should respond_to :each
18
+ @lists.map { |id, l| id }.should be_an Array
19
+ end
20
+
21
+ it "should be accessible via id in normal Hash form" do
22
+ @lists[1].id.should == 1
23
+ end
24
+
25
+ it "should retrieve more resources, if needed, when being iterated over" do
26
+ list_ids = @lists.map{ |id, list| list }
27
+ list_ids.length.should == 3
28
+ list_ids.all? { |e| e.is_a? AWeber::Resources::List }.should == true
29
+ end
30
+
31
+ it "should return single entries with dynamic find_by methods" do
32
+ @lists.find_by_id(1).should be_an AWeber::Resources::List
33
+ @lists.find_by_id(1).id.should == 1
34
+ end
35
+
36
+ it "should return Hashes of entries when find_by methods match many" do
37
+ lists = @lists.find_by_resource_type_link("https://api.aweber.com/1.0/#list")
38
+ lists.length.should == 3
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "http_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
3
+ "lists_collection_link": "https://api.aweber.com/1.0/accounts/1/lists",
4
+ "self_link": "https://api.aweber.com/1.0/accounts/1",
5
+ "resource_type_link": "https://api.aweber.com/1.0/#account",
6
+ "id": 1,
7
+ "integrations_collection_link": "https://api.aweber.com/1.0/accounts/1/integrations"
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "total_size": 1,
3
+ "start": 0,
4
+ "resource_type_link": "https://api.aweber.com/1.0/#accounts",
5
+ "entries": [{
6
+ "http_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-ca5feee2b7fbb6febfca8af5541541ea960aaedb\"",
7
+ "lists_collection_link": "https://api.aweber.com/1.0/accounts/1/lists",
8
+ "self_link": "https://api.aweber.com/1.0/accounts/1",
9
+ "resource_type_link": "https://api.aweber.com/1.0/#account",
10
+ "id": 1,
11
+ "integrations_collection_link": "https://api.aweber.com/1.0/accounts/1/integrations"
12
+ }]
13
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "click_tracking_enabled": 0,
3
+ "sent_date": null,
4
+ "is_archived": true,
5
+ "spam_assassin_score": null,
6
+ "http_etag": "\"14a1a033beff462b137a8222f595af4622875d44-ccadae5b53f02d3db0cc83ca57ae75ac804b2b98\"",
7
+ "total_undeliverable": null,
8
+ "twitter_account_link": null,
9
+ "total_opens": 0,
10
+ "links_collection_link": "http://api.apitest.lab/1.0/accounts/1/lists/1/campaigns/b2/links",
11
+ "total_clicks": 0,
12
+ "published_to_archive": null,
13
+ "messages_collection_link": "http://api.apitest.lab/1.0/accounts/1/lists/1/campaigns/b2/messages",
14
+ "send_date": "2010-22-12T22:15:00-07:00",
15
+ "content_type": "HTML",
16
+ "total_sent": 0,
17
+ "self_link": "http://api.apitest.lab/1.0/accounts/1/lists/1/campaigns/b2",
18
+ "subject": "Something about stuff.",
19
+ "resource_type_link": "http://api.apitest.lab/1.0/#broadcast_campaign",
20
+ "id": 2,
21
+ "total_unsubscribes": 0,
22
+ "total_spam_complaints": null
23
+ }