church-community-builder 0.1.0
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/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +52 -0
- data/README.rdoc +54 -0
- data/Rakefile +32 -0
- data/ccb_api.gemspec +26 -0
- data/docs/batch_implement.pdf +0 -0
- data/docs/event_implement.pdf +0 -0
- data/docs/group_implement.pdf +0 -0
- data/docs/individual_profile_implement.pdf +0 -0
- data/docs/pwt_implement.pdf +0 -0
- data/docs/pwt_overview.pdf +0 -0
- data/examples/batch.rb +50 -0
- data/examples/calendar.rb +18 -0
- data/examples/campus.rb +13 -0
- data/examples/individual.rb +38 -0
- data/examples/sync_data.rb +48 -0
- data/lib/api/address.rb +28 -0
- data/lib/api/api_object.rb +116 -0
- data/lib/api/batch.rb +48 -0
- data/lib/api/batch_list.rb +50 -0
- data/lib/api/campus.rb +29 -0
- data/lib/api/campus_list.rb +65 -0
- data/lib/api/individual.rb +138 -0
- data/lib/api/individual_list.rb +65 -0
- data/lib/api/mergeable_individual_list.rb +92 -0
- data/lib/api/mergeable_transaction_list.rb +74 -0
- data/lib/api/search.rb +81 -0
- data/lib/api/transaction.rb +114 -0
- data/lib/api/transaction_list.rb +52 -0
- data/lib/api/valid_individual.rb +43 -0
- data/lib/api/valid_individual_list.rb +49 -0
- data/lib/auto_load.rb +17 -0
- data/lib/ccb_api.rb +33 -0
- data/lib/common.rb +41 -0
- data/lib/exceptions.rb +5 -0
- data/lib/readers/api_reader.rb +35 -0
- data/lib/readers/batch_list_reader.rb +17 -0
- data/lib/readers/batch_reader.rb +14 -0
- data/lib/readers/campus_list_reader.rb +17 -0
- data/lib/readers/individual_list_reader.rb +18 -0
- data/lib/readers/individual_reader.rb +14 -0
- data/lib/writers/api_writer.rb +64 -0
- data/lib/writers/user_writer.rb +46 -0
- data/spec/api/user_spec.rb +37 -0
- data/spec/factories/user.rb +51 -0
- data/spec/functional/ccb_spec.rb +20 -0
- data/spec/readers/user_reader_spec.rb +7 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/writers/user_writer_spec.rb +80 -0
- metadata +137 -0
data/lib/api/batch.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
class Batch < ApiObject
|
|
6
|
+
|
|
7
|
+
ccb_attr_accessor :id,
|
|
8
|
+
:campus,
|
|
9
|
+
:post_date,
|
|
10
|
+
:begin_date,
|
|
11
|
+
:end_date,
|
|
12
|
+
:in_accounting_package,
|
|
13
|
+
:status,
|
|
14
|
+
:source,
|
|
15
|
+
:transactions,
|
|
16
|
+
:creator,
|
|
17
|
+
:modifier,
|
|
18
|
+
:created,
|
|
19
|
+
:modified
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def self.load_by_id(batch_id)
|
|
23
|
+
reader = BatchReader.new(batch_id)
|
|
24
|
+
self.new(reader.load_feed)
|
|
25
|
+
rescue
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def initialize(json_data = nil, options = {})
|
|
31
|
+
initialize_from_json_object(json_data) unless json_data.nil?
|
|
32
|
+
|
|
33
|
+
if json_data["ccb_api"].nil?
|
|
34
|
+
batch_json = json_data
|
|
35
|
+
else
|
|
36
|
+
batch_json = json_data["ccb_api"]["response"]["batches"]["batch"]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
initialize_from_json_object(batch_json) unless batch_json.nil?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def has_transactions?
|
|
44
|
+
!self.transactions.nil?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
class BatchList
|
|
4
|
+
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
attr_reader :request_data,
|
|
8
|
+
:response_data,
|
|
9
|
+
:service,
|
|
10
|
+
:batches,
|
|
11
|
+
:count,
|
|
12
|
+
:batch_array,
|
|
13
|
+
:json_data #for debugging
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def initialize(json)
|
|
17
|
+
@json_data = json["ccb_api"]
|
|
18
|
+
@request_data = @json_data["request"]
|
|
19
|
+
@response_data = @json_data["response"]
|
|
20
|
+
@service = @response_data["service"] #CCB service type accessed
|
|
21
|
+
|
|
22
|
+
@batches = @response_data['batches']
|
|
23
|
+
|
|
24
|
+
@count = @batches["count"].to_i #number of records
|
|
25
|
+
@batch_array = @batches["batch"].class == Array ? @batches["batch"] : [@batches["batch"]].compact #array of each batch
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def all_names
|
|
29
|
+
return [] unless @batch_array
|
|
30
|
+
@batch_array.collect { |batch| [batch['first_name'], batch['last_name']].join(' ') }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def [](index)
|
|
34
|
+
Batch.new( @batch_array[index] ) if @batch_array and @batch_array[index]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# This method is needed for Enumerable.
|
|
39
|
+
def each &block
|
|
40
|
+
@batch_array.each{ |batch| yield( Batch.new(batch) )}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def empty?
|
|
45
|
+
self.count == 0 ? true : false
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
data/lib/api/campus.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
class Campus < ApiObject
|
|
6
|
+
|
|
7
|
+
ccb_attr_accessor :id,
|
|
8
|
+
:name,
|
|
9
|
+
:active,
|
|
10
|
+
:creator,
|
|
11
|
+
:modifier,
|
|
12
|
+
:created,
|
|
13
|
+
:modified
|
|
14
|
+
|
|
15
|
+
def initialize(json_data = nil, options = {})
|
|
16
|
+
|
|
17
|
+
# When we initialize from CampusReader, the "Campus" is buried
|
|
18
|
+
if json_data["ccb_api"].nil?
|
|
19
|
+
campus_json = json_data
|
|
20
|
+
else
|
|
21
|
+
campus_json = json_data["ccb_api"]["response"]["campuses"]["campus"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
initialize_from_json_object(campus_json) unless campus_json.nil?
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
class CampusList
|
|
4
|
+
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
attr_reader :request_data,
|
|
8
|
+
:response_data,
|
|
9
|
+
:service,
|
|
10
|
+
:individuals,
|
|
11
|
+
:count,
|
|
12
|
+
:campus_array,
|
|
13
|
+
:json_data #for debugging
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def initialize(json)
|
|
17
|
+
@json_data = json["ccb_api"]
|
|
18
|
+
@request_data = @json_data["request"]
|
|
19
|
+
@response_data = @json_data["response"]
|
|
20
|
+
@service = @response_data["service"] #CCB service type accessed
|
|
21
|
+
|
|
22
|
+
@campuses = @response_data['campuses']
|
|
23
|
+
|
|
24
|
+
@count = @campuses["count"].to_i #number of records
|
|
25
|
+
|
|
26
|
+
# if @campuses['campus'] is a single item, it will be returned
|
|
27
|
+
# as a Hash, rather than a single element Array, containing the Hash.
|
|
28
|
+
#
|
|
29
|
+
if @campuses["campus"].is_a?(Array)
|
|
30
|
+
@campus_array = @campuses["campus"]
|
|
31
|
+
|
|
32
|
+
elsif @campuses["campus"].is_a?(Hash)
|
|
33
|
+
@campus_array = []
|
|
34
|
+
@campus_array << @campuses["campus"] #array of each campus
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def all_names
|
|
40
|
+
return [] unless @campus_array
|
|
41
|
+
@campus_array.collect { |campus| campus['name'] }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def ids
|
|
45
|
+
(@campus_array.collect { |campus| campus['id'] }).uniq
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def [](index)
|
|
49
|
+
Campus.new( @campus_array[index] ) if @campus_array and @campus_array[index]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# This method is needed for Enumerable.
|
|
54
|
+
def each &block
|
|
55
|
+
@campus_array.each{ |campus| yield( Campus.new(campus) )}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def empty?
|
|
60
|
+
@campus_array.size == 0 ? true : false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
class Individual < ApiObject
|
|
6
|
+
|
|
7
|
+
ccb_attr_accessor :id,
|
|
8
|
+
:sync_id,
|
|
9
|
+
:other_id,
|
|
10
|
+
:giving_number,
|
|
11
|
+
:campus,
|
|
12
|
+
:family,
|
|
13
|
+
:family_image,
|
|
14
|
+
:family_position,
|
|
15
|
+
:family_members,
|
|
16
|
+
:first_name,
|
|
17
|
+
:last_name,
|
|
18
|
+
:middle_name,
|
|
19
|
+
:legal_first_name,
|
|
20
|
+
:full_name,
|
|
21
|
+
:salutation,
|
|
22
|
+
:suffix,
|
|
23
|
+
:image,
|
|
24
|
+
:email,
|
|
25
|
+
:addresses,
|
|
26
|
+
:phones,
|
|
27
|
+
:mobile_carrier,
|
|
28
|
+
:gender,
|
|
29
|
+
:marital_status,
|
|
30
|
+
:birthday,
|
|
31
|
+
:anniversary,
|
|
32
|
+
:deceased,
|
|
33
|
+
:membership_type,
|
|
34
|
+
:membership_date,
|
|
35
|
+
:membership_end,
|
|
36
|
+
:receive_email_from_church,
|
|
37
|
+
:default_new_group_messages,
|
|
38
|
+
:default_new_group_comments,
|
|
39
|
+
:default_new_group_digest,
|
|
40
|
+
:default_new_group_sms,
|
|
41
|
+
:privacy_settings,
|
|
42
|
+
:active,
|
|
43
|
+
:creator,
|
|
44
|
+
:modifier,
|
|
45
|
+
:created,
|
|
46
|
+
:modified,
|
|
47
|
+
:home_address,
|
|
48
|
+
:mailing_address,
|
|
49
|
+
:work_address,
|
|
50
|
+
:other_address,
|
|
51
|
+
:contact_phone,
|
|
52
|
+
:home_phone,
|
|
53
|
+
:work_phone,
|
|
54
|
+
:mobile_phone
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def initialize(json_data = nil)
|
|
58
|
+
#@writer_object = PersonWriter
|
|
59
|
+
|
|
60
|
+
# When we initialize from IndividualReader, the "Individual" is buried
|
|
61
|
+
if json_data["ccb_api"].nil?
|
|
62
|
+
individual_json = json_data
|
|
63
|
+
else
|
|
64
|
+
individual_json = json_data["ccb_api"]["response"]["individuals"]["individual"]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
initialize_from_json_object(individual_json) unless individual_json.nil?
|
|
68
|
+
|
|
69
|
+
_set_addresses
|
|
70
|
+
_set_phones
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.load_by_id(individual_id)
|
|
75
|
+
reader = IndividualReader.new(individual_id)
|
|
76
|
+
self.new(reader.load_feed)
|
|
77
|
+
rescue
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def family_id
|
|
82
|
+
self.family['id']
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def family_name
|
|
86
|
+
self.family['content']
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def campus_id
|
|
90
|
+
self.campus["id"]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def campus_name
|
|
94
|
+
self.campus["content"]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def _set_addresses
|
|
100
|
+
|
|
101
|
+
self.addresses["address"].each do |address|
|
|
102
|
+
case address["type"]
|
|
103
|
+
when 'mailing'
|
|
104
|
+
@mailing_address = Address.new(address)
|
|
105
|
+
when 'home'
|
|
106
|
+
@home_address = Address.new(address)
|
|
107
|
+
when 'work'
|
|
108
|
+
@work_address = Address.new(address)
|
|
109
|
+
when 'other'
|
|
110
|
+
@other_address = Address.new(address)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def _set_phones
|
|
118
|
+
|
|
119
|
+
self.phones["phone"].each do |phone|
|
|
120
|
+
case phone["type"]
|
|
121
|
+
when 'contact'
|
|
122
|
+
@contact_phone = phone["content"]
|
|
123
|
+
when 'home'
|
|
124
|
+
@home_phone = phone["content"]
|
|
125
|
+
when 'work'
|
|
126
|
+
@work_phone = phone["content"]
|
|
127
|
+
when 'mobile'
|
|
128
|
+
@mobile_phone = phone["content"]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
end
|
|
138
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
class IndividualList
|
|
4
|
+
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
attr_reader :request_data,
|
|
8
|
+
:response_data,
|
|
9
|
+
:service,
|
|
10
|
+
:individuals,
|
|
11
|
+
:count,
|
|
12
|
+
:individual_array,
|
|
13
|
+
:json_data #for debugging
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def initialize(json)
|
|
17
|
+
@json_data = json["ccb_api"]
|
|
18
|
+
@request_data = @json_data["request"]
|
|
19
|
+
@response_data = @json_data["response"]
|
|
20
|
+
@service = @response_data["service"] #CCB service type accessed
|
|
21
|
+
|
|
22
|
+
@individuals = @response_data['individuals']
|
|
23
|
+
|
|
24
|
+
@count = @individuals["count"].to_i #number of records
|
|
25
|
+
|
|
26
|
+
# if @individuals['individual'] is a single item, it will be returned
|
|
27
|
+
# as a Hash, rather than a single element Array, containing the Hash.
|
|
28
|
+
#
|
|
29
|
+
if @individuals["individual"].is_a?(Array)
|
|
30
|
+
@individual_array = @individuals["individual"]
|
|
31
|
+
|
|
32
|
+
elsif @individuals["individual"].is_a?(Hash)
|
|
33
|
+
@individual_array = []
|
|
34
|
+
@individual_array << @individuals["individual"] #array of each individual
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def all_names
|
|
40
|
+
return [] unless @individual_array
|
|
41
|
+
@individual_array.collect { |individual| [individual['first_name'], individual['last_name']].join(' ') }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def ids
|
|
45
|
+
(@individual_array.collect { |individual| individual['id'] }).uniq
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def [](index)
|
|
49
|
+
Individual.new( @individual_array[index] ) if @individual_array and @individual_array[index]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# This method is needed for Enumerable.
|
|
54
|
+
def each &block
|
|
55
|
+
@individual_array.each{ |individual| yield( Individual.new(individual) )}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def empty?
|
|
60
|
+
self.count == 0 ? true : false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module ChurchCommunityBuilder
|
|
2
|
+
|
|
3
|
+
class MergeableIndividualList
|
|
4
|
+
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
# Constructor.
|
|
8
|
+
# Can initialize from another IndividualList, else will default to an emtpy list
|
|
9
|
+
# which can then have other lists 'add'ed.
|
|
10
|
+
#
|
|
11
|
+
def initialize(individual_list = nil)
|
|
12
|
+
|
|
13
|
+
if individual_list.nil?
|
|
14
|
+
@individual_array = []
|
|
15
|
+
|
|
16
|
+
else
|
|
17
|
+
@individual_array = individual_list.individual_array
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# All the individuals in the list.
|
|
24
|
+
#
|
|
25
|
+
# @return array of names (first last).
|
|
26
|
+
def all_names
|
|
27
|
+
return [] unless @individual_array
|
|
28
|
+
@individual_array.collect { |individual| [individual['first_name'], individual['last_name']].join(' ') }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
alias_method :names, :all_names
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Get the specified individual.
|
|
35
|
+
#
|
|
36
|
+
# @param index The index of the individual to get.
|
|
37
|
+
#
|
|
38
|
+
# @return [individual]
|
|
39
|
+
def [](index)
|
|
40
|
+
Individual.new( @individual_array[index] ) if @individual_array and @individual_array[index]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# This method is needed for Enumerable.
|
|
45
|
+
def each &block
|
|
46
|
+
@individual_array.each{ |individual| yield( Individual.new(individual) )}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Get all the Individual ids in the list.
|
|
51
|
+
#
|
|
52
|
+
# @return An array of Individual ids.
|
|
53
|
+
def ids
|
|
54
|
+
(@individual_array.collect { |individual| individual['id'] }).uniq
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Adds an IndividualList, MergeableIndividualList, or Individual to this list.
|
|
58
|
+
#
|
|
59
|
+
def add(individual_type)
|
|
60
|
+
|
|
61
|
+
if individual_type.is_a?(IndividualList)
|
|
62
|
+
@individual_array += individual_type.individual_array
|
|
63
|
+
|
|
64
|
+
elsif individual_type.is_a?(MergeableIndividualList)
|
|
65
|
+
@individual_array += individual_type.individual_array
|
|
66
|
+
|
|
67
|
+
elsif individual_type.is_a?(Individual)
|
|
68
|
+
@individual_array << JSON.parse( individual_type.to_json )
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
alias_method :merge, :add
|
|
75
|
+
|
|
76
|
+
def count
|
|
77
|
+
@individual_array.size
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Checks if the list is empty.
|
|
81
|
+
#
|
|
82
|
+
# @return true on empty, false otherwise.
|
|
83
|
+
def empty?
|
|
84
|
+
self.count == 0 ? true : false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Alias the count method
|
|
88
|
+
alias :size :count
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|