Permalink
Browse files

Fetch all domains connected with account. Closes #8

  • Loading branch information...
1 parent a70426f commit 6780e85242d47872296b388dd6decc071f20835f @seban committed Feb 1, 2011
View
@@ -87,4 +87,10 @@ Add account from field
# with account
# account = existing account
account.from_fields.create("name" => "My new name", "email" => "my_new_email@foo.bar")
- => #<GetResponse::FromField:0xb7727010 ... >
+ => #<GetResponse::FromField:0xb7727010 ... >
+
+Get account domains
+
+ # with account
+ # account - existing account
+ account.domains.all
View
@@ -51,4 +51,6 @@ class Symbol
GetResponse.autoload :CampaignProxy, "get_response/campaign_proxy"
GetResponse.autoload :ContactProxy, "get_response/contact_proxy"
GetResponse.autoload :FromField, "get_response/from_field"
-GetResponse.autoload :FromFieldsProxy, "get_response/from_fields_proxy"
+GetResponse.autoload :FromFieldsProxy, "get_response/from_fields_proxy"
+GetResponse.autoload :Domain, "get_response/domain"
+GetResponse.autoload :DomainProxy, "get_response/domain_proxy"
@@ -17,5 +17,11 @@ def initialize(params, connection)
def from_fields
FromFieldsProxy.new(@connection)
end
+
+
+ def domains
+ DomainProxy.new(@connection)
+ end
+
end
end
@@ -0,0 +1,16 @@
+module GetResponse
+
+ # Domain connected with account or campaign in GetResponse
+ class Domain
+
+ attr_reader :id, :domain, :created_on
+
+ def initialize(attributes)
+ @id = attributes["id"]
+ @domain = attributes["domain"]
+ @created_on = attributes["created_on"]
+ end
+
+ end
+
+end
@@ -0,0 +1,23 @@
+module GetResponse
+
+ # Proxy class for domain operations.
+ class DomainProxy
+
+ def initialize(connection)
+ @connection = connection
+ end
+
+
+ # Get all domains connected with account.
+ #
+ # returns:: [GetResponse::Domain]
+ def all
+ domains_attrs = @connection.send_request("get_account_domains")["result"]
+ domains_attrs.map do |id, attrs|
+ GetResponse::Domain.new(attrs.merge("id" => id))
+ end
+ end
+
+ end
+
+end
@@ -22,6 +22,14 @@ def test_from_fields
end
+ def test_domains
+ @connection = connection
+ @account = new_account({}, @connection)
+
+ assert_kind_of GetResponse::DomainProxy, @account.domains
+ end
+
+
protected
@@ -0,0 +1,35 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '../test_helper'))
+
+class DomainProxyTest < Test::Unit::TestCase
+
+ def setup
+ @connection = GetResponse::Connection.new("API_KEY")
+ @domain_proxy = GetResponse::DomainProxy.new(@connection)
+ end
+
+
+ def test_all
+ mock(@connection).send_request("get_account_domains") { all_domains_resp }
+ all_domains = @domain_proxy.all
+
+ assert_kind_of Array, all_domains
+ assert_equal true, all_domains.all? { |obj| obj.instance_of?(GetResponse::Domain) }
+ end
+
+
+ protected
+
+
+ def all_domains_resp
+ {
+ "result" => {
+ "123" => {
+ "domain" => "domain.com",
+ "created_on" => "2011-01-20 00:00:00"
+ }
+ },
+ "error" => nil
+ }
+ end
+
+end
@@ -0,0 +1,14 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '../test_helper'))
+
+class DomainTest < Test::Unit::TestCase
+
+ def test_instance
+ @domain = GetResponse::Domain.new("id" => "234", "domain" => "newsletter.company.com",
+ "created_on" => "2011-01-20 00:00:00")
+
+ assert @domain.respond_to?(:id)
+ assert @domain.respond_to?(:domain)
+ assert @domain.respond_to?(:created_on)
+ end
+
+end

0 comments on commit 6780e85

Please sign in to comment.