fruit_to_lime 0.6.5 → 0.6.6
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/lib/fruit_to_lime/model/address.rb +0 -3
- data/lib/fruit_to_lime/model/coworker_reference.rb +0 -3
- data/lib/fruit_to_lime/model/customfield.rb +6 -3
- data/lib/fruit_to_lime/model/note.rb +0 -3
- data/lib/fruit_to_lime/model/organization.rb +37 -27
- data/lib/fruit_to_lime/model/person.rb +24 -19
- data/lib/fruit_to_lime/model/sourceref.rb +4 -7
- data/lib/fruit_to_lime/serialize_helper.rb +4 -31
- data/spec/helpers/serialize_helper_spec.rb +45 -27
- data/spec/person_spec.rb +3 -1
- metadata +2 -2
@@ -16,9 +16,12 @@ module FruitToLime
|
|
16
16
|
"CustomField"
|
17
17
|
end
|
18
18
|
include SerializeHelper
|
19
|
-
def initialize()
|
20
|
-
|
21
|
-
|
19
|
+
def initialize(opt=nil)
|
20
|
+
if opt!=nil
|
21
|
+
serialize_variables.each do |myattr|
|
22
|
+
val = opt[myattr[:id]]
|
23
|
+
instance_variable_set("@"+myattr[:id].to_s,val) if val!=nil
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -35,46 +35,56 @@ module FruitToLime
|
|
35
35
|
|
36
36
|
class Organization < OrganizationReference
|
37
37
|
include SerializeHelper
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
attr_accessor :organization_number, :email, :web_site, :postal_address, :visit_address
|
40
|
+
attr_reader :employees, :notes, :custom_fields
|
40
41
|
|
41
42
|
def initialize()
|
42
|
-
serialize_variables.each do |myattr|
|
43
|
-
instance_variable_set("@"+myattr[:id].to_s,get_default(myattr[:type]))
|
44
|
-
end
|
45
43
|
end
|
44
|
+
def with_postal_address
|
45
|
+
@postal_address = Address.new
|
46
|
+
yield @postal_address
|
47
|
+
end
|
48
|
+
|
49
|
+
def with_visit_address
|
50
|
+
@visit_address = Address.new
|
51
|
+
yield @visit_address
|
52
|
+
end
|
53
|
+
|
46
54
|
|
47
|
-
def set_custom_field(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
def set_custom_field(obj)
|
56
|
+
@custom_fields = [] if @custom_fields==nil
|
57
|
+
@custom_fields.push CustomField.new(obj)
|
58
|
+
end
|
59
|
+
def source_ref
|
60
|
+
@source_ref
|
61
|
+
end
|
62
|
+
def source_ref=(val)
|
63
|
+
if !val.is_a? SourceRef
|
64
|
+
@source_ref = SourceRef.new(val)
|
65
|
+
else
|
66
|
+
@source_ref = val
|
67
|
+
end
|
53
68
|
end
|
54
69
|
|
55
70
|
def tags
|
56
71
|
@tags
|
57
72
|
end
|
58
73
|
|
59
|
-
def
|
60
|
-
if
|
61
|
-
|
62
|
-
Tag.new(str)
|
63
|
-
end.to_a
|
64
|
-
else
|
65
|
-
@tags = strOrArray
|
66
|
-
end
|
74
|
+
def add_tag(str)
|
75
|
+
@tags = [] if @tags == nil
|
76
|
+
@tags.push(Tag.new(str))
|
67
77
|
end
|
68
78
|
|
69
79
|
def serialize_variables
|
70
|
-
[ :id, :integration_id, :name, :organization_number, :email, :web_site ].map { |prop| {:id=>prop
|
71
|
-
[
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
[ :id, :integration_id, :name, :organization_number, :email, :web_site ].map { |prop| { :id => prop, :type => :string } } +
|
81
|
+
[
|
82
|
+
{ :id => :postal_address, :type => :address},
|
83
|
+
{ :id => :visit_address, :type => :address},
|
84
|
+
{ :id => :employees, :type => :persons},
|
85
|
+
{ :id => :tags, :type => :tags},
|
86
|
+
{ :id => :custom_fields, :type => :custom_fields},
|
87
|
+
{ :id => :source_ref, :type => :source_ref}
|
78
88
|
]
|
79
89
|
end
|
80
90
|
|
@@ -34,35 +34,40 @@ module FruitToLime
|
|
34
34
|
attr_accessor :first_name, :last_name,
|
35
35
|
:direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
|
36
36
|
:position, :email, :alternative_email, :postal_address, :currently_employed,
|
37
|
-
:
|
38
|
-
|
37
|
+
:notes, :organization
|
38
|
+
attr_reader :custom_fields
|
39
39
|
|
40
40
|
def initialize()
|
41
|
-
serialize_variables.each do |myattr|
|
42
|
-
instance_variable_set("@"+myattr[:id].to_s, get_default(myattr[:type]))
|
43
|
-
end
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
def with_postal_address
|
44
|
+
@postal_address = Address.new
|
45
|
+
yield @postal_address
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_custom_field(obj)
|
49
|
+
@custom_fields = [] if @custom_fields==nil
|
50
|
+
@custom_fields.push CustomField.new(obj)
|
51
|
+
end
|
52
|
+
def source_ref
|
53
|
+
@source_ref
|
54
|
+
end
|
55
|
+
def source_ref=(val)
|
56
|
+
if !val.is_a? SourceRef
|
57
|
+
@source_ref = SourceRef.new(val)
|
58
|
+
else
|
59
|
+
@source_ref = val
|
60
|
+
end
|
52
61
|
end
|
53
62
|
|
63
|
+
|
54
64
|
def tags
|
55
65
|
@tags
|
56
66
|
end
|
57
67
|
|
58
|
-
def
|
59
|
-
if
|
60
|
-
|
61
|
-
Tag.new(str)
|
62
|
-
end.to_a
|
63
|
-
else
|
64
|
-
@tags = strOrArray
|
65
|
-
end
|
68
|
+
def add_tag(str)
|
69
|
+
@tags = [] if @tags == nil
|
70
|
+
@tags.push(Tag.new(str))
|
66
71
|
end
|
67
72
|
|
68
73
|
def serialize_name
|
@@ -58,13 +58,10 @@ module FruitToLime
|
|
58
58
|
end
|
59
59
|
def initialize(opt=nil)
|
60
60
|
if opt!=nil
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@name =""
|
66
|
-
@id =""
|
67
|
-
@format = ""
|
61
|
+
serialize_variables.each do |myattr|
|
62
|
+
val = opt[myattr[:id]]
|
63
|
+
instance_variable_set("@"+myattr[:id].to_s,val) if val!=nil
|
64
|
+
end
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
@@ -32,10 +32,12 @@ module SerializeHelper
|
|
32
32
|
varv = serialize_variables(varv)
|
33
33
|
elsif (varv.is_a?(Array))
|
34
34
|
varv = varv.map { |elem| SerializeHelper::serialize(elem) }.join("\n")
|
35
|
+
elsif (varv == nil)
|
36
|
+
varv = nil
|
35
37
|
else
|
36
38
|
varv = varv.to_s.encode('UTF-8').encode(:xml => :text)
|
37
39
|
end
|
38
|
-
"<#{varn}>#{ varv }</#{varn}>"
|
40
|
+
if varv != nil then "<#{varn}>#{ varv }</#{varn}>" else "" end
|
39
41
|
end.join("\n")
|
40
42
|
end
|
41
43
|
raise "!!#{obj.class}"
|
@@ -81,7 +83,7 @@ module SerializeHelper
|
|
81
83
|
end
|
82
84
|
subval = send(found[:id].to_s)
|
83
85
|
if !subval
|
84
|
-
subval =
|
86
|
+
subval = nil
|
85
87
|
send(found[:id].to_s+"=",subval)
|
86
88
|
end
|
87
89
|
subval.set_attribute(selected.slice(1), value)
|
@@ -94,35 +96,6 @@ module SerializeHelper
|
|
94
96
|
symbol.to_s.split('_').join(' ').capitalize
|
95
97
|
end
|
96
98
|
|
97
|
-
def get_default(type)
|
98
|
-
case type
|
99
|
-
when :string then
|
100
|
-
""
|
101
|
-
when :bool then
|
102
|
-
false
|
103
|
-
when :source_ref then
|
104
|
-
SourceRef.new
|
105
|
-
when :address then
|
106
|
-
Address.new
|
107
|
-
when :notes then
|
108
|
-
[]
|
109
|
-
when :tags then
|
110
|
-
[]
|
111
|
-
when :persons then
|
112
|
-
[]
|
113
|
-
when :custom_fields then
|
114
|
-
[]
|
115
|
-
when :organization_reference then
|
116
|
-
OrganizationReference.new
|
117
|
-
when :date then
|
118
|
-
nil
|
119
|
-
when :coworker_reference then
|
120
|
-
CoworkerReference.new
|
121
|
-
else
|
122
|
-
raise "Dont know how to handle '#{type}'"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
99
|
def map_symbol_to_row(symbol,type)
|
127
100
|
{
|
128
101
|
:id=>symbol.to_s,
|
@@ -6,7 +6,7 @@ describe FruitToLime::SerializeHelper do
|
|
6
6
|
describe "Serialize note" do
|
7
7
|
let(:serialized) {
|
8
8
|
n = FruitToLime::Note.new
|
9
|
-
|
9
|
+
n.text = "text"
|
10
10
|
FruitToLime::SerializeHelper::serialize(n)
|
11
11
|
}
|
12
12
|
it "should contain text" do
|
@@ -19,25 +19,38 @@ describe FruitToLime::SerializeHelper do
|
|
19
19
|
serialized.encoding.should equal Encoding::UTF_8
|
20
20
|
end
|
21
21
|
end
|
22
|
+
describe "Serialize without data" do
|
23
|
+
let(:serialized) {
|
24
|
+
p = FruitToLime::Person.new
|
25
|
+
FruitToLime::SerializeHelper::serialize(p)
|
26
|
+
}
|
27
|
+
it "should not contain fields that are not set" do
|
28
|
+
#puts serialized
|
29
|
+
serialized.should_not match(/<Email>/)
|
30
|
+
serialized.should_not match(/<Position>/)
|
31
|
+
serialized.should_not match(/<AlternativeEmail>/)
|
32
|
+
serialized.should_not match(/<Tags>/)
|
33
|
+
serialized.should_not match(/<CustomFields>/)
|
34
|
+
end
|
35
|
+
it "should be utf-8" do
|
36
|
+
serialized.encoding.should equal Encoding::UTF_8
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
22
40
|
describe "Serialize person" do
|
23
41
|
let(:serialized) {
|
24
42
|
p = FruitToLime::Person.new
|
25
43
|
p.id = "1"
|
26
44
|
p.first_name = "Kalle"
|
27
45
|
p.last_name = "Anka"
|
28
|
-
p.source_ref =
|
29
|
-
p.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
p.
|
36
|
-
cf2 = FruitToLime::CustomField.new
|
37
|
-
cf2.id = "3"
|
38
|
-
cf2.title = "cf title2"
|
39
|
-
cf2.value = "cf Bj\u{00F6}rk"
|
40
|
-
p.custom_fields.push(cf2)
|
46
|
+
p.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
47
|
+
p.with_postal_address do |addr|
|
48
|
+
addr.city = "Ankeborg"
|
49
|
+
end
|
50
|
+
p.add_tag("tag:anka")
|
51
|
+
p.add_tag("tag:Bj\u{00F6}rk")
|
52
|
+
p.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
53
|
+
p.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
41
54
|
FruitToLime::SerializeHelper::serialize(p)
|
42
55
|
}
|
43
56
|
it "should contain first and last name" do
|
@@ -47,6 +60,9 @@ describe FruitToLime::SerializeHelper do
|
|
47
60
|
it "should tag name" do
|
48
61
|
serialized.should match(/tag:anka/)
|
49
62
|
end
|
63
|
+
it "should contain address" do
|
64
|
+
serialized.should match(/Ankeborg/)
|
65
|
+
end
|
50
66
|
it "should contain custom field" do
|
51
67
|
serialized.should match(/cf title/)
|
52
68
|
serialized.should match(/cf value/)
|
@@ -69,24 +85,26 @@ describe FruitToLime::SerializeHelper do
|
|
69
85
|
let(:serialized) {
|
70
86
|
o = FruitToLime::Organization.new
|
71
87
|
o.name = "Ankeborgs bibliotek"
|
72
|
-
o.
|
73
|
-
o.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
o.custom_fields.push(cf2)
|
88
|
+
o.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
89
|
+
o.add_tag("tag:bibliotek")
|
90
|
+
o.add_tag("tag:Bj\u{00F6}rk")
|
91
|
+
o.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
92
|
+
o.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
93
|
+
o.with_postal_address do |addr|
|
94
|
+
addr.city = "Ankeborg"
|
95
|
+
end
|
96
|
+
o.with_visit_address do |addr|
|
97
|
+
addr.city = "Gaaseborg"
|
98
|
+
end
|
84
99
|
FruitToLime::SerializeHelper::serialize(o)
|
85
100
|
}
|
86
101
|
it "should contain name" do
|
87
102
|
serialized.should match(/Ankeborgs bibliotek/)
|
88
103
|
end
|
89
|
-
|
104
|
+
it "should contain address" do
|
105
|
+
serialized.should match(/Ankeborg/)
|
106
|
+
serialized.should match(/Gaaseborg/)
|
107
|
+
end
|
90
108
|
it "should tag name" do
|
91
109
|
serialized.should match(/<Tag>tag:bibliotek<\/Tag>/)
|
92
110
|
end
|
data/spec/person_spec.rb
CHANGED
@@ -6,7 +6,9 @@ describe "Person" do
|
|
6
6
|
@person = FruitToLime::Person.new
|
7
7
|
end
|
8
8
|
it "can set a customfield" do
|
9
|
-
@person.set_custom_field('the key',
|
9
|
+
@person.set_custom_field({:integration_id=>'the key',
|
10
|
+
:title=> 'the title',
|
11
|
+
:value=> 'the value'})
|
10
12
|
|
11
13
|
field = @person.custom_fields[0]
|
12
14
|
field.integration_id.should eq 'the key'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fruit_to_lime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: iso_country_codes
|