insightly 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,16 @@
1
1
  module Insightly
2
2
  class TaskLink < ReadOnly
3
3
  self.url_base ="TaskLinks"
4
+ api_field "TASK_LINK_ID",
5
+ "PROJECT_ID",
6
+ "CONTACT_ID",
7
+ "OPPORTUNITY_ID",
8
+ "ORGANISATION_ID",
9
+ "TASK_ID"
4
10
 
5
- def opportunity_id
6
- @data["OPPORTUNITY_ID"]
7
- end
8
- def task_id
9
- @data["TASK_ID"]
11
+
12
+ def remote_id
13
+ self.task_link_id
10
14
  end
11
15
 
12
16
  def self.search_by_opportunity_id(opportunity_id)
@@ -18,5 +22,24 @@ module Insightly
18
22
  end
19
23
  list
20
24
  end
25
+
26
+ def self.add_contact(id)
27
+ item = TaskLink.new
28
+ item.contact_id = id
29
+ item
30
+ end
31
+
32
+ def self.add_opportunity(id)
33
+ item = TaskLink.new
34
+ item.opportunity_id = id
35
+
36
+ item
37
+ end
38
+
39
+ def self.add_organisation(id)
40
+ item = TaskLink.new
41
+ item.organisation_id = id
42
+ item
43
+ end
21
44
  end
22
45
  end
@@ -0,0 +1,14 @@
1
+ module Insightly
2
+ module TaskLinkHelper
3
+ def task_links
4
+ @data["TASKLINKS"].collect {|a| Insightly::TaskLink.build(a)}
5
+ end
6
+ def task_links=(list)
7
+ @data["TASKLINKS"] = list.collect {|a| fix_for_link(a).remote_data}
8
+ end
9
+ def add_task_link(link)
10
+ @data["TASKLINKS"] << fix_for_link(link).remote_data
11
+ true
12
+ end
13
+ end
14
+ end
@@ -3,8 +3,8 @@
3
3
  module Insightly
4
4
  module Version
5
5
  Major = 0
6
- Minor = 1
7
- Tiny = 8
6
+ Minor = 2
7
+ Tiny = 0
8
8
  String = "#{Major}.#{Minor}.#{Tiny}"
9
9
  end
10
10
  end
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::Address do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+ @address = Insightly::Address.build({
7
+ "ADDRESS_ID" => 1,
8
+ "ADDRESS_TYPE" => "Work",
9
+ "STREET" => "123 Main St.",
10
+ "CITY" => "San Antonio",
11
+ "STATE" => "TX",
12
+ "POSTCODE" => "78216",
13
+ "COUNTRY" => "US"
14
+ })
15
+ end
16
+ it "should be able to build an address from data" do
17
+ data = {
18
+ "ADDRESS_ID" => 1,
19
+ "ADDRESS_TYPE" => "Work",
20
+ "STREET" => "123 Main St.",
21
+ "CITY" => "San Antonio",
22
+ "STATE" => "TX",
23
+ "POSTCODE" => "78216",
24
+ "COUNTRY" => "US"
25
+ }
26
+ @address = Insightly::Address.build(data)
27
+
28
+ @address.remote_data.should == data
29
+ end
30
+ it "should be able to retrieve the data as an array" do
31
+ @address.remote_data["ADDRESS_ID"].should == 1
32
+ end
33
+ it "should be able to convert to json" do
34
+ @address.to_json.should == @address.remote_data.to_json
35
+ end
36
+
37
+ it "should know if two addresses are equal" do
38
+ @address2 = Insightly::Address.build(@address.remote_data.clone)
39
+ @address2.should == @address
40
+ @address.country = nil
41
+ @address2.should_not == @address
42
+ end
43
+ it "should know if it is the same address" do
44
+ @address2 = Insightly::Address.build(@address.remote_data.clone)
45
+ @address2.should be_same_address(@address)
46
+ @address2.address_id = 2
47
+ @address2.should be_same_address(@address)
48
+ @address.country = "UK"
49
+ @address2.should_not be_same_address(@address)
50
+
51
+ end
52
+ it "should have accessor for address_id" do
53
+ @address.address_id = 2
54
+ @address.address_id.should == 2
55
+ end
56
+ it "should have an accessor for address type" do
57
+ @address.address_type = "Home"
58
+ @address.address_type.should == "Home"
59
+ end
60
+ it "should have an accessor for street" do
61
+ @address.street = "432 Other St"
62
+ @address.street.should == "432 Other St"
63
+ end
64
+ it "should have an accessor for city" do
65
+ @address.city = "Miami"
66
+ @address.city.should == "Miami"
67
+ end
68
+ it "should have an accessor for state" do
69
+ @address.state = "FL"
70
+ @address.state.should == "FL"
71
+ end
72
+ it "should have an accessor for postcode" do
73
+ @address.postcode = 123456
74
+ @address.postcode.should == 123456
75
+ end
76
+ it "should have an accessor for country" do
77
+ @address.country = "UK"
78
+ @address.country.should == "UK"
79
+ end
80
+
81
+ end
@@ -0,0 +1,255 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::Contact do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+
7
+ @contact = Insightly::Contact.build({"CONTACT_ID" => 1234567,
8
+ "SALUTATION" => nil,
9
+ "FIRST_NAME" => "John",
10
+ "LAST_NAME" => "Doe",
11
+ "BACKGROUND" => nil,
12
+ "CONTACT_FIELD_1" => nil,
13
+ "CONTACT_FIELD_2" => nil,
14
+ "CONTACT_FIELD_3" => nil,
15
+ "CONTACT_FIELD_4" => nil,
16
+ "CONTACT_FIELD_5" => nil,
17
+ "CONTACT_FIELD_6" => nil,
18
+ "CONTACT_FIELD_7" => nil,
19
+ "CONTACT_FIELD_8" => nil,
20
+ "CONTACT_FIELD_9" => nil,
21
+ "CONTACT_FIELD_10" => nil,
22
+ "DATE_CREATED_UTC" => "2012-03-13 05:19:10",
23
+ "DATE_UPDATED_UTC" => "2012-03-13 05:19:10",
24
+ " ADDRESSES" => [],
25
+ "CONTACTINFOS" => [{
26
+ "CONTACT_INFO_ID" => 7894561,
27
+ "TYPE" => "EMAIL",
28
+ "SUBTYPE" => nil,
29
+ "LABEL" => "Home",
30
+ "DETAIL" => "johndoe@insight.ly"
31
+ }],
32
+ "VISIBLE_TO" => "EVERYONE",
33
+ "VISIBLE_TEAM_ID" => nil
34
+ })
35
+ # @task_links = Insightly::TaskLink.all
36
+ # d = 1
37
+ end
38
+ it "should have a url base" do
39
+ Insightly::Contact.new.url_base.should == "Contacts"
40
+ end
41
+ it "should know the contact id" do
42
+
43
+ end
44
+ it " should know the contact id " do
45
+ @contact.contact_id.should == 1234567
46
+ end
47
+ it "should know the remote id " do
48
+ @contact.remote_id.should == @contact.contact_id
49
+ end
50
+
51
+ # it "should be able to create an contact" do
52
+ # @contact = Insightly::Contact.new
53
+ #
54
+ # @contact.visible_to = "EVERYONE"
55
+ # @contact.first_name = "000 Dummy"
56
+ # @contact.last_name = "Test Contact"
57
+ # @contact.background = "This contact was created for test purposes and can be deleted."
58
+ #
59
+ # @contact.save
60
+ #
61
+ # @new_contact = Insightly::Contact.new(@contact.remote_id)
62
+ # @new_contact.last_name.should == @contact.last_name
63
+ #end
64
+ context "addresses" do
65
+ before(:each) do
66
+ @contact = Insightly::Contact.new(20315449)
67
+ @contact.addresses = []
68
+ @contact.save
69
+
70
+ @address = Insightly::Address.new
71
+ @address.address_type = "Work"
72
+ @address.street = "123 Main St"
73
+ @address.city = "Indianpolis"
74
+ @address.state = "IN"
75
+ @address.postcode = "46112"
76
+ @address.country = "US"
77
+ end
78
+ it "should allow you to update an address" do
79
+ @contact.addresses.should == []
80
+ @contact.add_address(@address)
81
+
82
+ @contact.save
83
+ @address = @contact.addresses.first
84
+ @address.state = "TX"
85
+ @contact.addresses = [@address]
86
+ @contact.addresses.length.should == 1
87
+
88
+ @contact.save
89
+
90
+ @contact.reload
91
+
92
+ @contact.addresses.length.should == 1
93
+ @contact.addresses.first.state.should == "TX"
94
+ end
95
+ it "should allow you to add an address" do
96
+
97
+
98
+ @contact.addresses.should == []
99
+ @contact.add_address(@address)
100
+
101
+ @contact.save
102
+ @contact.reload
103
+ @contact.addresses.length.should == 1
104
+ @contact.addresses.first.street.should == "123 Main St"
105
+ end
106
+ it "should allow you to remove an address" do
107
+
108
+ @contact.addresses.should == []
109
+ @contact.add_address(@address)
110
+
111
+ @contact.save
112
+ @contact.addresses = []
113
+ @contact.save
114
+ @contact.reload
115
+ @contact.addresses.length.should == 0
116
+
117
+ end
118
+ it "should allow you to clear all addresses" do
119
+ @contact.addresses.should == []
120
+ @contact.add_address(@address)
121
+
122
+ @contact.save
123
+ @contact.addresses = []
124
+ @contact.save
125
+ @contact.reload
126
+ @contact.addresses.length.should == 0
127
+ end
128
+
129
+ it "should not add an address if the same address is already on the organization" do
130
+
131
+ @contact.addresses.should == []
132
+ @contact.add_address(@address)
133
+
134
+ @contact.add_address(@address)
135
+ @contact.addresses.length.should == 1
136
+ end
137
+ end
138
+ context "contact_infos" do
139
+ before(:each) do
140
+ @contact = Insightly::Contact.new(20315449)
141
+ @contact.contact_infos = []
142
+ @contact.save
143
+
144
+ @contact_info = Insightly::ContactInfo.new
145
+ @contact_info.type = "PHONE"
146
+ @contact_info.label = "Work"
147
+ @contact_info.subtype = nil
148
+ @contact_info.detail = "bob@aol.com"
149
+
150
+ end
151
+ it "should allow you to update an contact_info" do
152
+ @contact.contact_infos.should == []
153
+ @contact.add_contact_info(@contact_info)
154
+
155
+ @contact.save
156
+ @contact_info.detail = "bobroberts@aol.com"
157
+ @contact.contact_infos = [@contact_info]
158
+ @contact.save
159
+ @contact.reload
160
+ @contact.contact_infos.length.should == 1
161
+ @contact.contact_infos.first.detail.should == "bobroberts@aol.com"
162
+ end
163
+ it "should allow you to add an contact_info" do
164
+
165
+
166
+ @contact.contact_infos.should == []
167
+ @contact.add_contact_info(@contact_info)
168
+
169
+ @contact.save
170
+ @contact.reload
171
+ @contact.contact_infos.length.should == 1
172
+ @contact.contact_infos.first.detail.should == "bob@aol.com"
173
+ end
174
+ it "should allow you to remove an contact_info" do
175
+
176
+ @contact.contact_infos.should == []
177
+ @contact.add_contact_info(@contact_info)
178
+
179
+ @contact.save
180
+ @contact.contact_infos = []
181
+ @contact.save
182
+ @contact.reload
183
+ @contact.contact_infos.length.should == 0
184
+
185
+ end
186
+ it "should allow you to clear all contact_infos" do
187
+ @contact.contact_infos.should == []
188
+ @contact.add_contact_info(@contact_info)
189
+
190
+ @contact.save
191
+ @contact.contact_infos = []
192
+ @contact.save
193
+ @contact.reload
194
+ @contact.contact_infos.length.should == 0
195
+ end
196
+ end
197
+ context "Links" do
198
+ before(:each) do
199
+ @contact = Insightly::Contact.new(20315449)
200
+ @contact.links = []
201
+ @contact.save
202
+
203
+
204
+ @link = Insightly::Link.add_organisation(8936117, "Employeer", "Handles payment")
205
+ # @link = Insightly::Link.add_opportunity(968613,"Janitor", "Recent Hire")
206
+ end
207
+ it "should allow you to update an link" do
208
+ @contact.links.should == []
209
+ @contact.add_link(@link)
210
+
211
+ @contact.save
212
+ @link = @contact.links.first
213
+ @link.details = "Old Veteran"
214
+ @contact.links = [@link]
215
+ @contact.save
216
+ @contact.reload
217
+ @contact.links.length.should == 1
218
+ @contact.links.first.details.should == "Old Veteran"
219
+ end
220
+ it "should allow you to add an link" do
221
+
222
+
223
+ @contact.links.should == []
224
+ @contact.add_link(@link)
225
+ @contact.add_link(@link)
226
+ @contact.links.length.should == 2
227
+ @contact.save
228
+ @contact.reload
229
+ @contact.links.length.should == 1
230
+ @contact.links.first.details.should == "Handles payment"
231
+ end
232
+ it "should allow you to remove an link" do
233
+
234
+ @contact.links.should == []
235
+ @contact.add_link(@link)
236
+
237
+ @contact.save
238
+ @contact.links = []
239
+ @contact.save
240
+ @contact.reload
241
+ @contact.links.length.should == 0
242
+
243
+ end
244
+ it "should allow you to clear all links" do
245
+ @contact.links.should == []
246
+ @contact.add_link(@link)
247
+
248
+ @contact.save
249
+ @contact.links = []
250
+ @contact.save
251
+ @contact.reload
252
+ @contact.links.length.should == 0
253
+ end
254
+ end
255
+ end
@@ -0,0 +1,98 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::Link do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+ @link = Insightly::Link.build({
7
+ "LINK_ID" => 1,
8
+ "ROLE" => "Manager",
9
+ "DETAILS" => "Added 2 weeks ago",
10
+ "CONTACT_ID" => 100,
11
+
12
+ })
13
+ end
14
+ it "should be able to build an link from data" do
15
+ data = {
16
+ "LINK_ID" => 1,
17
+ "ROLE" => "Manager",
18
+ "DETAILS" => "Added 2 weeks ago",
19
+ "CONTACT_ID" => 100,
20
+
21
+ }
22
+ @link = Insightly::Link.build(data)
23
+
24
+ @link.remote_data.should == data
25
+ end
26
+ it "should be able to retrieve the data as an array" do
27
+ @link.remote_data["LINK_ID"].should == 1
28
+ end
29
+ it "should be able to convert to json" do
30
+ @link.to_json.should == @link.remote_data.to_json
31
+ end
32
+
33
+ it "should know if two linkes are equal" do
34
+ @link2 = Insightly::Link.build(@link.remote_data.clone)
35
+ @link2.should == @link
36
+ @link.role = nil
37
+ @link2.should_not == @link
38
+ end
39
+
40
+ it "should have accessor for link_id" do
41
+ @link.link_id = 2
42
+ @link.link_id.should == 2
43
+ end
44
+ it "should have accessor for project_id" do
45
+ @link.project_id = 2
46
+ @link.project_id.should == 2
47
+ end
48
+ it "should have accessor for contact_id" do
49
+ @link.contact_id = 2
50
+ @link.contact_id.should == 2
51
+ end
52
+ it "should have accessor for opportunity_id" do
53
+ @link.opportunity_id = 2
54
+ @link.opportunity_id.should == 2
55
+ end
56
+ it "should have accessor for organisation_id" do
57
+ @link.organisation_id = 2
58
+ @link.organisation_id.should == 2
59
+ end
60
+ it "should have accessor for role" do
61
+ @link.role = "Worker"
62
+ @link.role.should == "Worker"
63
+ end
64
+ it "should have accessor for details" do
65
+ @link.details = "New hire"
66
+ @link.details.should == "New hire"
67
+ end
68
+ it "should make it easy to add a contact" do
69
+ @link = Insightly::Link.add_contact(100,"Consultant", "Charges a lot!")
70
+ @link.contact_id.should == 100
71
+ @link.details.should == "Charges a lot!"
72
+ @link.role.should == "Consultant"
73
+ @link.project_id.should be_nil
74
+ @link.opportunity_id.should be_nil
75
+ @link.organisation_id.should be_nil
76
+
77
+ end
78
+ it "should make it easy to add an opportunity" do
79
+ @link = Insightly::Link.add_opportunity(100,"Big Sale", "Quaterly Project")
80
+ @link.opportunity_id.should == 100
81
+ @link.details.should == "Quaterly Project"
82
+ @link.role.should == "Big Sale"
83
+ @link.project_id.should be_nil
84
+ @link.contact_id.should be_nil
85
+ @link.organisation_id.should be_nil
86
+
87
+ end
88
+ it "should make it easy to add an organisation" do
89
+ @link = Insightly::Link.add_organisation(100,"Walmart", "Low Prices")
90
+ @link.organisation_id.should == 100
91
+ @link.details.should == "Low Prices"
92
+ @link.role.should == "Walmart"
93
+ @link.project_id.should be_nil
94
+ @link.contact_id.should be_nil
95
+ @link.opportunity_id.should be_nil
96
+
97
+ end
98
+ end