insightly 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ #METODO contacts allow you to set special dates to remember - can we access that via api?
1
2
  #METODO only allow build to set fields that are part of the API fields
2
3
  #METODO make a distinction between fields that you can set and save and ones you can only read - like DATE_UPDATED_UTC
3
4
  module Insightly
@@ -1,61 +1,67 @@
1
1
  module Insightly
2
- class ContactInfo
3
- def initialize
4
- @data = {}
5
- end
2
+ class ContactInfo < BaseData
3
+ api_field "CONTACT_INFO_ID",
4
+ "TYPE",
5
+ "SUBTYPE",
6
+ "LABEL",
7
+ "DETAIL"
6
8
 
7
- def to_json
8
- @data.to_json
9
- end
10
- def build(data)
11
- @data = data
12
- self
9
+ def self.phone(label, number)
10
+ item = self.new
11
+ item.type = "PHONE"
12
+ item.label = label
13
+ item.detail = number
14
+ item
13
15
  end
14
16
 
15
- def self.build(data)
16
- self.new.build(data)
17
+ def self.email(label, email)
18
+ item = self.new
19
+ item.type = "EMAIL"
20
+ item.label = label
21
+ item.detail = email
22
+ item
17
23
  end
18
24
 
19
- def ==(other)
20
- self.remote_data == other.remote_data
25
+ def self.social(label, info, subtype)
26
+ item = self.new
27
+ item.type = "SOCIAL"
28
+ item.subtype = subtype
29
+ item.label = label
30
+ item.detail = info
31
+ item
21
32
  end
22
33
 
23
- def remote_data
24
- @data
34
+ def self.website(label, url)
35
+ item = self.new
36
+ item.type = "WEBSITE"
37
+ item.label = label
38
+ item.detail = url
39
+ item
25
40
  end
26
- def contact_info_id
27
- @data["CONTACT_INFO_ID"]
28
41
 
42
+ def self.twitter_id(id)
43
+ self.social("TwitterID", id, "TwitterID")
29
44
  end
30
- def type
31
- @data["TYPE"]
32
- end
33
- def subtype
34
- @data["SUBTYPE"]
45
+
46
+ def self.linked_in(url)
47
+ self.social("LinkedInPublicProfileUrl", url, "LinkedInPublicProfileUrl")
35
48
  end
36
- def label
37
- @data["LABEL"]
49
+
50
+ def self.work_phone(number)
51
+ self.phone("Work", number)
38
52
  end
39
- def detail
40
- @data["DETAIL"]
53
+
54
+ def self.work_email(email)
55
+ self.email("Work", email)
41
56
  end
42
57
 
43
- def contact_info_id=(value)
44
- @data["CONTACT_INFO_ID"] = value
45
58
 
46
- end
47
- def type=(value)
48
- @data["TYPE"] = value
49
- end
50
- def subtype=(value)
51
- @data["SUBTYPE"] = value
52
- end
53
- def label=(value)
54
- @data["LABEL"] = value
55
- end
56
- def detail=(value)
57
- @data["DETAIL"] = value
59
+ def self.business_website(url)
60
+ self.website("Work", url)
58
61
  end
59
62
 
63
+ def self.blog(url)
64
+ self.website("Blog", url)
65
+ end
60
66
  end
61
67
  end
@@ -4,7 +4,7 @@ module Insightly
4
4
  module Version
5
5
  Major = 0
6
6
  Minor = 2
7
- Tiny = 2
7
+ Tiny = 3
8
8
  String = "#{Major}.#{Minor}.#{Tiny}"
9
9
  end
10
10
  end
@@ -0,0 +1,138 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::ContactInfo do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+
7
+ # @all = Insightly::Contact.new(20315449)
8
+ @contact_info = Insightly::ContactInfo.build({
9
+ "LABEL" => "Work",
10
+ "SUBTYPE" => nil,
11
+ "CONTACT_INFO_ID" => 1,
12
+ "TYPE" => "WEBSITE",
13
+ "DETAIL" => "http://www.truckingoffice.com"
14
+
15
+ })
16
+ end
17
+ it "should be able to build an contact_info from data" do
18
+ data = {
19
+ "LABEL" => "Work",
20
+ "SUBTYPE" => nil,
21
+ "CONTACT_INFO_ID" => 1,
22
+ "TYPE" => "WEBSITE",
23
+ "DETAIL" => "http://www.truckingoffice.com"
24
+
25
+ }
26
+ @contact_info = Insightly::ContactInfo.build(data)
27
+
28
+ @contact_info.remote_data.should == data
29
+ end
30
+ it "should be able to retrieve the data as an array" do
31
+ @contact_info.remote_data["CONTACT_INFO_ID"].should == 1
32
+ end
33
+ it "should be able to convert to json" do
34
+ @contact_info.to_json.should == @contact_info.remote_data.to_json
35
+ end
36
+
37
+ it "should know if two contact_info are equal" do
38
+ @contact_info2 = Insightly::ContactInfo.build(@contact_info.remote_data.clone)
39
+ @contact_info2.should == @contact_info
40
+ @contact_info.detail = nil
41
+ @contact_info2.should_not == @contact_info
42
+ end
43
+
44
+ it "should have accessor for contact_info_id" do
45
+ @contact_info.contact_info_id = 2
46
+ @contact_info.contact_info_id.should == 2
47
+ end
48
+ it "should have accessor for type" do
49
+ @contact_info.type = 2
50
+ @contact_info.type.should == 2
51
+ end
52
+ it "should have accessor for subtype" do
53
+ @contact_info.subtype = 2
54
+ @contact_info.subtype.should == 2
55
+ end
56
+
57
+ it "should have accessor for label" do
58
+ @contact_info.label = "Worker"
59
+ @contact_info.label.should == "Worker"
60
+ end
61
+ it "should have accessor for detail" do
62
+ @contact_info.detail = "New hire"
63
+ @contact_info.detail.should == "New hire"
64
+ end
65
+
66
+ it "should be easy to add a phone number" do
67
+ @info = Insightly::ContactInfo.phone("Work","210-555-1212")
68
+ @info.label.should == "Work"
69
+ @info.subtype.should be_nil
70
+ @info.detail.should == "210-555-1212"
71
+ @info.type.should == "PHONE"
72
+ end
73
+ it "should be easy to add a work phone number" do
74
+ @info = Insightly::ContactInfo.work_phone("210-555-1212")
75
+ @info.label.should == "Work"
76
+ @info.subtype.should be_nil
77
+ @info.detail.should == "210-555-1212"
78
+ @info.type.should == "PHONE"
79
+ end
80
+ it "should be easy to add an email" do
81
+ @info = Insightly::ContactInfo.email("Work","bob@aol.com")
82
+ @info.label.should == "Work"
83
+ @info.subtype.should be_nil
84
+ @info.detail.should == "bob@aol.com"
85
+ @info.type.should == "EMAIL"
86
+ end
87
+ it "should be easy to add a work email" do
88
+ @info = Insightly::ContactInfo.work_email("bob@aol.com")
89
+ @info.label.should == "Work"
90
+ @info.subtype.should be_nil
91
+ @info.detail.should == "bob@aol.com"
92
+ @info.type.should == "EMAIL"
93
+ end
94
+ it "should be easy to add a website" do
95
+ @info = Insightly::ContactInfo.website("Work","http://www.truckingoffice.com")
96
+ @info.label.should == "Work"
97
+ @info.subtype.should be_nil
98
+ @info.detail.should == "http://www.truckingoffice.com"
99
+ @info.type.should == "WEBSITE"
100
+ end
101
+ it "should be easy to add a business website" do
102
+ @info = Insightly::ContactInfo.business_website("http://www.truckingoffice.com")
103
+ @info.label.should == "Work"
104
+ @info.subtype.should be_nil
105
+ @info.detail.should == "http://www.truckingoffice.com"
106
+ @info.type.should == "WEBSITE"
107
+ end
108
+ it "should be easy to add a blog" do
109
+ @info = Insightly::ContactInfo.blog("http://www.r26d.com")
110
+ @info.label.should == "Blog"
111
+ @info.subtype.should be_nil
112
+ @info.detail.should == "http://www.r26d.com"
113
+ @info.type.should == "WEBSITE"
114
+ end
115
+ it "should be easy to add a twitter id" do
116
+ @info = Insightly::ContactInfo.twitter_id("economysizegeek")
117
+ @info.label.should == "TwitterID"
118
+ @info.subtype.should == "TwitterID"
119
+ @info.detail.should == "economysizegeek"
120
+ @info.type.should == "SOCIAL"
121
+ end
122
+ it "should be easy to add a social entry" do
123
+ @info = Insightly::ContactInfo.social('TwitterID','economysizegeek','TwitterID')
124
+ @info.label.should == "TwitterID"
125
+ @info.subtype.should == "TwitterID"
126
+ @info.detail.should == "economysizegeek"
127
+ @info.type.should == "SOCIAL"
128
+ end
129
+ it "should be easy to add a linked in profile" do
130
+ @info = Insightly::ContactInfo.linked_in("http://www.linkedin.com/company/1499784")
131
+ @info.label.should == "LinkedInPublicProfileUrl"
132
+ @info.subtype.should == "LinkedInPublicProfileUrl"
133
+ @info.detail.should == "http://www.linkedin.com/company/1499784"
134
+ @info.type.should == "SOCIAL"
135
+ end
136
+
137
+
138
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insightly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dirk Elmendorf
@@ -167,6 +167,7 @@ files:
167
167
  - spec/unit/task_category_spec.rb
168
168
  - spec/unit/opportunity_category_spec.rb
169
169
  - spec/unit/team_member_spec.rb
170
+ - spec/unit/contact_info_spec.rb
170
171
  - spec/unit/opportunity_state_reason_spec.rb
171
172
  - spec/unit/address_spec.rb
172
173
  - spec/unit/relationship_spec.rb