insightly 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/lib/insightly/contact.rb +2 -0
- data/lib/insightly/country.rb +22 -0
- data/lib/insightly/currency.rb +23 -0
- data/lib/insightly/custom_field.rb +21 -0
- data/lib/insightly/opportunity.rb +1 -1
- data/lib/insightly/opportunity_category.rb +15 -0
- data/lib/insightly/organisation.rb +2 -0
- data/lib/insightly/relationship.rb +16 -0
- data/lib/insightly/tag.rb +44 -0
- data/lib/insightly/tag_helper.rb +15 -0
- data/lib/insightly/task_category.rb +15 -0
- data/lib/insightly/team_member.rb +13 -0
- data/lib/insightly/user.rb +46 -0
- data/lib/insightly/version.rb +1 -1
- data/lib/insightly.rb +10 -0
- data/spec/unit/contact_spec.rb +226 -162
- data/spec/unit/country_spec.rb +49 -0
- data/spec/unit/currency_spec.rb +53 -0
- data/spec/unit/custom_field_spec.rb +46 -0
- data/spec/unit/opportunity_category_spec.rb +50 -0
- data/spec/unit/opportunity_spec.rb +152 -90
- data/spec/unit/organisation_spec.rb +234 -171
- data/spec/unit/relationship_spec.rb +42 -0
- data/spec/unit/tag_spec.rb +70 -0
- data/spec/unit/task_category_spec.rb +52 -0
- data/spec/unit/team_member_spec.rb +36 -0
- data/spec/unit/user_spec.rb +165 -0
- metadata +62 -43
data/README.md
CHANGED
@@ -57,4 +57,12 @@ Organisation? Organization
|
|
57
57
|
===========
|
58
58
|
|
59
59
|
The documentation for Insight.ly the mixes the use of Organization and Organisation. Insight.ly spells it Organisation in urls and in the API - so we
|
60
|
-
only use that spelling in the library.
|
60
|
+
only use that spelling in the library.
|
61
|
+
|
62
|
+
|
63
|
+
Custom Fields vs Tags
|
64
|
+
=========
|
65
|
+
|
66
|
+
Insight.ly supports both custom fields (up to 10 on Opportunities, Organisations, and Contacts). Opportunities, Organisations,
|
67
|
+
Contacts also support tags. What is the difference? Custom fields allow you to put data on the item. This data shows up when you look
|
68
|
+
at the details page of that record. Tags show up in the summary list, and also allow you to search/sort by.
|
data/lib/insightly/contact.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Insightly
|
2
|
+
class Country < ReadOnly
|
3
|
+
self.url_base = "Countries"
|
4
|
+
api_field "COUNTRY_NAME"
|
5
|
+
|
6
|
+
def build(data)
|
7
|
+
if data.respond_to? :keys
|
8
|
+
@data = data
|
9
|
+
else
|
10
|
+
@data = {"COUNTRY_NAME" => data}
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
def self.us
|
15
|
+
self.build("United States")
|
16
|
+
end
|
17
|
+
def self.canada
|
18
|
+
self.build("Canada")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Insightly
|
2
|
+
class Currency < ReadOnly
|
3
|
+
self.url_base = "Currencies"
|
4
|
+
api_field "CURRENCY_CODE",
|
5
|
+
"CURRENCY_SYMBOL"
|
6
|
+
|
7
|
+
def build(data)
|
8
|
+
if data.respond_to? :keys
|
9
|
+
@data = data
|
10
|
+
else
|
11
|
+
@data = {"CURRENCY_CODE" => data, "CURRENCY_SYMBOL" => "$"}
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
def self.us
|
16
|
+
self.build("USD")
|
17
|
+
end
|
18
|
+
def self.canada
|
19
|
+
self.build("CAD")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#METODO add better handling for CUSTOM_FIELD_OPTIONS
|
2
|
+
module Insightly
|
3
|
+
class CustomField < ReadOnly
|
4
|
+
self.url_base = "CustomFields"
|
5
|
+
api_field "CUSTOM_FIELD_ID",
|
6
|
+
"FIELD_NAME",
|
7
|
+
"FIELD_HELP_TEXT",
|
8
|
+
"CUSTOM_FIELD_OPTIONS",
|
9
|
+
"ORDER_ID",
|
10
|
+
"FIELD_TYPE",
|
11
|
+
"FIELD_FOR"
|
12
|
+
def initialize(id = nil)
|
13
|
+
@data = {"CUSTOM_FIELD_OPTIONS" = []}
|
14
|
+
load(id) if id
|
15
|
+
end
|
16
|
+
def remote_id
|
17
|
+
self.custom_field_id
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Insightly
|
2
2
|
class Opportunity < ReadWrite
|
3
3
|
include Insightly::LinkHelper
|
4
|
+
include Insightly::TagHelper
|
4
5
|
self.url_base = "Opportunities"
|
5
6
|
CUSTOM_FIELD_PREFIX = "OPPORTUNITY_FIELD"
|
6
7
|
api_field "OPPORTUNITY_FIELD_10",
|
@@ -23,7 +24,6 @@ module Insightly
|
|
23
24
|
"PIPELINE_ID",
|
24
25
|
"CATEGORY_ID",
|
25
26
|
"PROBABILITY",
|
26
|
-
"TAGS",
|
27
27
|
"IMAGE_URL",
|
28
28
|
"BID_AMOUNT",
|
29
29
|
"VISIBLE_TEAM_ID",
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Insightly
|
2
|
+
class Relationship < ReadOnly
|
3
|
+
self.url_base = "Relationships"
|
4
|
+
api_field "RELATIONSHIP_ID",
|
5
|
+
"FOR_ORGANISATIONS",
|
6
|
+
"FOR_CONTACTS",
|
7
|
+
"REVERSE_TITLE",
|
8
|
+
"FORWARD",
|
9
|
+
"REVERSE",
|
10
|
+
"FORWARD_TITLE"
|
11
|
+
|
12
|
+
def remote_id
|
13
|
+
self.relationship_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Insightly
|
2
|
+
class Tag < ReadOnly
|
3
|
+
self.url_base = "Tags"
|
4
|
+
api_field "TAG_NAME"
|
5
|
+
|
6
|
+
def build(data)
|
7
|
+
if data.respond_to? :keys
|
8
|
+
@data = data
|
9
|
+
else
|
10
|
+
@data = {"TAG_NAME" => data}
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
def self.contact_tags
|
15
|
+
|
16
|
+
self.tags_by_type("Contacts")
|
17
|
+
|
18
|
+
end
|
19
|
+
def self.organisation_tags
|
20
|
+
self.tags_by_type("Organisations")
|
21
|
+
|
22
|
+
end
|
23
|
+
def self.opportunity_tags
|
24
|
+
self.tags_by_type("Opportunities")
|
25
|
+
|
26
|
+
end
|
27
|
+
def self.project_tags
|
28
|
+
self.tags_by_type("Projects")
|
29
|
+
end
|
30
|
+
def self.email_tags
|
31
|
+
self.tags_by_type("Emails")
|
32
|
+
|
33
|
+
end
|
34
|
+
def self.tags_by_type(type)
|
35
|
+
item = self.new
|
36
|
+
list = []
|
37
|
+
item.get_collection("#{item.url_base}/#{type}").each do |d|
|
38
|
+
list << self.new.build(d)
|
39
|
+
end
|
40
|
+
list
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Insightly
|
2
|
+
module TagHelper
|
3
|
+
def tags
|
4
|
+
@data["TAGS"].collect {|a| Insightly::Tag.build(a)}
|
5
|
+
end
|
6
|
+
def tags=(list)
|
7
|
+
@data["TAGS"] = list.collect {|a| a.remote_data}
|
8
|
+
end
|
9
|
+
def add_tag(tag)
|
10
|
+
@data["TAGS"] ||= []
|
11
|
+
@data["TAGS"] << tag.remote_data
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Insightly
|
2
|
+
class User < ReadOnly
|
3
|
+
self.url_base = "Users"
|
4
|
+
api_field "DATE_UPDATED_UTC",
|
5
|
+
"ACTIVE",
|
6
|
+
"TIMEZONE_ID",
|
7
|
+
"DATE_CREATED_UTC",
|
8
|
+
"EMAIL_ADDRESS",
|
9
|
+
"ACCOUNT_OWNER",
|
10
|
+
"CONTACT_ID",
|
11
|
+
"USER_ID",
|
12
|
+
"ADMINISTRATOR",
|
13
|
+
"LAST_NAME",
|
14
|
+
"FIRST_NAME"
|
15
|
+
|
16
|
+
def remote_id
|
17
|
+
self.user_id
|
18
|
+
end
|
19
|
+
def self.find_all_by_email(email)
|
20
|
+
User.all.collect {|x| x if x.email_address && x.email_address.match(email)}.compact
|
21
|
+
end
|
22
|
+
def self.find_by_email(email)
|
23
|
+
User.all.each do |x|
|
24
|
+
return x if x.email_address && x.email_address.match(email)
|
25
|
+
end
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
def self.find_all_by_name(name)
|
29
|
+
User.all.collect {|x| x if x.name && x.name.match(name) }.compact
|
30
|
+
|
31
|
+
end
|
32
|
+
def self.find_by_name(name)
|
33
|
+
User.all.collect do |x|
|
34
|
+
return x if x.name && x.name.match(name)
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
def name
|
39
|
+
"#{self.first_name} #{self.last_name}".strip
|
40
|
+
end
|
41
|
+
def last_name_first
|
42
|
+
result = "#{self.last_name},#{self.first_name}".strip
|
43
|
+
result == "," ? "" : result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/insightly/version.rb
CHANGED
data/lib/insightly.rb
CHANGED
@@ -8,6 +8,7 @@ require 'insightly/address_helper'
|
|
8
8
|
require 'insightly/contact_info_helper'
|
9
9
|
require 'insightly/link_helper'
|
10
10
|
require 'insightly/task_link_helper'
|
11
|
+
require 'insightly/tag_helper'
|
11
12
|
|
12
13
|
|
13
14
|
require 'insightly/base'
|
@@ -24,4 +25,13 @@ require 'insightly/opportunity_state_reason'
|
|
24
25
|
require 'insightly/opportunity'
|
25
26
|
require 'insightly/organisation'
|
26
27
|
require "insightly/link"
|
28
|
+
require "insightly/tag"
|
29
|
+
require "insightly/user"
|
30
|
+
require "insightly/country"
|
31
|
+
require "insightly/currency"
|
32
|
+
require "insightly/team_member"
|
33
|
+
require "insightly/relationship"
|
34
|
+
require "insightly/opportunity_category"
|
35
|
+
require "insightly/task_category"
|
36
|
+
require "insightly/custom_field"
|
27
37
|
|