household_people_and_contributions 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +72 -0
- data/README.txt +17 -0
- data/Rakefile +1 -0
- data/bin/household_people_and_contributions.rb +14 -0
- data/cache/.keep +0 -0
- data/config/.keep +0 -0
- data/config/f1_keys_rb.sample +28 -0
- data/household_people_and_contributions.gemspec +27 -0
- data/lib/household_people_and_contributions.rb +11 -0
- data/lib/household_people_and_contributions/client.rb +416 -0
- data/lib/household_people_and_contributions/version.rb +3 -0
- data/output/.keep +0 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41b8b5cdba9af60a25fbd1a9f9ac7c898c99adf8
|
4
|
+
data.tar.gz: ea6f562ad2ffcfa5d9196061315db9ba5bb46dd1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7ee6e8ba6126cb6922d37f1976ff4e154db58781e93d5b9f39a6b12bfbfd598329c8261240a64e77501c1aea446f862b47c4344c59ec837b46f2b39a314656a
|
7
|
+
data.tar.gz: c7afcb7d370b8187d55ffa1f5b74f53031a32eb264ca95257ac6b1635de4ca81efa71b9732632296426064d9b90bbd2d88c47c8cbfa801163f2c044ef4892d28
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
household_people_and_contributions
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.4
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
household_people_and_contributions (0.0.1)
|
5
|
+
f1api
|
6
|
+
fellowshipone-api
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (4.2.5)
|
12
|
+
activesupport (= 4.2.5)
|
13
|
+
builder (~> 3.1)
|
14
|
+
activeresource (4.0.0)
|
15
|
+
activemodel (~> 4.0)
|
16
|
+
activesupport (~> 4.0)
|
17
|
+
rails-observers (~> 0.1.1)
|
18
|
+
activesupport (4.2.5)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
builder (3.2.2)
|
25
|
+
diff-lcs (1.2.5)
|
26
|
+
ethon (0.6.3)
|
27
|
+
ffi (>= 1.3.0)
|
28
|
+
mime-types (~> 1.18)
|
29
|
+
f1api (0.10.0)
|
30
|
+
activeresource
|
31
|
+
oauth (>= 0.4.4)
|
32
|
+
fellowshipone-api (0.9.0)
|
33
|
+
oauth_weshays (= 0.4.8.pre2)
|
34
|
+
typhoeus (= 0.6.6)
|
35
|
+
ffi (1.9.10)
|
36
|
+
i18n (0.7.0)
|
37
|
+
json (1.8.3)
|
38
|
+
mime-types (1.25.1)
|
39
|
+
minitest (5.8.3)
|
40
|
+
oauth (0.4.7)
|
41
|
+
oauth_weshays (0.4.8.pre2)
|
42
|
+
rails-observers (0.1.2)
|
43
|
+
activemodel (~> 4.0)
|
44
|
+
rspec (3.4.0)
|
45
|
+
rspec-core (~> 3.4.0)
|
46
|
+
rspec-expectations (~> 3.4.0)
|
47
|
+
rspec-mocks (~> 3.4.0)
|
48
|
+
rspec-core (3.4.1)
|
49
|
+
rspec-support (~> 3.4.0)
|
50
|
+
rspec-expectations (3.4.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.4.0)
|
53
|
+
rspec-mocks (3.4.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.4.0)
|
56
|
+
rspec-support (3.4.1)
|
57
|
+
thread_safe (0.3.5)
|
58
|
+
typhoeus (0.6.6)
|
59
|
+
ethon (~> 0.6.1)
|
60
|
+
tzinfo (1.2.2)
|
61
|
+
thread_safe (~> 0.1)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
fellowshipone-api
|
68
|
+
household_people_and_contributions!
|
69
|
+
rspec
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.11.2
|
data/README.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# edit the sample from this gem (/repo), to setup your f1_keys.rb file
|
2
|
+
# e.g.
|
3
|
+
# gem which household_people_and_contributions
|
4
|
+
# now get the sample config file that is relative to the parent directory of that file's directory
|
5
|
+
# config/f1_keys_rb.sample
|
6
|
+
# be sure you have the local dirs:
|
7
|
+
# o cache
|
8
|
+
# o config
|
9
|
+
# o output
|
10
|
+
|
11
|
+
KEY_FILE=`pwd`/config/f1_keys.rb ./bin/household_people_and_contributions.rb
|
12
|
+
# OR:
|
13
|
+
KEY_FILE=`pwd`/config/f1_keys.rb irb -r "./bin/household_people_and_contributions.rb"
|
14
|
+
> hpac = HouseholdPeopleAndContributions.new
|
15
|
+
> hpac.pp
|
16
|
+
> hpac.contributions_by_household
|
17
|
+
> hpac.hh
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
gem "household_people_and_contributions"
|
6
|
+
require "household_people_and_contributions"
|
7
|
+
rescue LoadError => e
|
8
|
+
warn "LoadError: #{e.message.inspect}"
|
9
|
+
# require_relative "../lib/household_people_and_contributions"
|
10
|
+
end
|
11
|
+
|
12
|
+
if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
13
|
+
HouseholdPeopleAndContributions::Client.report
|
14
|
+
end
|
data/cache/.keep
ADDED
File without changes
|
data/config/.keep
ADDED
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module F1Keys
|
2
|
+
|
3
|
+
CONSUMER_KEY = 'DDD'
|
4
|
+
CONSUMER_SECRET = 'DA-da'
|
5
|
+
ENVIRONMENT = 'staging'
|
6
|
+
CHURCH_CODE = 'code' # must be lower-case
|
7
|
+
|
8
|
+
# http://developer.fellowshipone.com/test_harness/index.php
|
9
|
+
# CALLBACK_URL = 'http://portal.fellowshipone.com/fellowship_one_connect'
|
10
|
+
|
11
|
+
# callback is the URL on THIS server (assuming this app is hosted):
|
12
|
+
CALLBACK_URL = 'http://www.example.com/fellowship_one_connect'
|
13
|
+
#'https://demo.fellowshiponeapi.com/'
|
14
|
+
|
15
|
+
OAUTH_TOKEN = '*** OAUTH TOKEN ***'
|
16
|
+
OAUTH_SECRET = '*** OAUTH SECRET ***'
|
17
|
+
|
18
|
+
# need to base64 encode username:pwd, too:
|
19
|
+
USERNAME = '** USERNAME **'
|
20
|
+
PASSWORD = '** PWD **'
|
21
|
+
require 'cgi'
|
22
|
+
require 'base64'
|
23
|
+
BODY = CGI.escape(Base64.strict_encode64("#{USERNAME} #{PASSWORD}"))
|
24
|
+
|
25
|
+
###############################################################
|
26
|
+
IS_PRODUCTION = ENVIRONMENT == 'production' ? true : false
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "household_people_and_contributions/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "household_people_and_contributions"
|
7
|
+
s.version = HouseholdPeopleAndContributions::VERSION
|
8
|
+
s.authors = ["Jay Tee"]
|
9
|
+
s.email = ["jaytee@jayteesf.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Extract GSP Data from Fellowshipone}
|
12
|
+
s.description = %q{Extract GSP Data from Fellowshipone}
|
13
|
+
|
14
|
+
s.rubyforge_project = "household_people_and_contributions"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
|
23
|
+
# specify any dependencies here; for example:
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
25
|
+
s.add_runtime_dependency 'f1api'
|
26
|
+
s.add_runtime_dependency 'fellowshipone-api' #, require: 'fellowshipone'
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
#require "rubygems"
|
5
|
+
gem 'fellowshipone-api', require: 'fellowshipone'
|
6
|
+
|
7
|
+
module HouseholdPeopleAndContributions
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative "./household_people_and_contributions/version"
|
11
|
+
require_relative "./household_people_and_contributions/client"
|
@@ -0,0 +1,416 @@
|
|
1
|
+
module HouseholdPeopleAndContributions
|
2
|
+
class Client
|
3
|
+
def self.help(error_message = "")
|
4
|
+
help_message = <<-HM
|
5
|
+
#{error_message}
|
6
|
+
|
7
|
+
KEY_FILE=`pwd`/config/f1_keys.rb ./bin/household_people_and_contributions.rb
|
8
|
+
# OR:
|
9
|
+
KEY_FILE=`pwd`/config/f1_keys.rb irb -r "./bin/household_people_and_contributions.rb"
|
10
|
+
> hpac = HouseholdPeopleAndContributions.new
|
11
|
+
> hpac.pp
|
12
|
+
> hpac.contributions_by_household
|
13
|
+
> hpac.hh
|
14
|
+
HM
|
15
|
+
return help_message
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.report
|
19
|
+
new.report
|
20
|
+
end
|
21
|
+
|
22
|
+
CACHE_DIR = "./cache"
|
23
|
+
fail help("missing cache_dir: #{CACHE_DIR.inspect}") unless File.exists?(CACHE_DIR)
|
24
|
+
CONFIG_DIR = "./config"
|
25
|
+
fail help("missing config_dir: #{CONFIG_DIR.inspect}") unless File.exists?(CONFIG_DIR)
|
26
|
+
KEY_FILE = ENV['KEY_FILE']
|
27
|
+
fail help("missing KEY_FILE: #{KEY_FILE.inspect}") unless KEY_FILE && File.exists?(KEY_FILE)
|
28
|
+
require_relative(KEY_FILE)
|
29
|
+
|
30
|
+
OUTPUT_DIR = "./output"
|
31
|
+
fail help("missing output_dir: #{OUTPUT_DIR.inspect}") unless File.exists?(OUTPUT_DIR)
|
32
|
+
|
33
|
+
MARSHALED_ACCESS_TOKEN_FILE = "#{CONFIG_DIR}/access_token_marshal.txt"
|
34
|
+
YAMLED_ACCESS_TOKEN_FILE = "#{CONFIG_DIR}/access_token.yml"
|
35
|
+
|
36
|
+
JSONED_CONTRIBUTION_FILE = "contribution_records.json"
|
37
|
+
JSONED_PEOPLE_FILE = "people_records.json"
|
38
|
+
JSONED_GRADE_FILE = "grade_records.json"
|
39
|
+
JSONED_HOUSEHOLDS_FILE = "household_records.json"
|
40
|
+
|
41
|
+
HOUSEHOLD_SEARCH_PATH_PREFIX = "/v1/Households/Search.json?searchfor="
|
42
|
+
PEOPLE_RECORDS_PATH_TEMPLATE = "/v1/Households/%s/People.json"
|
43
|
+
ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT = "/v1/People/Search.json?id=%s&include=attributes"
|
44
|
+
CONTRIBUTION_RECORDS_PATH_TEMPLATE = "/giving/v1/contributionreceipts/search.json?householdID=%s&startReceivedDate=%s&endReceivedDate=%s"
|
45
|
+
|
46
|
+
def key
|
47
|
+
unless @key
|
48
|
+
@key =
|
49
|
+
F1Keys::CONSUMER_KEY
|
50
|
+
end
|
51
|
+
@key
|
52
|
+
end
|
53
|
+
|
54
|
+
def secret
|
55
|
+
unless @secret
|
56
|
+
@secret =
|
57
|
+
F1Keys::CONSUMER_SECRET
|
58
|
+
end
|
59
|
+
@secret
|
60
|
+
end
|
61
|
+
|
62
|
+
def consumer
|
63
|
+
unless @consumer
|
64
|
+
@consumer = OAuth::Consumer.new(key, secret, {
|
65
|
+
site: "https://#{F1Keys::CHURCH_CODE}.#{F1Keys::ENVIRONMENT}.fellowshiponeapi.com",
|
66
|
+
request_token_path: "/v1/Tokens/RequestToken",
|
67
|
+
authorize_path: "/v1/PortalUser/Login",
|
68
|
+
# access_token_path: "/v1/Tokens/AccessToken",
|
69
|
+
access_token_path: "/v1/PortalUser/AccessToken", # per some blog post
|
70
|
+
|
71
|
+
http_method: :get, #vs. :post,
|
72
|
+
scheme: :header, # vs. :body, # vs. :query_string,
|
73
|
+
})
|
74
|
+
end
|
75
|
+
@consumer
|
76
|
+
end
|
77
|
+
|
78
|
+
def oauth_tokens?
|
79
|
+
F1Keys::OAUTH_TOKEN && F1Keys::OAUTH_SECRET
|
80
|
+
end
|
81
|
+
|
82
|
+
def access_token
|
83
|
+
unless @access_token
|
84
|
+
if oauth_tokens?
|
85
|
+
@access_token = OAuth::AccessToken.new(consumer, F1Keys::OAUTH_TOKEN, F1Keys::OAUTH_SECRET)
|
86
|
+
end
|
87
|
+
unless @access_token
|
88
|
+
if File.exists?(MARSHALED_ACCESS_TOKEN_FILE)
|
89
|
+
@access_token = Marshal::load(File.read(MARSHALED_ACCESS_TOKEN_FILE))
|
90
|
+
# @access_token = YAML::load(File.read(YAMLED_ACCESS_TOKEN_FILE))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
unless @access_token
|
94
|
+
# @request_token = @consumer.get_request_token('Authorization' => F1Keys::BODY)
|
95
|
+
# @request_token = @consumer.get_request_token({}, F1Keys::BODY)
|
96
|
+
# @request_token = @consumer.get_request_token({}, 'Authorize' => F1Keys::BODY)
|
97
|
+
# @request_token = @consumer.get_request_token({request_body: F1Keys::BODY})
|
98
|
+
@request_token = consumer.get_request_token()
|
99
|
+
|
100
|
+
warn @request_token.token
|
101
|
+
warn @request_token.secret
|
102
|
+
|
103
|
+
warn "\nPaste URL into your browser:\n\n"
|
104
|
+
|
105
|
+
warn @request_token.authorize_url
|
106
|
+
|
107
|
+
warn "\nPress Enter when Done\n\n"
|
108
|
+
|
109
|
+
gets
|
110
|
+
|
111
|
+
@access_token = @request_token.get_access_token
|
112
|
+
|
113
|
+
warn "Access Token:"
|
114
|
+
warn @access_token.inspect
|
115
|
+
warn "\nDone inspecting...\n"
|
116
|
+
|
117
|
+
File.write(MARSHALED_ACCESS_TOKEN_FILE, Marshal.dump(@access_token))
|
118
|
+
File.write(YAMLED_ACCESS_TOKEN_FILE, YAML.dump(@access_token))
|
119
|
+
|
120
|
+
warn "\nAccess Token is now saved for future use"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
@access_token
|
124
|
+
end
|
125
|
+
|
126
|
+
def get(path, key=nil)
|
127
|
+
loop_again = true
|
128
|
+
current_page_number = 1
|
129
|
+
records = []
|
130
|
+
while loop_again
|
131
|
+
paged_path = key.nil? ? path : "#{path}&page=#{current_page_number}"
|
132
|
+
|
133
|
+
warn "GET'ing: #{paged_path.inspect}..."
|
134
|
+
response = access_token.get(paged_path)
|
135
|
+
|
136
|
+
response_body = response.body
|
137
|
+
warn "BODY: #{response_body.inspect}..."
|
138
|
+
json_body = JSON.parse(response_body)
|
139
|
+
|
140
|
+
results = key.nil? ? json_body : json_body[key]
|
141
|
+
|
142
|
+
records << results
|
143
|
+
|
144
|
+
if results["@additionalPages"] && results["@additionalPages"] != "0"
|
145
|
+
loop_again = true
|
146
|
+
fail("odd page number: #{results['@pageNumber']}") unless results["@pageNumber"] == current_page_number.to_s
|
147
|
+
current_page_number += 1
|
148
|
+
sleep 5
|
149
|
+
else
|
150
|
+
loop_again = false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
return records
|
154
|
+
end
|
155
|
+
|
156
|
+
def lookup(records_path, cache_file, options={})
|
157
|
+
if options.key?(:prefix) && options[:prefix]
|
158
|
+
cache_file = options[:prefix] + "_" + cache_file
|
159
|
+
end
|
160
|
+
cache_file = CACHE_DIR + "/" + cache_file
|
161
|
+
if File.exists?(cache_file)
|
162
|
+
results_array = JSON.parse(File.read(cache_file))
|
163
|
+
else
|
164
|
+
results_array = get(records_path, options[:key])
|
165
|
+
File.write(cache_file, results_array.to_json)
|
166
|
+
end
|
167
|
+
return results_array
|
168
|
+
end
|
169
|
+
|
170
|
+
def household_records(household_records_path)
|
171
|
+
@household_records = []
|
172
|
+
household_results = lookup(household_records_path, JSONED_HOUSEHOLDS_FILE, key: "results")
|
173
|
+
|
174
|
+
household_results.each do |results|
|
175
|
+
household_array = results["household"]
|
176
|
+
@household_records += household_array.reduce([]) { |memo, household_record|
|
177
|
+
tmp_record = {}
|
178
|
+
tmp_record["id"] = household_record["@id"]
|
179
|
+
tmp_record["household_name"] = household_record["householdName"]
|
180
|
+
tmp_record["household_sort_name"] = household_record["householdSortName"]
|
181
|
+
tmp_record["created_date"] = household_record["createdDate"]
|
182
|
+
tmp_record["updated_date"] = household_record["lastUpdatedDate"]
|
183
|
+
memo << tmp_record.dup
|
184
|
+
memo
|
185
|
+
}
|
186
|
+
end
|
187
|
+
@household_records
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_contributions_for_households(households=[], from=nil, upto_but_not_including=nil)
|
191
|
+
@contributions = []
|
192
|
+
household_ids_for(households).each do |household_id|
|
193
|
+
@contributions += contribution_records(household_id, from, upto_but_not_including)
|
194
|
+
end
|
195
|
+
return @contributions
|
196
|
+
end
|
197
|
+
|
198
|
+
# may-1 -> may-1
|
199
|
+
# if < may1 # jan - apr 30th ...current-year
|
200
|
+
# if >= may1 # may - dec ...next-year
|
201
|
+
def contribution_records(household_id, from=nil, upto_but_not_including=nil)
|
202
|
+
@contribution_records = []
|
203
|
+
unless from
|
204
|
+
current_time = Time.now.utc
|
205
|
+
current_month = current_time.month
|
206
|
+
|
207
|
+
current_year = current_time.year
|
208
|
+
previous_year = current_year - 1
|
209
|
+
next_year = current_year + 1
|
210
|
+
|
211
|
+
if current_month < 5 # we're nearing the end of the cycle
|
212
|
+
# from previous year, to current-year
|
213
|
+
from = "#{previous_year}-05-01"
|
214
|
+
upto_but_not_including ||= "#{current_year}-05-01"
|
215
|
+
else
|
216
|
+
# from current year, to next-year
|
217
|
+
from = "#{current_year}-05-01"
|
218
|
+
upto_but_not_including ||= "#{next_year}-05-01"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
path_params = [household_id, from, upto_but_not_including]
|
223
|
+
contributions_path = CONTRIBUTION_RECORDS_PATH_TEMPLATE % path_params
|
224
|
+
contributions_path = "#{contributions_path}&recordsPerPage=200"
|
225
|
+
|
226
|
+
contribution_results = lookup(contributions_path, JSONED_CONTRIBUTION_FILE, key: "results", prefix: path_params.join('_'))
|
227
|
+
|
228
|
+
contribution_results.each do |results|
|
229
|
+
if contribution_array = results["contributionReceipt"]
|
230
|
+
@contribution_records += contribution_array.reduce([]) { |memo, contribution_record|
|
231
|
+
tmp_record = {}
|
232
|
+
tmp_record["id"] = contribution_record["@id"]
|
233
|
+
tmp_record["amount"] = contribution_record["amount"]
|
234
|
+
tmp_record["fund_id"] = contribution_record["fund"]["@id"]
|
235
|
+
tmp_record["fund_name"] = contribution_record["fund"]["name"]
|
236
|
+
tmp_record["household_id"] = contribution_record["household"]["@id"]
|
237
|
+
tmp_record["received_date"] = contribution_record["receivedDate"]
|
238
|
+
tmp_record["transmit_date"] = contribution_record["transmitDate"]
|
239
|
+
tmp_record["created_date"] = contribution_record["createdDate"]
|
240
|
+
|
241
|
+
tmp_record["updated_date"] = contribution_record["lastUpdatedDate"]
|
242
|
+
memo << tmp_record.dup
|
243
|
+
memo
|
244
|
+
}
|
245
|
+
end
|
246
|
+
end
|
247
|
+
@contribution_records
|
248
|
+
end
|
249
|
+
|
250
|
+
SCHOLAR_STATUS = "scholar"
|
251
|
+
PARENT_STATUS = "parent"
|
252
|
+
VALID_STATUSES = [SCHOLAR_STATUS, PARENT_STATUS]
|
253
|
+
def people_records(household_id)
|
254
|
+
people_records_path = PEOPLE_RECORDS_PATH_TEMPLATE % household_id
|
255
|
+
|
256
|
+
@people_records = []
|
257
|
+
people_results = lookup(people_records_path, JSONED_PEOPLE_FILE, prefix: household_id)
|
258
|
+
|
259
|
+
people_results.each do |results|
|
260
|
+
persons_array = results["people"]["person"]
|
261
|
+
@people_records += persons_array.reduce([]) { |memo, person_record|
|
262
|
+
|
263
|
+
status = person_record["status"]["name"].downcase
|
264
|
+
if VALID_STATUSES.include?(status) && household_id == person_record["@householdID"]
|
265
|
+
tmp_record = {}
|
266
|
+
|
267
|
+
tmp_record["id"] = person_record["@id"]
|
268
|
+
tmp_record["household_id"] = person_record["@householdID"]
|
269
|
+
tmp_record["status"] = status
|
270
|
+
|
271
|
+
tmp_record["first_name"] = person_record["firstName"]
|
272
|
+
tmp_record["last_name"] = person_record["lastName"]
|
273
|
+
tmp_record["suffix"] = person_record["suffix"]
|
274
|
+
|
275
|
+
tmp_record["created_date"] = person_record["createdDate"]
|
276
|
+
tmp_record["updated_date"] = person_record["lastUpdatedDate"]
|
277
|
+
|
278
|
+
memo << tmp_record.dup
|
279
|
+
end
|
280
|
+
memo
|
281
|
+
}
|
282
|
+
end
|
283
|
+
@people_records
|
284
|
+
end
|
285
|
+
|
286
|
+
def household_ids_for(households)
|
287
|
+
households.map { |household_record| household_record["id"] }
|
288
|
+
end
|
289
|
+
|
290
|
+
def get_people_in_households(households=[])
|
291
|
+
@people = []
|
292
|
+
household_ids_for(households).each do |household_id|
|
293
|
+
@people += people_records(household_id)
|
294
|
+
end
|
295
|
+
return @people
|
296
|
+
end
|
297
|
+
|
298
|
+
def scholar_records(id_list_csv, options={})
|
299
|
+
@scholar_records = []
|
300
|
+
attributed_scholar_records_path = ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT % id_list_csv
|
301
|
+
attributed_scholar_records_path = "#{attributed_scholar_records_path}&#{options[:extra_params]}"
|
302
|
+
scholar_results = lookup(attributed_scholar_records_path, JSONED_GRADE_FILE, prefix: id_list_csv.gsub(',','_'))
|
303
|
+
|
304
|
+
scholar_results.each do |results|
|
305
|
+
scholars_array = results["results"]["person"]
|
306
|
+
@scholar_records += scholars_array.reduce([]) { |memo, scholar_record|
|
307
|
+
|
308
|
+
tmp_record = {}
|
309
|
+
attributes_array = scholar_record["attributes"]["attribute"]
|
310
|
+
attributes_array.each do |attribute_entry|
|
311
|
+
if attribute_entry["attributeGroup"]["name"] == "Grade"
|
312
|
+
tmp_record["id"] = attribute_entry["person"]["@id"]
|
313
|
+
tmp_record["grade"] = attribute_entry["attributeGroup"]["attribute"]["name"]
|
314
|
+
end
|
315
|
+
end
|
316
|
+
memo << tmp_record.dup if tmp_record["grade"]
|
317
|
+
memo
|
318
|
+
}
|
319
|
+
end
|
320
|
+
@scholar_records
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
def get_scholar_grades_for(people=[], options = {})
|
325
|
+
n_at_a_time = options[:recordsPerPage] || 200
|
326
|
+
@attributed_scholars = []
|
327
|
+
scholars = people.select { |person| SCHOLAR_STATUS == person["status"] }
|
328
|
+
extra_params = "recordsPerPage=#{n_at_a_time}"
|
329
|
+
while !scholars.empty?
|
330
|
+
scholar_id_list = scholars.pop(n_at_a_time).map {|s| s["id"] }
|
331
|
+
scholar_id_list_csv = scholar_id_list.join(",")
|
332
|
+
@attributed_scholars += scholar_records(scholar_id_list_csv, extra_params: extra_params)
|
333
|
+
end
|
334
|
+
|
335
|
+
return @attributed_scholars
|
336
|
+
end
|
337
|
+
|
338
|
+
def add_contribution_sum_to_households(contributions, hh)
|
339
|
+
contributions.each do |contribution_record|
|
340
|
+
household = hh.detect { |h| h["id"] == contribution_record["household_id"] }
|
341
|
+
if household
|
342
|
+
household["contribution_total"] ||= 0
|
343
|
+
household["contribution_total"] += contribution_record["amount"].to_f
|
344
|
+
end
|
345
|
+
end
|
346
|
+
return hh
|
347
|
+
end
|
348
|
+
|
349
|
+
def add_grades_to_people(as, pp)
|
350
|
+
as.each do |scholar|
|
351
|
+
person = pp.detect { |p| p["id"] == scholar["id"] }
|
352
|
+
if person
|
353
|
+
person["grade"] = scholar["grade"]
|
354
|
+
end
|
355
|
+
end
|
356
|
+
return pp
|
357
|
+
end
|
358
|
+
|
359
|
+
# get all the household(s):
|
360
|
+
def hh
|
361
|
+
unless @hh
|
362
|
+
query = "%"
|
363
|
+
path = "#{HOUSEHOLD_SEARCH_PATH_PREFIX}#{query}"
|
364
|
+
household_records_path = "#{path}&recordsPerPage=200"
|
365
|
+
warn "-> Search Households for #{query}..."
|
366
|
+
@hh = household_records(household_records_path)
|
367
|
+
end
|
368
|
+
@hh
|
369
|
+
end
|
370
|
+
|
371
|
+
# get the people in each household:
|
372
|
+
def pp
|
373
|
+
unless @pp
|
374
|
+
@pp = get_people_in_households(hh)
|
375
|
+
end
|
376
|
+
@pp
|
377
|
+
end
|
378
|
+
|
379
|
+
# attribute the people that are scholars w/ a grade(-level)
|
380
|
+
def as
|
381
|
+
unless @as
|
382
|
+
@as = get_scholar_grades_for(pp, recordsPerPage: 200)
|
383
|
+
@pp = add_grades_to_people(@as, pp)
|
384
|
+
end
|
385
|
+
@as
|
386
|
+
end
|
387
|
+
|
388
|
+
#Search for receipts containing the householdID that is passed with this parameter.
|
389
|
+
#startReceivedDate = search for receipts with a received date greater than or equal to this parameter (format: yyyy-mm-dd).
|
390
|
+
#endReceivedDate = search for receipts with a received date less than or equal to this parameter. Must be used in conjunction with startReceivedDate (format: yyyy-mm-dd).
|
391
|
+
#ex. startReceivedDate=2014-12-15&endReceivedDate=2014-12-16 will give you a 24 hour period.
|
392
|
+
def contributions_by_household
|
393
|
+
unless @contributions_by_household
|
394
|
+
@contributions_by_household = get_contributions_for_households(hh)
|
395
|
+
# merge with household data
|
396
|
+
@hh = add_contribution_sum_to_households(@contributions_by_household, hh)
|
397
|
+
end
|
398
|
+
@contributions_by_household
|
399
|
+
end
|
400
|
+
|
401
|
+
def report
|
402
|
+
warn "--> hh: "
|
403
|
+
File.write(OUTPUT_DIR + "/" + "households.json", hh.to_json)
|
404
|
+
puts hh.to_json
|
405
|
+
|
406
|
+
warn "\n--> people and scholars: "
|
407
|
+
File.write(OUTPUT_DIR + "/" + "people.json", pp.to_json)
|
408
|
+
puts pp.to_json
|
409
|
+
|
410
|
+
warn "\n--> contributions: "
|
411
|
+
File.write(OUTPUT_DIR + "/" + "contributions.json", contributions_by_household.to_json)
|
412
|
+
puts contributions_by_household.to_json
|
413
|
+
return {hh: @hh, pp: @pp, contributions_by_household: @contributions_by_household}
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
data/output/.keep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: household_people_and_contributions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jay Tee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: f1api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fellowshipone-api
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Extract GSP Data from Fellowshipone
|
56
|
+
email:
|
57
|
+
- jaytee@jayteesf.com
|
58
|
+
executables:
|
59
|
+
- household_people_and_contributions.rb
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- README.txt
|
69
|
+
- Rakefile
|
70
|
+
- bin/household_people_and_contributions.rb
|
71
|
+
- cache/.keep
|
72
|
+
- config/.keep
|
73
|
+
- config/f1_keys_rb.sample
|
74
|
+
- household_people_and_contributions.gemspec
|
75
|
+
- lib/household_people_and_contributions.rb
|
76
|
+
- lib/household_people_and_contributions/client.rb
|
77
|
+
- lib/household_people_and_contributions/version.rb
|
78
|
+
- output/.keep
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project: household_people_and_contributions
|
98
|
+
rubygems_version: 2.4.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Extract GSP Data from Fellowshipone
|
102
|
+
test_files: []
|