fellowshipone-api 0.6.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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +64 -0
  7. data/README.rdoc +44 -0
  8. data/Rakefile +32 -0
  9. data/fellowshipone_api.gemspec +25 -0
  10. data/lib/api/api_object.rb +141 -0
  11. data/lib/api/communication.rb +59 -0
  12. data/lib/api/contribution.rb +97 -0
  13. data/lib/api/contribution_list.rb +57 -0
  14. data/lib/api/fund.rb +40 -0
  15. data/lib/api/fund_list.rb +53 -0
  16. data/lib/api/household.rb +50 -0
  17. data/lib/api/household_list.rb +78 -0
  18. data/lib/api/member_household_list.rb +73 -0
  19. data/lib/api/mergeable_household_list.rb +79 -0
  20. data/lib/api/mergeable_person_list.rb +110 -0
  21. data/lib/api/person.rb +169 -0
  22. data/lib/api/person_list.rb +85 -0
  23. data/lib/api/search.rb +55 -0
  24. data/lib/auto_load.rb +17 -0
  25. data/lib/common.rb +76 -0
  26. data/lib/exceptions.rb +5 -0
  27. data/lib/fellowship_one.rb +54 -0
  28. data/lib/oauth_monkey_patch.rb +13 -0
  29. data/lib/readers/api_reader.rb +34 -0
  30. data/lib/readers/communication_reader.rb +19 -0
  31. data/lib/readers/contribution_list_reader.rb +37 -0
  32. data/lib/readers/contribution_reader.rb +18 -0
  33. data/lib/readers/fund_list_reader.rb +13 -0
  34. data/lib/readers/fund_reader.rb +14 -0
  35. data/lib/readers/household_list_reader.rb +62 -0
  36. data/lib/readers/household_reader.rb +18 -0
  37. data/lib/readers/member_household_list_reader.rb +27 -0
  38. data/lib/readers/person_list_reader.rb +37 -0
  39. data/lib/readers/person_reader.rb +20 -0
  40. data/lib/writers/api_writer.rb +64 -0
  41. data/lib/writers/communication_writer.rb +27 -0
  42. data/lib/writers/contribution_writer.rb +28 -0
  43. data/lib/writers/household_writer.rb +30 -0
  44. data/lib/writers/person_writer.rb +64 -0
  45. data/spec/api/person_spec.rb +21 -0
  46. data/spec/functional/fellowship_one_spec.rb +17 -0
  47. data/spec/readers/api_reader_spec.rb +7 -0
  48. data/spec/spec_helper.rb +47 -0
  49. data/spec/vcr_setup.rb +5 -0
  50. data/spec/writers/api_writer_spec.rb +7 -0
  51. metadata +129 -0
@@ -0,0 +1,57 @@
1
+ module FellowshipOne
2
+
3
+ class ContributionList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :count, :page_number, :total_records, :additional_pages
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param options A hash of options for loading the list.
13
+ #
14
+ # Options:
15
+ # :page - (optional) The page number to get.
16
+ # :reader - (optional) The Reader to use to load the data.
17
+ def initialize(options)
18
+ #options[:page] ||= 1
19
+ reader = options[:reader] || FellowshipOne::ContributionListReader.new(options)
20
+ @json_data = reader.load_feed
21
+
22
+ @count = @json_data['@count'].to_i
23
+ @page_number = @json_data['@pageNumber'].to_i
24
+ @total_records = @json_data['@totalRecords'].to_i
25
+ @additional_pages = @json_data['@additionalPages'].to_i
26
+ end
27
+
28
+
29
+ # Get the specified contribution.
30
+ #
31
+ # @param index The index of the contribution to get.
32
+ #
33
+ # @return Contribution
34
+ def [](index)
35
+ Contribution.new( @json_data['contributionReceipt'][index] ) if @json_data['contributionReceipt'][index]
36
+ end
37
+
38
+
39
+ # This method is needed for Enumerable.
40
+ def each &block
41
+ @json_data['contributionReceipt'].each{ |cont_recpt| yield( Contribution.new(cont_recpt) )}
42
+ end
43
+
44
+ # Alias the count method
45
+ alias :size :count
46
+
47
+
48
+ # Checks if the list is empty.
49
+ #
50
+ # @return True on empty, false otherwise.
51
+ def empty?
52
+ self.count == 0 ? true : false
53
+ end
54
+
55
+ end
56
+
57
+ end
data/lib/api/fund.rb ADDED
@@ -0,0 +1,40 @@
1
+ module FellowshipOne
2
+
3
+ class Fund < ApiObject
4
+
5
+ f1_attr_accessor :id,
6
+ :name,
7
+ :fund_type,
8
+ :fund_code,
9
+ :is_web_enabled,
10
+ :account_reference,
11
+ :is_active,
12
+ :created_date,
13
+ :created_by_person,
14
+ :last_updated_date,
15
+ :last_updated_by_person
16
+
17
+ # Load the fund by the specified ID.
18
+ #
19
+ # @param fund_id The ID of the fund to load.
20
+ #
21
+ # Returns a new Fund object.
22
+ def self.load_by_id(fund_id)
23
+ reader = FundReader.new(fund_id)
24
+ self.new(reader)
25
+ end
26
+
27
+ # Constructor.
28
+ #
29
+ # @param reader (optional) The object that has the data. This can be a FundReader or Hash object.
30
+ def initialize(reader = nil)
31
+ if reader.is_a?(FundReader)
32
+ initialize_from_json_object(reader.load_feed['fund'])
33
+ elsif reader.is_a?(Hash)
34
+ initialize_from_json_object(reader)
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,53 @@
1
+ module FellowshipOne
2
+
3
+ class FundList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :count, :page_number, :total_records, :additional_pages
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param options A hash of options for loading the list.
13
+ #
14
+ # Options:
15
+ # :reader - (optional) The Reader to use to load the data.
16
+ def initialize(options = {})
17
+ reader = options[:reader] || FellowshipOne::FundListReader.new(options)
18
+ @json_data = reader.load_feed
19
+ @count = @json_data['funds']['fund'].size.to_i
20
+ @page_number = 1
21
+ @total_records = @count
22
+ @additional_pages = 0
23
+ end
24
+
25
+ # Get the specified fund.
26
+ #
27
+ # @param index The index of the fund to get.
28
+ #
29
+ # @return Fund
30
+ def [](index)
31
+ Fund.new( @json_data['funds']['fund'][index] ) if @json_data['funds']['fund'][index]
32
+ end
33
+
34
+
35
+ # This method is needed for Enumerable.
36
+ def each &block
37
+ @json_data['funds']['fund'].each{ |cont_recpt| yield( Fund.new(cont_recpt) )}
38
+ end
39
+
40
+ # Alias the count method
41
+ alias :size :count
42
+
43
+
44
+ # Checks if the list is empty.
45
+ #
46
+ # @return True on empty, false otherwise.
47
+ def empty?
48
+ self.count == 0 ? true : false
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,50 @@
1
+ module FellowshipOne
2
+
3
+ class Household < ApiObject
4
+
5
+ f1_attr_accessor :id,
6
+ :uri,
7
+ :old_id,
8
+ :h_code,
9
+ :household_name,
10
+ :household_sort_name,
11
+ :household_first_name,
12
+ :last_security_authorization,
13
+ :last_activity_date,
14
+ :created_date,
15
+ :last_updated_date # This is a datetime
16
+
17
+ # Loads the household by the specified ID.
18
+ #
19
+ def self.load_by_id(household_id)
20
+ reader = HouseholdReader.new(household_id)
21
+ self.new(reader)
22
+ end
23
+
24
+
25
+ # Constructor.
26
+ #
27
+ # @param reader (optional) The object that has the data. This can be a HouseholdReader or Hash object.
28
+ def initialize(reader = nil)
29
+ @writer_object = HouseholdWriter
30
+ if reader.is_a?(HouseholdReader)
31
+ initialize_from_json_object(reader.load_feed['household'])
32
+ elsif reader.is_a?(Hash)
33
+ initialize_from_json_object(reader)
34
+ else # new
35
+ reader = HouseholdReader.new
36
+ initialize_from_json_object(reader.load_new['household'])
37
+ end
38
+ end
39
+
40
+
41
+ def _field_map
42
+ {:id => '@id',
43
+ :uri => '@uri',
44
+ :oldId => '@oldID',
45
+ :hCode => '@hCode'}
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,78 @@
1
+ module FellowshipOne
2
+
3
+ class HouseholdList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :count, :page_number, :total_records, :additional_pages
8
+
9
+ # Constructor.
10
+ #
11
+ # @param options A hash of options for loading the list.
12
+ #
13
+ # Options:
14
+ # :page - (optional) The page number to get.
15
+ # :reader - (optional) The Reader to use to load the data.
16
+ # :household_id - The household ID to pull the info for.
17
+ def initialize(options)
18
+ #options[:page] ||= 1
19
+ reader = options[:reader] || FellowshipOne::HouseholdListReader.new(options)
20
+ @json_data = reader.load_feed
21
+
22
+ @count = @json_data['@count'].to_i
23
+ @page_number = @json_data['@pageNumber'].to_i
24
+ @total_records = @json_data['@totalRecords'].to_i
25
+ @additional_pages = @json_data['@additionalPages'].to_i
26
+ end
27
+
28
+
29
+
30
+ # Get the specified user.
31
+ #
32
+ # @param index The index of the user to get.
33
+ #
34
+ # @return [User]
35
+ def [](index)
36
+ Household.new( @json_data['household'][index] ) if @json_data['household'] and @json_data['household'][index]
37
+ end
38
+
39
+ def all_names
40
+ return [] unless @json_data['household']
41
+ @json_data['household'].collect { |household| household['householdName'] }
42
+ end
43
+
44
+ # This method is needed for Enumerable.
45
+ def each &block
46
+ @json_data['household'].each{ |household| yield( Household.new(household) )}
47
+ end
48
+
49
+ # Alias the count method
50
+ alias :size :count
51
+
52
+ # Checks if the list is empty.
53
+ #
54
+ # @return True on empty, false otherwise.
55
+ def empty?
56
+ #@json_data['person'].empty?
57
+ self.count == 0 ? true : false
58
+ end
59
+
60
+ # Get all the household ids in the list.
61
+ #
62
+ # @return An array of household ids.
63
+ def ids
64
+ (@json_data['household'].collect { |household| household['@id'] }).uniq
65
+ end
66
+
67
+ # Access to the raw JSON data. This method is needed for merging lists.
68
+ #
69
+ # @returns Raw JSON data.
70
+ def raw_data
71
+ @json_data
72
+ end
73
+
74
+
75
+ end
76
+
77
+
78
+ end
@@ -0,0 +1,73 @@
1
+ module FellowshipOne
2
+
3
+ class MemberHouseholdList
4
+
5
+ include Enumerable
6
+
7
+ # Constructor.
8
+ #
9
+ # @param options A hash of options for loading the list.
10
+ #
11
+ # Options:
12
+ # :page - (optional) The page number to get.
13
+ # :reader - (optional) The Reader to use to load the data.
14
+ # :household_id - The household ID to pull the info for.
15
+ def initialize(options)
16
+ raise 'Household ID not specified' if options[:household_id].nil?
17
+
18
+ #options[:page] ||= 1
19
+ reader = options[:reader] || FellowshipOne::MemberHouseholdListReader.new(options)
20
+ @json_data = reader.load_feed
21
+ end
22
+
23
+
24
+
25
+ # Get the specified user.
26
+ #
27
+ # @param index The index of the user to get.
28
+ #
29
+ # @return [User]
30
+ def [](index)
31
+ Person.new( @json_data['people']['person'][index] ) if @json_data['people']['person'] and @json_data['people']['person'][index]
32
+ end
33
+
34
+ def all_names
35
+ return [] unless @json_data['people']
36
+ @json_data['people']['person'].collect { |person| [person['firstName'], person['lastName']].join(' ') }
37
+ end
38
+
39
+ # This method is needed for Enumerable.
40
+ def each &block
41
+ @json_data['people']['person'].each{ |person| yield( Person.new(person) )}
42
+ end
43
+
44
+ # Alias the count method
45
+ alias :size :count
46
+
47
+ # Checks if the list is empty.
48
+ #
49
+ # @return True on empty, false otherwise.
50
+ def empty?
51
+ #@json_data['person'].empty?
52
+ self.count == 0 ? true : false
53
+ end
54
+
55
+ # Get all the household ids in the list.
56
+ #
57
+ # @return An array of household ids.
58
+ def ids
59
+ @json_data['people']['person'].collect { |person| person['@id'] }
60
+ end
61
+
62
+ # Access to the raw JSON data. This method is needed for merging lists.
63
+ #
64
+ # @returns Raw JSON data.
65
+ def raw_data
66
+ @json_data['people']['person']
67
+ end
68
+
69
+
70
+ end
71
+
72
+
73
+ end
@@ -0,0 +1,79 @@
1
+ module FellowshipOne
2
+
3
+ class MergeableHouseholdList
4
+
5
+ include Enumerable
6
+
7
+ # Constructor.
8
+ #
9
+ def initialize
10
+ @json_data = { 'household' => [] }
11
+ # commented out until can figure out what he was doing here.
12
+ end
13
+
14
+
15
+ # All the households in the list.
16
+ #
17
+ # @return array of names (first last).
18
+ def all_names
19
+ return [] unless @json_data['household']
20
+ @json_data['household'].collect { |household| household['householdName'] }
21
+ end
22
+
23
+ alias_method :names, :all_names
24
+
25
+
26
+ # Get the specified household.
27
+ #
28
+ # @param index The index of the household to get.
29
+ #
30
+ # @return [household]
31
+ def [](index)
32
+ Household.new( @json_data['household'][index] ) if @json_data['household'] and @json_data['household'][index]
33
+ end
34
+
35
+
36
+ # This method is needed for Enumerable.
37
+ def each &block
38
+ @json_data['household'].each{ |household| yield( Household.new(household) )}
39
+ end
40
+
41
+ # Alias the count method
42
+ alias :size :count
43
+
44
+ # Checks if the list is empty.
45
+ #
46
+ # @return True on empty, false otherwise.
47
+ def empty?
48
+ #@json_data['household'].empty?
49
+ self.count == 0 ? true : false
50
+ end
51
+
52
+
53
+ # Get all the household ids in the list.
54
+ #
55
+ # @return An array of household ids.
56
+ def ids
57
+ (@json_data['household'].collect { |household| household['@id'] }).uniq
58
+ end
59
+
60
+
61
+ # Access to the raw JSON data. This method is needed for merging lists.
62
+ #
63
+ # @returns Raw JSON data.
64
+ def raw_data
65
+ @json_data
66
+ end
67
+
68
+
69
+ # Adds a HouseholdList to this list.
70
+ #
71
+ def add(household_list)
72
+ @json_data['household'] += household_list.raw_data['household']
73
+ end
74
+
75
+ alias_method :merge, :add
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,110 @@
1
+ module FellowshipOne
2
+
3
+ class MergeablePersonList
4
+
5
+ include Enumerable
6
+
7
+
8
+ # There is currently no way to list all people in FellowshipOne.
9
+ # This method will search all users, AA - AZ, or whatever
10
+ # range is specified, and load them into a MergedPersonList.
11
+ #
12
+ def self.load_all(alpha="aa",omega="zz")
13
+ mpl = MergeablePersonList.new
14
+ alpha.upto(omega).each do |x|
15
+ page = 1
16
+ person_list = Search.search_for_person_by_name(x)
17
+ mpl.add(person_list) unless person_list.empty?
18
+ while person_list.additional_pages > 0
19
+ page += 1
20
+ person_list = Search.search_for_person_by_name(x,page)
21
+ mpl.add(person_list) unless person_list.empty?
22
+ end
23
+ end
24
+ mpl
25
+ end
26
+
27
+
28
+ # Load all people created on or after the specified date and load them into a MergedPersonList.
29
+ #
30
+ def self.load_all_on_or_after(start_date)
31
+ mpl = MergeablePersonList.new
32
+ person_list = Search.search_for_person_created_on_or_after(start_date)
33
+ mpl.add(person_list) unless person_list.empty?
34
+ mpl
35
+ end
36
+
37
+
38
+ # Constructor.
39
+ #
40
+ def initialize
41
+ @json_data = { 'person' => [] }
42
+ # commented out until can figure out what he was doing here.
43
+ end
44
+
45
+
46
+ # All the people in the list.
47
+ #
48
+ # @return array of names (first last).
49
+ def all_names
50
+ return [] unless @json_data['person']
51
+ @json_data['person'].collect { |person| [person['firstName'], person['lastName']].join(' ') }
52
+ end
53
+
54
+ alias_method :names, :all_names
55
+
56
+
57
+ # Get the specified person.
58
+ #
59
+ # @param index The index of the person to get.
60
+ #
61
+ # @return [Person]
62
+ def [](index)
63
+ Person.new( @json_data['person'][index] ) if @json_data['person'] and @json_data['person'][index]
64
+ end
65
+
66
+
67
+ # This method is needed for Enumerable.
68
+ def each &block
69
+ @json_data['person'].each{ |person| yield( Person.new(person) )}
70
+ end
71
+
72
+ # Alias the count method
73
+ alias :size :count
74
+
75
+ # Checks if the list is empty.
76
+ #
77
+ # @return True on empty, false otherwise.
78
+ def empty?
79
+ #@json_data['person'].empty?
80
+ self.count == 0 ? true : false
81
+ end
82
+
83
+
84
+ # Get all the people ids in the list.
85
+ #
86
+ # @return An array of people ids.
87
+ def ids
88
+ (@json_data['person'].collect { |person| person['@id'] }).uniq
89
+ end
90
+
91
+
92
+ # Access to the raw JSON data. This method is needed for merging lists.
93
+ #
94
+ # @returns Raw JSON data.
95
+ def raw_data
96
+ @json_data
97
+ end
98
+
99
+
100
+ # Adds a PersonList to this list.
101
+ #
102
+ def add(person_list)
103
+ @json_data['person'] += person_list.raw_data['person']
104
+ end
105
+
106
+ alias_method :merge, :add
107
+
108
+ end
109
+
110
+ end