Skip to content

Commit

Permalink
Fetch from_fields for account. Closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
seban committed Jan 29, 2011
1 parent 2be8ec7 commit 0118174
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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>]
1 change: 1 addition & 0 deletions lib/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY='d333e12e5019b6940127e82b499d75a5'
3 changes: 2 additions & 1 deletion lib/get_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 10 additions & 1 deletion lib/get_response/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/get_response/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
18 changes: 18 additions & 0 deletions lib/get_response/from_field.rb
Original file line number Diff line number Diff line change
@@ -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
50 changes: 48 additions & 2 deletions test/unit/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions test/unit/from_field_test.rb
Original file line number Diff line number Diff line change
@@ -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.