Skip to content

Commit

Permalink
Added in features to make it easier to add in contact info
Browse files Browse the repository at this point in the history
  • Loading branch information
economysizegeek committed Sep 14, 2012
1 parent 9b46cac commit b998e42
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 42 deletions.
1 change: 1 addition & 0 deletions lib/insightly/base.rb
@@ -1,3 +1,4 @@
#METODO contacts allow you to set special dates to remember - can we access that via api?
#METODO only allow build to set fields that are part of the API fields
#METODO make a distinction between fields that you can set and save and ones you can only read - like DATE_UPDATED_UTC
module Insightly
Expand Down
88 changes: 47 additions & 41 deletions lib/insightly/contact_info.rb
@@ -1,61 +1,67 @@
module Insightly
class ContactInfo
def initialize
@data = {}
end
class ContactInfo < BaseData
api_field "CONTACT_INFO_ID",
"TYPE",
"SUBTYPE",
"LABEL",
"DETAIL"

def to_json
@data.to_json
end
def build(data)
@data = data
self
def self.phone(label, number)
item = self.new
item.type = "PHONE"
item.label = label
item.detail = number
item
end

def self.build(data)
self.new.build(data)
def self.email(label, email)
item = self.new
item.type = "EMAIL"
item.label = label
item.detail = email
item
end

def ==(other)
self.remote_data == other.remote_data
def self.social(label, info, subtype)
item = self.new
item.type = "SOCIAL"
item.subtype = subtype
item.label = label
item.detail = info
item
end

def remote_data
@data
def self.website(label, url)
item = self.new
item.type = "WEBSITE"
item.label = label
item.detail = url
item
end
def contact_info_id
@data["CONTACT_INFO_ID"]

def self.twitter_id(id)
self.social("TwitterID", id, "TwitterID")
end
def type
@data["TYPE"]
end
def subtype
@data["SUBTYPE"]

def self.linked_in(url)
self.social("LinkedInPublicProfileUrl", url, "LinkedInPublicProfileUrl")
end
def label
@data["LABEL"]

def self.work_phone(number)
self.phone("Work", number)
end
def detail
@data["DETAIL"]

def self.work_email(email)
self.email("Work", email)
end

def contact_info_id=(value)
@data["CONTACT_INFO_ID"] = value

end
def type=(value)
@data["TYPE"] = value
end
def subtype=(value)
@data["SUBTYPE"] = value
end
def label=(value)
@data["LABEL"] = value
end
def detail=(value)
@data["DETAIL"] = value
def self.business_website(url)
self.website("Work", url)
end

def self.blog(url)
self.website("Blog", url)
end
end
end
2 changes: 1 addition & 1 deletion lib/insightly/version.rb
Expand Up @@ -4,7 +4,7 @@ module Insightly
module Version
Major = 0
Minor = 2
Tiny = 2
Tiny = 3
String = "#{Major}.#{Minor}.#{Tiny}"
end
end
138 changes: 138 additions & 0 deletions spec/unit/contact_info_spec.rb
@@ -0,0 +1,138 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe Insightly::ContactInfo do
before(:each) do
Insightly::Configuration.api_key = INSIGHTLY_API_KEY

# @all = Insightly::Contact.new(20315449)
@contact_info = Insightly::ContactInfo.build({
"LABEL" => "Work",
"SUBTYPE" => nil,
"CONTACT_INFO_ID" => 1,
"TYPE" => "WEBSITE",
"DETAIL" => "http://www.truckingoffice.com"

})
end
it "should be able to build an contact_info from data" do
data = {
"LABEL" => "Work",
"SUBTYPE" => nil,
"CONTACT_INFO_ID" => 1,
"TYPE" => "WEBSITE",
"DETAIL" => "http://www.truckingoffice.com"

}
@contact_info = Insightly::ContactInfo.build(data)

@contact_info.remote_data.should == data
end
it "should be able to retrieve the data as an array" do
@contact_info.remote_data["CONTACT_INFO_ID"].should == 1
end
it "should be able to convert to json" do
@contact_info.to_json.should == @contact_info.remote_data.to_json
end

it "should know if two contact_info are equal" do
@contact_info2 = Insightly::ContactInfo.build(@contact_info.remote_data.clone)
@contact_info2.should == @contact_info
@contact_info.detail = nil
@contact_info2.should_not == @contact_info
end

it "should have accessor for contact_info_id" do
@contact_info.contact_info_id = 2
@contact_info.contact_info_id.should == 2
end
it "should have accessor for type" do
@contact_info.type = 2
@contact_info.type.should == 2
end
it "should have accessor for subtype" do
@contact_info.subtype = 2
@contact_info.subtype.should == 2
end

it "should have accessor for label" do
@contact_info.label = "Worker"
@contact_info.label.should == "Worker"
end
it "should have accessor for detail" do
@contact_info.detail = "New hire"
@contact_info.detail.should == "New hire"
end

it "should be easy to add a phone number" do
@info = Insightly::ContactInfo.phone("Work","210-555-1212")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "210-555-1212"
@info.type.should == "PHONE"
end
it "should be easy to add a work phone number" do
@info = Insightly::ContactInfo.work_phone("210-555-1212")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "210-555-1212"
@info.type.should == "PHONE"
end
it "should be easy to add an email" do
@info = Insightly::ContactInfo.email("Work","bob@aol.com")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "bob@aol.com"
@info.type.should == "EMAIL"
end
it "should be easy to add a work email" do
@info = Insightly::ContactInfo.work_email("bob@aol.com")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "bob@aol.com"
@info.type.should == "EMAIL"
end
it "should be easy to add a website" do
@info = Insightly::ContactInfo.website("Work","http://www.truckingoffice.com")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "http://www.truckingoffice.com"
@info.type.should == "WEBSITE"
end
it "should be easy to add a business website" do
@info = Insightly::ContactInfo.business_website("http://www.truckingoffice.com")
@info.label.should == "Work"
@info.subtype.should be_nil
@info.detail.should == "http://www.truckingoffice.com"
@info.type.should == "WEBSITE"
end
it "should be easy to add a blog" do
@info = Insightly::ContactInfo.blog("http://www.r26d.com")
@info.label.should == "Blog"
@info.subtype.should be_nil
@info.detail.should == "http://www.r26d.com"
@info.type.should == "WEBSITE"
end
it "should be easy to add a twitter id" do
@info = Insightly::ContactInfo.twitter_id("economysizegeek")
@info.label.should == "TwitterID"
@info.subtype.should == "TwitterID"
@info.detail.should == "economysizegeek"
@info.type.should == "SOCIAL"
end
it "should be easy to add a social entry" do
@info = Insightly::ContactInfo.social('TwitterID','economysizegeek','TwitterID')
@info.label.should == "TwitterID"
@info.subtype.should == "TwitterID"
@info.detail.should == "economysizegeek"
@info.type.should == "SOCIAL"
end
it "should be easy to add a linked in profile" do
@info = Insightly::ContactInfo.linked_in("http://www.linkedin.com/company/1499784")
@info.label.should == "LinkedInPublicProfileUrl"
@info.subtype.should == "LinkedInPublicProfileUrl"
@info.detail.should == "http://www.linkedin.com/company/1499784"
@info.type.should == "SOCIAL"
end


end

0 comments on commit b998e42

Please sign in to comment.