fellowshipone-api 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +64 -0
- data/README.rdoc +44 -0
- data/Rakefile +32 -0
- data/fellowshipone_api.gemspec +25 -0
- data/lib/api/api_object.rb +141 -0
- data/lib/api/communication.rb +59 -0
- data/lib/api/contribution.rb +97 -0
- data/lib/api/contribution_list.rb +57 -0
- data/lib/api/fund.rb +40 -0
- data/lib/api/fund_list.rb +53 -0
- data/lib/api/household.rb +50 -0
- data/lib/api/household_list.rb +78 -0
- data/lib/api/member_household_list.rb +73 -0
- data/lib/api/mergeable_household_list.rb +79 -0
- data/lib/api/mergeable_person_list.rb +110 -0
- data/lib/api/person.rb +169 -0
- data/lib/api/person_list.rb +85 -0
- data/lib/api/search.rb +55 -0
- data/lib/auto_load.rb +17 -0
- data/lib/common.rb +76 -0
- data/lib/exceptions.rb +5 -0
- data/lib/fellowship_one.rb +54 -0
- data/lib/oauth_monkey_patch.rb +13 -0
- data/lib/readers/api_reader.rb +34 -0
- data/lib/readers/communication_reader.rb +19 -0
- data/lib/readers/contribution_list_reader.rb +37 -0
- data/lib/readers/contribution_reader.rb +18 -0
- data/lib/readers/fund_list_reader.rb +13 -0
- data/lib/readers/fund_reader.rb +14 -0
- data/lib/readers/household_list_reader.rb +62 -0
- data/lib/readers/household_reader.rb +18 -0
- data/lib/readers/member_household_list_reader.rb +27 -0
- data/lib/readers/person_list_reader.rb +37 -0
- data/lib/readers/person_reader.rb +20 -0
- data/lib/writers/api_writer.rb +64 -0
- data/lib/writers/communication_writer.rb +27 -0
- data/lib/writers/contribution_writer.rb +28 -0
- data/lib/writers/household_writer.rb +30 -0
- data/lib/writers/person_writer.rb +64 -0
- data/spec/api/person_spec.rb +21 -0
- data/spec/functional/fellowship_one_spec.rb +17 -0
- data/spec/readers/api_reader_spec.rb +7 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/vcr_setup.rb +5 -0
- data/spec/writers/api_writer_spec.rb +7 -0
- metadata +129 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
#
|
2
|
+
# small monkey patch for the oauth-ruby gem,
|
3
|
+
# for compatibility with typhoeus > 0.5.0
|
4
|
+
#
|
5
|
+
module OAuth::RequestProxy::Typhoeus
|
6
|
+
class Request < OAuth::RequestProxy::Base
|
7
|
+
|
8
|
+
def method
|
9
|
+
request.options[:method].to_s.upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
# This adapter is the standard for all loading objects.
|
4
|
+
class ApiReader
|
5
|
+
attr_reader :headers
|
6
|
+
|
7
|
+
# Retrieve an empty resource with the proper structure.
|
8
|
+
#
|
9
|
+
# @return a new empty resource.
|
10
|
+
def load_new
|
11
|
+
return if @url_new_data_path.nil?
|
12
|
+
return _load_data(@url_new_data_path, {})
|
13
|
+
end
|
14
|
+
|
15
|
+
# Loads the list
|
16
|
+
#
|
17
|
+
# @return the data loaded in a JSON object.
|
18
|
+
def load_feed
|
19
|
+
@url_data_params ||= {}
|
20
|
+
return _load_data(@url_data_path, @url_data_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def _load_data(url_data_path, url_data_params)
|
26
|
+
response = FellowshipOne::api_request(:get, url_data_path, url_data_params)
|
27
|
+
data = JSON.parse(response.body)
|
28
|
+
@headers = response.headers
|
29
|
+
return data.keys == ['results'] ? data['results'] : data
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class CommunicationReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param person_id The ID of the person to load the communication for.
|
8
|
+
# @param communication_id (optional) The ID of the communication to load.
|
9
|
+
def initialize(person_id, communication_id)
|
10
|
+
if communication_id.nil?
|
11
|
+
@url_new_data_path = "/v1/People/#{person_id}/Communications/new"
|
12
|
+
else
|
13
|
+
@url_data_path = "/v1/People/#{person_id}/Communications/#{communication_id}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class ContributionListReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# Options:
|
8
|
+
# :page - (optional) The page number to get. The default is 1.
|
9
|
+
# :per_page - (optional) The number of items to return per page.
|
10
|
+
# :individual_id - (optional) search for receipts containing the individualID that is passed with this parameter.
|
11
|
+
# :household_id - (optional) search for receipts containing the householdID that is passed with this parameter.
|
12
|
+
# :start_date - (optional) search for receipts with a received date greater than or equal to this parameter.
|
13
|
+
# :end_date - (optional) search for receipts with a received date less than or equal to this parameter. Must be used in conjunction with startReceivedDate.
|
14
|
+
def initialize(options = {})
|
15
|
+
page = options[:page] || 1
|
16
|
+
per_page = options[:per_page] || 500
|
17
|
+
|
18
|
+
@url_data_params = {}
|
19
|
+
@url_data_path = '/giving/v1/contributionreceipts/search'
|
20
|
+
if options[:household_id].nil? and
|
21
|
+
options[:individual_id].nil? and
|
22
|
+
options[:start_date].nil? and
|
23
|
+
options[:end_date].nil? and
|
24
|
+
@url_data_path = '/giving/v1/contributionreceipts'
|
25
|
+
end
|
26
|
+
|
27
|
+
@url_data_params.merge!({:page => page}) if page
|
28
|
+
@url_data_params.merge!({:recordsPerPage => per_page}) if per_page
|
29
|
+
@url_data_params.merge!({:individualID => options[:individual_id]}) if options[:individual_id]
|
30
|
+
@url_data_params.merge!({:householdID => options[:household_id]}) if options[:household_id]
|
31
|
+
@url_data_params.merge!({:startReceivedDate => options[:start_date]}) if options[:start_date]
|
32
|
+
@url_data_params.merge!({:endReceivedDate => options[:end_date]}) if options[:end_date]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class ContributionReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param contribution_id (optional) The ID of the contribution to load.
|
8
|
+
def initialize(contribution_id = nil)
|
9
|
+
if contribution_id.nil?
|
10
|
+
@url_new_data_path = '/giving/v1/contributionreceipts/new'
|
11
|
+
else
|
12
|
+
@url_data_path = "/giving/v1/contributionreceipts/#{contribution_id}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class HouseholdListReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# Options:
|
8
|
+
# :page - (optional) The page number to get.
|
9
|
+
# :per_page - (optional) The number of items to return per page.
|
10
|
+
# :household_id - The household ID to pull the info for.
|
11
|
+
# :search_for - (optional) Search for name in the request.
|
12
|
+
def initialize(options = {})
|
13
|
+
raise 'Household ID not specified' if options[:household_id].nil? and options[:search_for].nil?
|
14
|
+
|
15
|
+
page = options[:page] || 1
|
16
|
+
per_page = options[:per_page] || 100
|
17
|
+
|
18
|
+
@url_data_params = {}
|
19
|
+
@url_data_path = options[:search_for].nil? ? "/v1/Households/#{options[:household_id].to_i}/People" : '/v1/Households/Search'
|
20
|
+
|
21
|
+
@url_data_params.merge!({:page => page}) if page
|
22
|
+
@url_data_params.merge!({:recordsPerPage => per_page}) if per_page
|
23
|
+
@url_data_params.merge!({:search_for => options[:search_for]}) if options[:search_for]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
######### This will be refactored later.
|
32
|
+
|
33
|
+
|
34
|
+
# # Constructor.
|
35
|
+
# #
|
36
|
+
# # Options:
|
37
|
+
# # :page - (optional) The page number to get.
|
38
|
+
# #
|
39
|
+
# # Only one of the optional parameters below can be specified.
|
40
|
+
# # :search_for - (optional) This parameter will be used as: parameter.searchfor like household.householdName.
|
41
|
+
# # :last_activity_date - (optional) This parameter will be used as: parameter.lastActivityDate >= household.lastActivityDate.
|
42
|
+
# # :last_updated_date - (optional) This parameter will be used as: parameter.lastUpdatedDate >= household.lastUpdatedDate.
|
43
|
+
# # :created_date - (optional) This parameter will be used as: parameter.createdDate >= household.createdDate.
|
44
|
+
# def initialize(options = {})
|
45
|
+
# page = options[:page] || 1
|
46
|
+
|
47
|
+
# @url_data_params = {:page => page}
|
48
|
+
# @url_data_path = '/v1/Households/Search'
|
49
|
+
|
50
|
+
# @url_data_params.merge!({:page => page}) if page
|
51
|
+
# if options[:search_for]
|
52
|
+
# @url_data_params.merge!({:searchfor => options[:search_for]})
|
53
|
+
# elsif options[:last_activity_date]
|
54
|
+
# @url_data_params.merge!({:lastActivityDate => options[:last_activity_date]})
|
55
|
+
# elsif options[:last_updated_date]
|
56
|
+
# @url_data_params.merge!({:lastUpdatedDate => options[:last_updated_date]})
|
57
|
+
# elsif options[:created_date]
|
58
|
+
# @url_data_params.merge!({:createdDate => options[:created_date]})
|
59
|
+
# end
|
60
|
+
# ....
|
61
|
+
# end
|
62
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class HouseholdReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param household_id (optional) The ID of the household to load.
|
8
|
+
def initialize(household_id = nil)
|
9
|
+
if household_id.nil?
|
10
|
+
@url_new_data_path = '/v1/Households/New'
|
11
|
+
else
|
12
|
+
@url_data_path = "/v1/Households/#{household_id}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class MemberHouseholdListReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# Options:
|
8
|
+
# :page - (optional) The page number to get.
|
9
|
+
# :filter - (optional) Filter options for the request.
|
10
|
+
# :household_id - The household ID to pull the info for.
|
11
|
+
def initialize(options = {})
|
12
|
+
raise 'Household ID not specified' if options[:household_id].nil?
|
13
|
+
|
14
|
+
page = options[:page] || 1
|
15
|
+
filter = options[:filter]
|
16
|
+
household_id = options[:household_id]
|
17
|
+
|
18
|
+
@url_data_params = options[:url_data_params] || {}
|
19
|
+
@url_data_path = options[:url_data_path] || "/v1/Households/#{household_id}/People"
|
20
|
+
|
21
|
+
@url_data_params.merge!({:page => page}) if page
|
22
|
+
@url_data_params.merge!({:filter => filter}) if filter
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class PersonListReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# Options:
|
8
|
+
# :page - (optional) The page number to get. The default is 1.
|
9
|
+
# :per_page - (optional) The number of items to return per page.
|
10
|
+
# :search_for - (optional) Search for name in the request.
|
11
|
+
# :created_date - (optional) Search for those created on or after specified date.
|
12
|
+
#
|
13
|
+
# ** search params are mutually exclusive and cannot be used with any other search parameters
|
14
|
+
def initialize(options = {})
|
15
|
+
page = options[:page] || 1
|
16
|
+
per_page = options[:per_page] || 100
|
17
|
+
|
18
|
+
@url_data_params = {}
|
19
|
+
@url_data_path = '/v1/People/Search'
|
20
|
+
if options[:search_for].nil? and
|
21
|
+
options[:communication].nil? and
|
22
|
+
options[:created_date].nil? and
|
23
|
+
options[:hsdid].nil?
|
24
|
+
@url_data_path = '/v1/People'
|
25
|
+
end
|
26
|
+
|
27
|
+
@url_data_params.merge!({:page => page, :include => 'addresses,communications'}) if page
|
28
|
+
@url_data_params.merge!({:recordsPerPage => per_page}) if per_page
|
29
|
+
@url_data_params.merge!({:hsdid => options[:hsdid]}) if options[:hsdid]
|
30
|
+
@url_data_params.merge!({:searchFor => options[:search_for]}) if options[:search_for]
|
31
|
+
@url_data_params.merge!({:communication => options[:communication]}) if options[:communication]
|
32
|
+
@url_data_params.merge!({:createdDate => options[:created_date]}) if options[:created_date]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class PersonReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param person_id (optional) The ID of the person to load.
|
8
|
+
def initialize(person_id = nil)
|
9
|
+
if person_id.nil?
|
10
|
+
@url_new_data_path = '/v1/People/New'
|
11
|
+
else
|
12
|
+
@url_data_path = "/v1/People/#{person_id}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
# This adapter is the standard for all saving objects.
|
4
|
+
class ApiWriter
|
5
|
+
attr_reader :error_messages, :response_code
|
6
|
+
|
7
|
+
# Saves this object.
|
8
|
+
#
|
9
|
+
# @return True or ID on success, otherwise false.
|
10
|
+
def save_object
|
11
|
+
@url_data_params ||= {}
|
12
|
+
success = true
|
13
|
+
|
14
|
+
if @url_data_path.nil?
|
15
|
+
@error_messages = ["#{@url_action.to_s.upcase} not implemented for #{self.class.to_s}"]
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
if @updatable_fields and !@updatable_fields.empty?
|
20
|
+
# fields_to_remove = @url_data_params.keys - @updatable_fields
|
21
|
+
# fields_to_remove.each { |ftr| @url_data_params.delete(ftr) }
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
response = FellowshipOne::api_request(@url_action, @url_data_path, [], @url_data_params.to_json)
|
26
|
+
@response_code = response.code
|
27
|
+
# No content but is a success
|
28
|
+
success = response.code == 204 ? {'success' => true} : JSON.parse(response.body)
|
29
|
+
rescue Exception => e
|
30
|
+
@error_messages = e.message.split(',')
|
31
|
+
success = false
|
32
|
+
end
|
33
|
+
|
34
|
+
return success
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Deletes this object.
|
39
|
+
#
|
40
|
+
# @return True or ID on success, otherwise false.
|
41
|
+
def delete_object
|
42
|
+
success = true
|
43
|
+
|
44
|
+
if @url_data_delete_path.nil?
|
45
|
+
@error_messages = ["DELETE not implemented for #{self.class.to_s}"]
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
# @url_data_path should be the same as :put if this object is already
|
51
|
+
# setup and mapped to an object that exists
|
52
|
+
response = FellowshipOne::api_request(:delete, @url_data_delete_path)
|
53
|
+
success = response.code == 204 ? true : false # No content but is a success
|
54
|
+
rescue Exception => e
|
55
|
+
@error_messages = e.message.split(',')
|
56
|
+
success = false
|
57
|
+
end
|
58
|
+
|
59
|
+
return success
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class CommunicationWriter < ApiWriter
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
# Note: writer will get data after it has been mapped to the FellowshipOne
|
7
|
+
# resource so the hash keys will be the same as FellowshipOne
|
8
|
+
#
|
9
|
+
# @param data The json object data to save.
|
10
|
+
def initialize(data)
|
11
|
+
if data[:id]
|
12
|
+
@url_action = :put
|
13
|
+
@url_data_path = "/v1/People/#{data['person']['@id']}/Communications/#{data['@id']}"
|
14
|
+
else
|
15
|
+
@url_action = :post
|
16
|
+
@url_data_path = "/v1/People/#{data['person']['@id']}/Communications"
|
17
|
+
end
|
18
|
+
@url_data_delete_path = "/v1/Communications/#{data['@id']}"
|
19
|
+
|
20
|
+
@url_data_params = @url_data_params = {:communication => data}
|
21
|
+
|
22
|
+
@updatable_fields = []
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FellowshipOne
|
2
|
+
|
3
|
+
class ContributionWriter < ApiWriter
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param data The json object data to save.
|
8
|
+
def initialize(data)
|
9
|
+
if data[:id]
|
10
|
+
@url_action = :put
|
11
|
+
@url_data_path = "/giving/v1/contributionreceipts/#{data[:id]}"
|
12
|
+
else
|
13
|
+
@url_action = :post
|
14
|
+
@url_data_path = "/giving/v1/contributionreceipts"
|
15
|
+
end
|
16
|
+
@url_data_delete_path = "/giving/v1/contributionreceipts/#{data[:id]}"
|
17
|
+
|
18
|
+
@url_data_params = @url_data_params = {:contributionReceipt => data}
|
19
|
+
|
20
|
+
@updatable_fields = [:amount,
|
21
|
+
:fund, #required
|
22
|
+
:received_date, #required
|
23
|
+
:contribution_type] #required
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|