Browse files

Fetch from_fields for account. Closes #6

  • Loading branch information...
1 parent 2be8ec7 commit 011817493bcbdd5c3dea49a99f882e7a072c3b25 @seban committed Jan 29, 2011
View
9 README.rdoc
@@ -73,4 +73,11 @@ Get custom attributes
# with connection
# contact - existing contact
contact.customs
- => { "attr_name" => "attr_value" }
+ => { "attr_name" => "attr_value" }
+
+Get account from fields
+
+ # with account
+ # acocunt - existing account
+ account.from_fields
+ => [<FromField: xcv>]
View
1 lib/api.rb
@@ -0,0 +1 @@
+API_KEY='d333e12e5019b6940127e82b499d75a5'
View
3 lib/get_response.rb
@@ -49,4 +49,5 @@ class Symbol
GetResponse.autoload :Contact, "get_response/contact"
GetResponse.autoload :Message, "get_response/message"
GetResponse.autoload :CampaignProxy, "get_response/campaign_proxy"
-GetResponse.autoload :ContactProxy, "get_response/contact_proxy"
+GetResponse.autoload :ContactProxy, "get_response/contact_proxy"
+GetResponse.autoload :FromField, "get_response/from_field"
View
11 lib/get_response/account.rb
@@ -5,11 +5,20 @@ class Account
attr_reader :login, :name, :email, :created_on
- def initialize(params)
+ def initialize(params, connection)
@login = params["login"]
@name = params["from_name"]
@email = params["from_email"]
@created_on = params["created_on"]
+ @connection = connection
+ end
+
+
+ def from_fields
+ from_fields_attrs = @connection.send_request("get_account_from_fields")["result"]
+ from_fields_attrs.map do |id, attrs|
+ FromField.new(attrs.merge("id" => id))
+ end
end
end
end
View
2 lib/get_response/connection.rb
@@ -27,7 +27,7 @@ def ping
# returns:: GetResponse::Account
def account
resp = self.send_request("get_account_info")
- GetResponse::Account.new(resp["result"])
+ GetResponse::Account.new(resp["result"], self)
end
View
18 lib/get_response/from_field.rb
@@ -0,0 +1,18 @@
+module GetResponse
+
+ # Form field connected with account.
+ class FromField
+
+ attr_reader :id, :name, :email, :created_on
+
+
+ def initialize(params)
+ @id = params["id"]
+ @name = params["name"]
+ @email = params["email"]
+ @created_on = params["created_on"]
+ end
+
+ end
+
+end
View
50 test/unit/account_test.rb
@@ -3,13 +3,59 @@
class AccountTest < Test::Unit::TestCase
def test_initialize
- account = GetResponse::Account.new("login" => "test", "from_name" => "From test",
- "from_email" => "email@test.xx", "created_on" => "2010-02-12")
+ account = GetResponse::Account.new({"login" => "test", "from_name" => "From test",
+ "from_email" => "email@test.xx", "created_on" => "2010-02-12"}, connection)
assert_kind_of GetResponse::Account, account
assert_equal "test", account.login
assert_equal "From test", account.name
assert_equal "email@test.xx", account.email
assert_equal "2010-02-12", account.created_on
end
+
+
+ def test_from_fields
+ @connection = connection
+ mock(@connection).send_request("get_account_from_fields") { from_fields_resp }
+ @account = new_account({}, @connection)
+ from_fields = @account.from_fields
+
+ assert_kind_of Array, from_fields
+ assert_equal true, from_fields.all? { |field| field.instance_of? GetResponse::FromField }
+ end
+
+
+ protected
+
+
+ def new_account(options = {}, new_conn = nil)
+ GetResponse::Account.new({
+ "login" => "test",
+ "from_name" => "From test",
+ "from_email" => "email@test.xx",
+ "created_on" => "2010-02-12"
+ }.merge(options), (new_conn || connection))
+ end
+
+
+ def connection
+ GetResponse::Connection.new("my_secret_api_key")
+ end
+
+
+ # Fetch from fields for account.
+ #
+ # returns:: [FromField]
+ def from_fields_resp
+ {
+ "result" => {
+ "1024" => {
+ "created_on" => "2010-12-14 00:00:00",
+ "email" => "email@text.xx",
+ "name" => "default"
+ }
+ },
+ "error" => nil
+ }
+ end
end
View
15 test/unit/from_field_test.rb
@@ -0,0 +1,15 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '../test_helper'))
+
+class FromFieldTest < Test::Unit::TestCase
+
+ def test_initialize
+ @from_field = GetResponse::FromField.new("name" => "text", "email" => "test@email.cc",
+ "created_on" => "2010-12-23 00:00:00", "id" => "234")
+
+ assert @from_field.id
+ assert @from_field.name
+ assert @from_field.email
+ assert @from_field.created_on
+ end
+
+end

0 comments on commit 0118174

Please sign in to comment.