household_people_and_contributions 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9c256d0c422ecb7162b855841d3507fd2a25db1
4
- data.tar.gz: 211ebb18cef5728653bf696369186f8b4c5ef785
3
+ metadata.gz: 1d9a91c47d27bfa976f854fd2a85ca6eb12cf2d8
4
+ data.tar.gz: 5dc77e700b48af65c6fdc4bcf59bf6d183976d9c
5
5
  SHA512:
6
- metadata.gz: 4fa7d7353e2ffc639595f1c8d13713291abc503460b0da1c17a881f77fb519d57bc63515fa75a0bc706b82533c9dc55e5dd0671ce556eec529552bc1c31a8289
7
- data.tar.gz: 0282a8c4d2cd1d81ffe6fd20d8b0759905af8bb6ddef57d4c005600d61f89f8a85dd5bfb445f963fe25938fd4300a3f8d5d9d197053718cd628e306d22f98b39
6
+ metadata.gz: cfb7c893f52945b2bda79e1037bf1a0986f976de12942be4328930e8d5d4c2961844fcb8ae4ce7ed2a5df3fb86d4c402302127241d45ac665521d434d54379a9
7
+ data.tar.gz: a675043c16ed18ff764fa0793e43e96f43f101b5b00b80f312d9eefd9bd5a837a55c175cf4e3d710d29dd79d94830000014da425bf5d840b508cbf2ff0bd4061
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- household_people_and_contributions (0.0.4)
4
+ household_people_and_contributions (0.0.5)
5
5
  oauth
6
6
 
7
7
  GEM
@@ -6,7 +6,7 @@ begin
6
6
  require "household_people_and_contributions"
7
7
  rescue LoadError => e
8
8
  warn "LoadError: #{e.message.inspect}"
9
- # require_relative "../lib/household_people_and_contributions"
9
+ require_relative "../lib/household_people_and_contributions"
10
10
  end
11
11
 
12
12
  if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
@@ -38,9 +38,9 @@ module HouseholdPeopleAndContributions
38
38
  JSONED_GRADE_FILE = "grade_records.json"
39
39
  JSONED_HOUSEHOLDS_FILE = "household_records.json"
40
40
 
41
- HOUSEHOLD_SEARCH_PATH_PREFIX = "/v1/Households/Search.json?searchfor="
41
+ HOUSEHOLD_SEARCH_PATH_PREFIX = "/v1/Households/Search.json?include=communications&searchfor="
42
42
  PEOPLE_RECORDS_PATH_TEMPLATE = "/v1/Households/%s/People.json"
43
- ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT = "/v1/People/Search.json?id=%s&include=attributes"
43
+ ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT = "/v1/People/Search.json?id=%s&include=communications,attributes"
44
44
  CONTRIBUTION_RECORDS_PATH_TEMPLATE = "/giving/v1/contributionreceipts/search.json?householdID=%s&startReceivedDate=%s&endReceivedDate=%s"
45
45
 
46
46
  def key
@@ -295,6 +295,33 @@ module HouseholdPeopleAndContributions
295
295
  return @people
296
296
  end
297
297
 
298
+ def parent_records(id_list_csv, options={})
299
+ @parent_records = []
300
+ emailable_parent_records_path = ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT % id_list_csv
301
+ emailable_parent_records_path = "#{emailable_parent_records_path}&#{options[:extra_params]}"
302
+ parent_results = lookup(emailable_parent_records_path, JSONED_GRADE_FILE, prefix: id_list_csv.gsub(',','_'))
303
+
304
+ parent_results.each do |results|
305
+ parents_array = results["results"]["person"]
306
+ @parent_records += parents_array.reduce([]) { |memo, parent_record|
307
+
308
+ if parent_record["communications"]
309
+ tmp_record = {}
310
+ communications_array = parent_record["communications"]["communication"]
311
+ communications_array.each do |communication_entry|
312
+ if communication_entry["communicationType"]["name"].downcase == "email"
313
+ tmp_record["key"] = communication_entry["person"]["@id"]
314
+ tmp_record["email"] = communication_entry["communicationValue"]
315
+ end
316
+ end
317
+ memo << tmp_record.dup if tmp_record["email"]
318
+ end
319
+ memo
320
+ }
321
+ end
322
+ @parent_records
323
+ end
324
+
298
325
  def scholar_records(id_list_csv, options={})
299
326
  @scholar_records = []
300
327
  attributed_scholar_records_path = ATTRIBUTED_SCHOLAR_RECORDS_PATH_FORMAT % id_list_csv
@@ -321,10 +348,28 @@ module HouseholdPeopleAndContributions
321
348
  end
322
349
 
323
350
 
351
+ def get_people_email_for(people=[], options = {})
352
+ n_at_a_time = options[:recordsPerPage] || 200
353
+ @emailable_people = []
354
+ warn "\n\n\t------------------> HERE\n\n"
355
+ parents = people.select { |person| PARENT_STATUS == person["status"].downcase }
356
+ warn "\n\tparents: #{parents.inspect}\n\n\n"
357
+ extra_params = "recordsPerPage=#{n_at_a_time}"
358
+ while !parents.empty?
359
+ parent_id_list = parents.pop(n_at_a_time).map {|s| s["key"] }
360
+ parent_id_list_csv = parent_id_list.join(",")
361
+ @emailable_people += parent_records(parent_id_list_csv, extra_params: extra_params)
362
+ end
363
+
364
+ return @emailable_people
365
+ end
366
+
324
367
  def get_scholar_grades_for(people=[], options = {})
325
368
  n_at_a_time = options[:recordsPerPage] || 200
326
369
  @attributed_scholars = []
327
- scholars = people.select { |person| SCHOLAR_STATUS == person["status"] }.dup
370
+ warn "\n\n\t------------------> HERE\n\n"
371
+ scholars = people.select { |person| SCHOLAR_STATUS == person["status"].downcase }
372
+ warn "\n\tscholars: #{scholars.inspect}\n\n\n"
328
373
  extra_params = "recordsPerPage=#{n_at_a_time}"
329
374
  while !scholars.empty?
330
375
  scholar_id_list = scholars.pop(n_at_a_time).map {|s| s["key"] }
@@ -346,6 +391,16 @@ module HouseholdPeopleAndContributions
346
391
  return hh
347
392
  end
348
393
 
394
+ def add_email_to_people(em, pp)
395
+ em.each do |parent|
396
+ person = pp.detect { |p| p["key"] == parent["key"] }
397
+ if person
398
+ person["email"] = parent["email"]
399
+ end
400
+ end
401
+ return pp
402
+ end
403
+
349
404
  def add_grades_to_people(as, pp)
350
405
  as.each do |scholar|
351
406
  person = pp.detect { |p| p["key"] == scholar["key"] }
@@ -380,6 +435,8 @@ module HouseholdPeopleAndContributions
380
435
  def as
381
436
  unless @as
382
437
  @as = get_scholar_grades_for(pp, recordsPerPage: 200)
438
+ @em = get_people_email_for(pp, recordsPerPage: 200)
439
+ @pp = add_email_to_people(@em, pp)
383
440
  @pp = add_grades_to_people(@as, pp)
384
441
  end
385
442
  @as
@@ -399,6 +456,7 @@ module HouseholdPeopleAndContributions
399
456
  end
400
457
 
401
458
  def report
459
+ as # get people, add grades to them...
402
460
  warn "\n--> people and scholars: "
403
461
  File.write(OUTPUT_DIR + "/" + "people.json", pp.to_json)
404
462
  puts pp.to_json
@@ -1,3 +1,3 @@
1
1
  module HouseholdPeopleAndContributions
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: household_people_and_contributions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Tee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec