Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in features to make it easier to add in contact info
- Loading branch information
1 parent
9b46cac
commit b998e42
Showing
4 changed files
with
187 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |