go_import 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/bin/go-import +96 -0
  2. data/lib/go_import/csv_helper.rb +47 -0
  3. data/lib/go_import/email_helper.rb +10 -0
  4. data/lib/go_import/errors.rb +22 -0
  5. data/lib/go_import/excel_helper.rb +10 -0
  6. data/lib/go_import/global_phone.json +6571 -0
  7. data/lib/go_import/model/address.rb +61 -0
  8. data/lib/go_import/model/class_settings.rb +50 -0
  9. data/lib/go_import/model/coworker.rb +76 -0
  10. data/lib/go_import/model/coworker_reference.rb +33 -0
  11. data/lib/go_import/model/customfield.rb +87 -0
  12. data/lib/go_import/model/deal.rb +172 -0
  13. data/lib/go_import/model/deal_class_settings.rb +73 -0
  14. data/lib/go_import/model/deal_state.rb +15 -0
  15. data/lib/go_import/model/deal_status.rb +23 -0
  16. data/lib/go_import/model/deal_status_reference.rb +47 -0
  17. data/lib/go_import/model/deal_status_setting.rb +49 -0
  18. data/lib/go_import/model/documents.rb +51 -0
  19. data/lib/go_import/model/link.rb +70 -0
  20. data/lib/go_import/model/note.rb +97 -0
  21. data/lib/go_import/model/note_classification.rb +25 -0
  22. data/lib/go_import/model/organization.rb +219 -0
  23. data/lib/go_import/model/person.rb +151 -0
  24. data/lib/go_import/model/referencetosource.rb +46 -0
  25. data/lib/go_import/model/relation.rb +23 -0
  26. data/lib/go_import/model/rootmodel.rb +359 -0
  27. data/lib/go_import/model/settings.rb +61 -0
  28. data/lib/go_import/model/tag.rb +35 -0
  29. data/lib/go_import/model_helpers.rb +54 -0
  30. data/lib/go_import/phone_helper.rb +74 -0
  31. data/lib/go_import/roo_helper.rb +80 -0
  32. data/lib/go_import/serialize_helper.rb +186 -0
  33. data/lib/go_import/source.rb +87 -0
  34. data/lib/go_import/templating.rb +52 -0
  35. data/lib/go_import.rb +19 -0
  36. data/sources/csv/.gitignore +14 -0
  37. data/sources/csv/.go_import/runner.rb +62 -0
  38. data/sources/csv/Gemfile +5 -0
  39. data/sources/csv/Rakefile.rb +7 -0
  40. data/sources/csv/converter.rb +179 -0
  41. data/sources/csv/data/coworkers.csv +2 -0
  42. data/sources/csv/data/deals.csv +2 -0
  43. data/sources/csv/data/organizations.csv +2 -0
  44. data/sources/csv/data/persons.csv +2 -0
  45. data/sources/csv/spec/exporter_spec.rb +17 -0
  46. data/sources/csv/spec/sample_data/coworkers.csv +2 -0
  47. data/sources/csv/spec/sample_data/deals.csv +2 -0
  48. data/sources/csv/spec/sample_data/organizations.csv +2 -0
  49. data/sources/csv/spec/sample_data/persons.csv +2 -0
  50. data/sources/csv/spec/spec_helper.rb +30 -0
  51. data/sources/easy/.gitignore +14 -0
  52. data/sources/easy/.go_import/runner.rb +115 -0
  53. data/sources/easy/Export/readme.txt +6 -0
  54. data/sources/easy/Gemfile +5 -0
  55. data/sources/easy/Rakefile.rb +7 -0
  56. data/sources/easy/converter.rb +435 -0
  57. data/sources/easy/spec/exporter_spec.rb +10 -0
  58. data/sources/easy/spec/sample_data/Company.txt +649 -0
  59. data/sources/easy/spec/spec_helper.rb +30 -0
  60. data/sources/excel/.gitignore +14 -0
  61. data/sources/excel/.go_import/runner.rb +116 -0
  62. data/sources/excel/Gemfile +6 -0
  63. data/sources/excel/Rakefile.rb +7 -0
  64. data/sources/excel/converter.rb +130 -0
  65. data/sources/excel/spec/sample_data/sample.xlsx +0 -0
  66. data/sources/excel/spec/spec_helper.rb +26 -0
  67. data/sources/excel/spec/tomodel_spec.rb +18 -0
  68. data/sources/excel/template.xlsx +0 -0
  69. data/spec/address_spec.rb +49 -0
  70. data/spec/class_settings_spec.rb +37 -0
  71. data/spec/coworker_spec.rb +94 -0
  72. data/spec/custom_field_spec.rb +22 -0
  73. data/spec/deal_class_settings_spec.rb +104 -0
  74. data/spec/deal_spec.rb +182 -0
  75. data/spec/deal_status_reference_spec.rb +17 -0
  76. data/spec/documents_spec.rb +37 -0
  77. data/spec/helpers/csv_helper_spec.rb +29 -0
  78. data/spec/helpers/email_helper_spec.rb +32 -0
  79. data/spec/helpers/phone_helper_spec.rb +97 -0
  80. data/spec/helpers/roo_helper_spec.rb +10 -0
  81. data/spec/helpers/serialize_helper_spec.rb +249 -0
  82. data/spec/helpers/xsd_validate_spec.rb +55 -0
  83. data/spec/link_spec.rb +106 -0
  84. data/spec/note_spec.rb +110 -0
  85. data/spec/organization_spec.rb +151 -0
  86. data/spec/person_spec.rb +132 -0
  87. data/spec/rootmodel_spec.rb +371 -0
  88. data/spec/spec_helper.rb +30 -0
  89. data/spec/templating_spec.rb +12 -0
  90. metadata +306 -0
@@ -0,0 +1,61 @@
1
+ require 'iso_country_codes'
2
+ module GoImport
3
+ class Address
4
+ attr_accessor :street, :zip_code, :city, :country_code, :location
5
+ def serialize_variables
6
+ [ :street, :zip_code, :city, :country_code, :location].map {|p| {:id=>p,:type=>:string} }
7
+ end
8
+ include SerializeHelper
9
+ def initialize()
10
+ end
11
+
12
+ # What fields/rows on the class is supposed to be used by the Gem to generate the xml
13
+ # This method uses {#serialize_variables}. It also adds {#country_name} to be serialized
14
+ def get_import_rows
15
+ (serialize_variables+[{:id=>:country_name, :type=>:string}]).map do |p|
16
+ map_to_row p
17
+ end
18
+ end
19
+ # Used as a convenience in order to get country code from internally used {#country_code}
20
+ def country_name
21
+ if @country_code
22
+ IsoCountryCodes.find(@country_code).name
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
28
+ # Used as a convenience in order to map country name to the internal {#country_code}
29
+ def country_name=(name)
30
+ @country_code = case name
31
+ when nil
32
+ nil
33
+ when 'Sverige'
34
+ 'SE'
35
+ else
36
+ IsoCountryCodes.search_by_name(name).first.alpha2
37
+ end
38
+ end
39
+ # parses a line like "226 48 LUND" into its corresponding
40
+ # zipcode and city properties on the address
41
+ def parse_zip_and_address_se(line)
42
+ Address.parse_line_to_zip_and_address_se(line, self)
43
+ end
44
+
45
+ private
46
+ def self.parse_line_to_zip_and_address_se(line, address)
47
+ matched_zipcode = /^\d{3}\s?\d{2}/.match(line)
48
+ if matched_zipcode && matched_zipcode.length == 1
49
+ address.zip_code = matched_zipcode[0].strip()
50
+ matched_city = /\D*$/.match(line)
51
+ if matched_city && matched_city.length == 1
52
+ address.city = matched_city[0].strip()
53
+ return address
54
+ end
55
+ end
56
+ return nil
57
+ end
58
+
59
+
60
+ end
61
+ end
@@ -0,0 +1,50 @@
1
+ # Encoding: utf-8
2
+ module GoImport
3
+ class ClassSettings
4
+ include SerializeHelper
5
+ attr_reader :custom_fields
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [{:id => :custom_fields, :type => :custom_fields} ]
18
+ end
19
+
20
+ def serialize_name
21
+ "ClassSettings"
22
+ end
23
+
24
+ # Set custom field. If there is already an existing custom field, then it is overwritten.
25
+ def set_custom_field(obj)
26
+ @custom_fields = [] if @custom_fields.nil?
27
+
28
+ if obj.is_a?(CustomField)
29
+ field = obj
30
+ else
31
+ field = CustomField.new(obj)
32
+ end
33
+
34
+ if field.integration_id == "" && field.id == ""
35
+ raise InvalidCustomFieldError, "Custom field must have either id or integration_id"
36
+ end
37
+
38
+ index = @custom_fields.find_index do |custom_field|
39
+ custom_field.same_as?(field)
40
+ end
41
+ if index
42
+ @custom_fields.delete_at index
43
+ end
44
+
45
+ @custom_fields.push field
46
+
47
+ return field
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ module GoImport
3
+ class Coworker
4
+ include SerializeHelper
5
+ attr_accessor :id, :integration_id, :email, :first_name, :last_name, :direct_phone_number,
6
+ :mobile_phone_number, :home_phone_number
7
+
8
+ def initialize(opt = nil)
9
+ if opt != nil
10
+ serialize_variables.each do |myattr|
11
+ val = opt[myattr[:id]]
12
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
13
+ end
14
+ end
15
+ end
16
+
17
+ def serialize_variables
18
+ [
19
+ :id, :integration_id, :email, :first_name, :last_name,
20
+ :direct_phone_number, :mobile_phone_number, :home_phone_number
21
+ ].map {|p| { :id => p, :type => :string } }
22
+ end
23
+
24
+ def to_reference
25
+ reference = CoworkerReference.new
26
+ reference.id = @id
27
+ reference.integration_id = @integration_id
28
+ reference.heading = "#{@first_name} #{@last_name}".strip
29
+
30
+ return reference
31
+ end
32
+
33
+ def serialize_name
34
+ "Coworker"
35
+ end
36
+
37
+ def ==(that)
38
+ if that.nil?
39
+ return false
40
+ end
41
+
42
+ if that.is_a? Coworker
43
+ return @integration_id == that.integration_id
44
+ end
45
+
46
+ return false
47
+ end
48
+
49
+ def parse_name_to_firstname_lastname_se(name, when_missing = '')
50
+ if name.nil? or name.empty?
51
+ @first_name = when_missing
52
+ return
53
+ end
54
+
55
+ splitted = name.split(' ')
56
+ @first_name = splitted[0]
57
+ if splitted.length > 1
58
+ @last_name = splitted.drop(1).join(' ')
59
+ end
60
+ end
61
+
62
+ def to_email_chars(s)
63
+ s.tr " åäöèé", "-aaoee"
64
+ end
65
+
66
+ def guess_email(domain)
67
+ return '' if @last_name.nil? || @last_name.empty?
68
+ return '' if @first_name.nil? || @first_name.empty?
69
+
70
+ firstname = to_email_chars @first_name.downcase
71
+ lastname = to_email_chars @last_name.downcase
72
+ return "#{firstname}.#{lastname}@#{domain}"
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,33 @@
1
+ module GoImport
2
+ class CoworkerReference
3
+ include SerializeHelper
4
+ attr_accessor :id, :heading, :integration_id
5
+
6
+ def initialize(opt = nil)
7
+ if opt != nil
8
+ serialize_variables.each do |myattr|
9
+ val = opt[myattr[:id]]
10
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
11
+ end
12
+ end
13
+ end
14
+
15
+ def serialize_variables
16
+ [:id, :integration_id, :heading].map {|p| {:id => p, :type => :string} }
17
+ end
18
+
19
+ def serialize_name
20
+ "CoworkerReference"
21
+ end
22
+
23
+ def self.from_coworker(coworker)
24
+ if coworker.nil?
25
+ return nil
26
+ elsif coworker.is_a?(Coworker)
27
+ return coworker.to_reference
28
+ elsif coworker.is_a?(CoworkerReference)
29
+ return coworker
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,87 @@
1
+ module GoImport
2
+ class CustomFieldReference
3
+ include SerializeHelper, ModelWithIntegrationIdSameAs
4
+
5
+ attr_accessor :integration_id
6
+
7
+ def initialize(opt=nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [:integration_id].map {|p| { :id => p, :type => :string } }
18
+ end
19
+
20
+ def get_import_rows
21
+ serialize_variables.map do |p|
22
+ map_to_row p
23
+ end
24
+ end
25
+
26
+ def serialize_name
27
+ "CustomFieldReference"
28
+ end
29
+ end
30
+
31
+ class CustomField
32
+ include SerializeHelper, ModelWithIntegrationIdSameAs
33
+ attr_accessor :id, :integration_id, :title, :type
34
+
35
+ def initialize(opt=nil)
36
+ if opt != nil
37
+ serialize_variables.each do |myattr|
38
+ val = opt[myattr[:id]]
39
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
40
+ end
41
+ end
42
+ end
43
+
44
+ def serialize_variables
45
+ [:id, :integration_id, :title, :type].map {|p| { :id => p, :type => :string } }
46
+ end
47
+
48
+ def get_import_rows
49
+ serialize_variables.map do |p|
50
+ map_to_row p
51
+ end
52
+ end
53
+
54
+ def serialize_name
55
+ "CustomField"
56
+ end
57
+ end
58
+
59
+ class CustomValue
60
+ include SerializeHelper
61
+ attr_accessor :field, :value
62
+
63
+ def initialize(opt=nil)
64
+ if opt != nil
65
+ serialize_variables.each do |myattr|
66
+ val = opt[myattr[:id]]
67
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
68
+ end
69
+ end
70
+ end
71
+
72
+ def serialize_variables
73
+ [ { :id =>:field, :type => :custom_field_reference },
74
+ { :id =>:value, :type => :string }]
75
+ end
76
+
77
+ def get_import_rows
78
+ serialize_variables.map do |p|
79
+ map_to_row p
80
+ end
81
+ end
82
+
83
+ def serialize_name
84
+ "CustomValue"
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,172 @@
1
+ module GoImport
2
+ class DealReference
3
+ include SerializeHelper
4
+ attr_accessor :id, :integration_id
5
+ def serialize_variables
6
+ [ :id, :integration_id ].map { |prop| {:id => prop, :type => :string} }
7
+ end
8
+
9
+ def initialize(opt = nil)
10
+ if opt != nil
11
+ serialize_variables.each do |var|
12
+ value = opt[var[:id]]
13
+ instance_variable_set("@" + var[:id].to_s, value) if value != nil
14
+ end
15
+ end
16
+ end
17
+
18
+ def to_s
19
+ return "(#{id}, #{integration_id})"
20
+ end
21
+
22
+ def empty?
23
+ return !@integration_id && !@id
24
+ end
25
+
26
+ def self.from_deal(deal)
27
+ if deal.nil?
28
+ return nil
29
+ elsif deal.is_a?(Deal)
30
+ return deal.to_reference
31
+ elsif deal.is_a?(DealReference)
32
+ return deal
33
+ end
34
+ end
35
+ end
36
+
37
+ class Deal
38
+ include SerializeHelper, ModelHasCustomFields, ModelHasTags
39
+
40
+ # Get/set the deal's status. Statuses must be configured in
41
+ # LIME Go before the import.
42
+ attr_accessor :status
43
+
44
+ attr_accessor :id, :integration_id, :name, :description, :probability, :order_date
45
+
46
+ # you add custom values by using {#set_custom_value}
47
+ attr_reader :custom_values
48
+
49
+ attr_reader :customer, :responsible_coworker, :customer_contact, :value
50
+
51
+ def serialize_variables
52
+ [ :id, :integration_id, :name, :description, :probability, :value, :order_date ].map {
53
+ |p| {
54
+ :id => p,
55
+ :type => :string
56
+ }
57
+ } +
58
+ [
59
+ { :id => :customer, :type => :organization_reference },
60
+ { :id => :responsible_coworker, :type => :coworker_reference },
61
+ { :id => :customer_contact, :type => :person_reference },
62
+ { :id => :custom_values, :type => :custom_values },
63
+ { :id => :tags, :type => :tags },
64
+ { :id => :status, :type => :deal_status }
65
+ ]
66
+ end
67
+
68
+ def serialize_name
69
+ "Deal"
70
+ end
71
+
72
+ def initialize(opt = nil)
73
+ if !opt.nil?
74
+ serialize_variables.each do |myattr|
75
+ val = opt[myattr[:id]]
76
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
77
+ end
78
+ end
79
+ end
80
+
81
+ def to_s
82
+ return "deal[id=#{@id}, integration_id=#{@integration_id}]"
83
+ end
84
+
85
+ def to_reference
86
+ reference = DealReference.new
87
+ reference.id = @id
88
+ reference.integration_id = @integration_id
89
+ return reference
90
+ end
91
+
92
+ def validate
93
+ error = String.new
94
+
95
+ if @name.nil? || @name.empty?
96
+ error = "A name is required for deal.\n}"
97
+ end
98
+
99
+ if !@status.nil? && @status.status_reference.nil?
100
+ error = "#{error}\nStatus must have a status reference."
101
+ end
102
+
103
+ if !@status.nil? && !@status.status_reference.nil? && @status.status_reference.validate.length > 0
104
+ error = "#{error}\n#{@status.status_reference.validate}"
105
+ end
106
+
107
+ if error.length > 0
108
+ error = "#{error}\n#{serialize()}"
109
+ end
110
+
111
+ return error
112
+ end
113
+
114
+
115
+ def with_status
116
+ @status = DealStatus.new if @status.nil?
117
+ yield @status
118
+ end
119
+
120
+ # Sets the deal's status to the specifed status. The specifed
121
+ # status could be either a DealStatusSetting, a string or an
122
+ # integer. Use DealStatusSetting if you want to create new
123
+ # statuses during import (you will probably add the
124
+ # DealStatusSettings to the settings model). If the statuses
125
+ # already exists in the application use the status label
126
+ # (String) or id (Integer) here.
127
+ def status=(status)
128
+ @status = DealStatus.new if @status.nil?
129
+
130
+ @status.status_reference = DealStatusReference.from_deal_status(status)
131
+ end
132
+
133
+ def customer=(customer)
134
+ @customer = OrganizationReference.from_organization(customer)
135
+ end
136
+
137
+ def responsible_coworker=(coworker)
138
+ @responsible_coworker = CoworkerReference.from_coworker(coworker)
139
+ end
140
+
141
+ def customer_contact=(person)
142
+ @customer_contact = PersonReference.from_person(person)
143
+ end
144
+
145
+ def value=(value)
146
+ if value.nil?
147
+ @value = 0
148
+ else
149
+ # we have had some issues with LIME Easy imports where
150
+ # the value was in the format "357 000". We need to
151
+ # remove those spaces.
152
+ fixed_value = value.gsub(" ", "")
153
+
154
+ if is_integer?(fixed_value)
155
+ @value = fixed_value
156
+ elsif is_float?(fixed_value)
157
+ @value = fixed_value
158
+ else
159
+ raise InvalidValueError, value
160
+ end
161
+ end
162
+ end
163
+
164
+ def is_integer?(value)
165
+ true if Integer(value) rescue false
166
+ end
167
+
168
+ def is_float?(value)
169
+ true if Float(value) rescue false
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ module GoImport
3
+ class DealClassSettings < ClassSettings
4
+ attr_reader :statuses
5
+
6
+ def initialize(opt = nil)
7
+ @statuses = []
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ super() + [{:id => :statuses, :type => :statuses }]
18
+ end
19
+
20
+ def add_status(obj)
21
+ @statuses = [] if @statuses.nil?
22
+
23
+ if obj.is_a?(DealStatusSetting)
24
+ status = obj
25
+ else
26
+ status = DealStatusSetting.new(obj)
27
+ end
28
+
29
+ if status.label.nil? || status.label.empty?
30
+ raise InvalidDealStatusError, "Deal status must have a label"
31
+ end
32
+
33
+ if status.assessment.nil?
34
+ status.assessment = DealState::NotAnEndState
35
+ end
36
+
37
+ index = @statuses.find_index do |deal_status|
38
+ deal_status.same_as?(status)
39
+ end
40
+ if index
41
+ @statuses.delete_at index
42
+ end
43
+
44
+ @statuses.push status
45
+
46
+ return status
47
+ end
48
+
49
+ def find_status_by_label(label)
50
+ return nil if @statuses.nil? || label.nil?
51
+
52
+ return @statuses.find do |status|
53
+ !status.label.nil? && status.label.casecmp(label) == 0
54
+ end
55
+ end
56
+
57
+ def find_status_by_integration_id(integration_id)
58
+ return nil if @statuses.nil? || integration_id.nil?
59
+
60
+ return @statuses.find do |status|
61
+ !status.integration_id.nil? && status.integration_id.casecmp(integration_id) == 0
62
+ end
63
+ end
64
+
65
+ def find_status_by_id(id)
66
+ return nil if @statuses.nil?
67
+
68
+ return @statuses.find do |status|
69
+ !status.id.nil? && status.id.casecmp(integration_id) == 0
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ module GoImport
2
+ module DealState
3
+ # This is the default, a deal with a status with this state is
4
+ # currently being worked on.
5
+ NotAnEndState = 0
6
+
7
+ # The deal has reached a positive end state, eg we have won
8
+ # the deal.
9
+ PositiveEndState = 1
10
+
11
+ # The deal has reached a negative end state, eg we have lost
12
+ # the deal.
13
+ NegativeEndState = -1
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module GoImport
2
+ class DealStatus
3
+ include SerializeHelper
4
+
5
+ attr_accessor :id, :date, :status_reference, :note
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [ :id, :label, :note ].map{ |p| { :id => p, :type => :string } } +
18
+ [ :date ].map { |p| { :id => p, :type => :date } } +
19
+ [ :status_reference ].map { |p| { :id => p, :type => :deal_status_reference } }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+ module GoImport
2
+ class DealStatusReference
3
+ include SerializeHelper
4
+
5
+ attr_accessor :label, :integration_id
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [:integration_id, :label].map {|p| {:id => p, :type => :string} }
18
+ end
19
+
20
+ def serialize_name
21
+ "StatusReference"
22
+ end
23
+
24
+ # Converts the specifed status to a status reference.
25
+ def self.from_deal_status(deal_status)
26
+ if deal_status.nil?
27
+ return nil
28
+ elsif deal_status.is_a?(DealStatusSetting)
29
+ return deal_status.to_reference
30
+ elsif deal_status.is_a?(String)
31
+ return DealStatusReference.new({:label => deal_status, :integration_id => deal_status})
32
+ end
33
+
34
+ raise InvalidDealStatusError
35
+ end
36
+
37
+ def validate
38
+ error = ""
39
+
40
+ if (@label.nil? || @label.empty?) && (@integration_id.nil? || @integration_id.empty?)
41
+ error = "label and integration_id can't all be nil or empty"
42
+ end
43
+
44
+ return error
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ module GoImport
3
+ class DealStatusSetting
4
+ include SerializeHelper
5
+
6
+ attr_accessor :id, :integration_id, :label, :assessment
7
+
8
+ def initialize(opt = nil)
9
+ if opt != nil
10
+ serialize_variables.each do |myattr|
11
+ val = opt[myattr[:id]]
12
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
13
+ end
14
+ end
15
+ end
16
+
17
+ def serialize_variables
18
+ [ :id, :integration_id, :label, :assessment ].map{ |p| { :id => p, :type => :string } }
19
+ end
20
+
21
+ def serialize_name
22
+ "DealStatus"
23
+ end
24
+
25
+ def to_reference()
26
+ reference = DealStatusReference.new
27
+ reference.label = @label
28
+ reference.integration_id = @integration_id
29
+
30
+ return reference
31
+ end
32
+
33
+ def same_as?(other)
34
+ if @integration_id != nil && @integration_id == other.integration_id
35
+ return true
36
+ end
37
+
38
+ if @id != nil && @id == other.id
39
+ return true
40
+ end
41
+
42
+ if @label != nil && @label == other.label
43
+ return true
44
+ end
45
+
46
+ return false
47
+ end
48
+ end
49
+ end