insightly 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.
@@ -3,6 +3,8 @@ module Insightly
3
3
  include Insightly::AddressHelper
4
4
  include Insightly::ContactInfoHelper
5
5
  include Insightly::LinkHelper
6
+ include Insightly::TagHelper
7
+
6
8
  self.url_base = "Contacts"
7
9
  CUSTOM_FIELD_PREFIX = "CONTACT_FIELD"
8
10
  api_field "CONTACT_ID",
@@ -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,15 @@
1
+ module Insightly
2
+ class OpportunityCategory < ReadOnly
3
+ self.url_base = "OpportunityCategories"
4
+ api_field "CATEGORY_ID",
5
+ "ACTIVE",
6
+ "BACKGROUND_COLOR",
7
+ "CATEGORY_NAME"
8
+
9
+ def remote_id
10
+ self.category_id
11
+ end
12
+
13
+
14
+ end
15
+ end
@@ -3,6 +3,8 @@ module Insightly
3
3
  include Insightly::AddressHelper
4
4
  include Insightly::ContactInfoHelper
5
5
  include Insightly::LinkHelper
6
+ include Insightly::TagHelper
7
+
6
8
  self.url_base = "Organisations"
7
9
  CUSTOM_FIELD_PREFIX = "ORGANISATION_FIELD"
8
10
  api_field "ORGANISATION_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,15 @@
1
+ module Insightly
2
+ class TaskCategory < ReadOnly
3
+ self.url_base = "TaskCategories"
4
+ api_field "CATEGORY_ID",
5
+ "ACTIVE",
6
+ "BACKGROUND_COLOR",
7
+ "CATEGORY_NAME"
8
+
9
+ def remote_id
10
+ self.category_id
11
+ end
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Insightly
2
+ class TeamMember < ReadOnly
3
+ self.url_base = "TeamMembers"
4
+ api_field "MEMBER_TEAM_ID",
5
+ "TEAM_ID",
6
+ "MEMBER_USER_ID",
7
+ "PERMISSION_ID"
8
+
9
+ def remote_id
10
+ self.team_id
11
+ end
12
+ end
13
+ 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
@@ -4,7 +4,7 @@ module Insightly
4
4
  module Version
5
5
  Major = 0
6
6
  Minor = 2
7
- Tiny = 0
7
+ Tiny = 1
8
8
  String = "#{Major}.#{Minor}.#{Tiny}"
9
9
  end
10
10
  end
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