ruby-fs-stack 0.3.0 → 0.3.2

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/README.rdoc CHANGED
@@ -98,6 +98,19 @@ or for the pure Ruby implementation
98
98
  new_person.id #=> 'KWQS-ZZZ'
99
99
  new_person.version #=> '687799'
100
100
 
101
+ === Selecting the Summary View
102
+
103
+ # assuming you know the value IDs that you want to set as summary
104
+ # grab a person with the ID and version set
105
+ person = communicator.familytree_v2.person 'KWQS-BBQ', :names => 'none', :events => 'none', :genders => 'none'
106
+ person.select_name_summary "100078"
107
+ person.select_birth_summary "1089498"
108
+ person.select_death_summary "7834987"
109
+ # you must set both the mother and the father summary unless you want a single parent as the summary parents.
110
+ person.select_mother_summary "KWQS-MOM"
111
+ person.select_father_summary "KWQS-DAD"
112
+ communicator.save_person person
113
+
101
114
  == RDoc
102
115
 
103
116
  RDoc is hosted at rdoc.info:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
@@ -52,7 +52,7 @@ module FamilytreeV2
52
52
  url = Base + 'person/' + id
53
53
  end
54
54
  end
55
- url += "?"+FsUtils.querystring_from_hash(options) unless options.empty?
55
+ url += add_querystring(options)
56
56
  response = @fs_communicator.get(url)
57
57
  familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
58
58
  if multiple_ids
@@ -82,7 +82,7 @@ module FamilytreeV2
82
82
  # <tt>search_params</tt> - A hash of search parameters matching API doc
83
83
  def search(search_params)
84
84
  url = Base + 'search'
85
- url += "?" + FsUtils.querystring_from_hash(search_params) unless search_params.empty?
85
+ url += add_querystring(search_params)
86
86
  response = @fs_communicator.get(url)
87
87
  familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
88
88
  # require 'pp'
@@ -106,7 +106,7 @@ module FamilytreeV2
106
106
  else
107
107
  raise ArgumentError, "first parameter must be a kind of String or Hash"
108
108
  end
109
- url += "?" + FsUtils.querystring_from_hash(params_hash) unless params_hash.empty?
109
+ url += add_querystring(params_hash) #"?" + FsUtils.querystring_from_hash(params_hash) unless params_hash.empty?
110
110
  response = @fs_communicator.get(url)
111
111
  familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
112
112
  # require 'pp'
@@ -152,7 +152,7 @@ module FamilytreeV2
152
152
  url = "#{Base}person/#{base_id}/#{relationship_type}/#{with_id}"
153
153
 
154
154
  # Get the existing person/relationship or create a new person
155
- unless person = relationship(base_id,options)
155
+ unless person = relationship(base_id,options.merge({:events => 'none'}))
156
156
  person = Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
157
157
  person.id = base_id
158
158
  end
@@ -177,7 +177,9 @@ module FamilytreeV2
177
177
 
178
178
  # ====Params
179
179
  # * <tt>base_id</tt> - The root person for creating the relationship
180
- # * <tt>options</tt> - Should include either :parent, :spouse, or :child. :lineage and :event is optional
180
+ # * <tt>options</tt> - Should include either :parent, :spouse, or :child. :lineage and :event is optional.
181
+ # Other Relationship Read parameters may be included in options such as :events => 'all',
182
+ # :characteristics => 'all', etc.
181
183
  #
182
184
  # If the :lineage is set, the parent-child relationships will be written via a characteristic.
183
185
  # Otherwise, an exists assertion will be created to just establish the relationship.
@@ -190,6 +192,7 @@ module FamilytreeV2
190
192
  r_type = get_relationship_type(options)
191
193
  with_id = options[r_type.to_sym]
192
194
  url = "#{Base}person/#{base_id}/#{r_type}/#{with_id}"
195
+ url += add_querystring(options)
193
196
  res = @fs_communicator.get(url)
194
197
  familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(res.body)
195
198
  person = familytree.persons.find{|p|p.id == base_id}
@@ -222,6 +225,11 @@ module FamilytreeV2
222
225
  key = keys.find{|k| ['parent','child','spouse'].include? k}
223
226
  key
224
227
  end
228
+
229
+ def add_querystring(options)
230
+ params = options.reject{|k,v| ['parent','child','spouse','lineage','event'].include? k.to_s }
231
+ (params.empty?) ? '' : "?" + FsUtils.querystring_from_hash(params)
232
+ end
225
233
  end
226
234
 
227
235
  end
@@ -292,6 +300,12 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
292
300
  self.value = NameValue.new
293
301
  self.value.add_form(value)
294
302
  end
303
+
304
+ def select(value_id)
305
+ self.action = 'Select'
306
+ self.value = AssertionValue.new
307
+ self.value.id = value_id
308
+ end
295
309
  end
296
310
 
297
311
  class EventValue
@@ -321,6 +335,13 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
321
335
  self.value.add_place(options[:place]) if options[:place]
322
336
  end
323
337
 
338
+ def select(type,value_id)
339
+ self.value = EventValue.new
340
+ self.value.id = value_id
341
+ self.value.type = type
342
+ self.action = 'Select'
343
+ end
344
+
324
345
  # To make porting code from v1 to v2 easier, date will reference
325
346
  # value.date
326
347
  def date
@@ -416,6 +437,13 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
416
437
  n.add_value(value)
417
438
  self.names << n
418
439
  end
440
+
441
+ def select_name(value_id)
442
+ self.names ||= []
443
+ n = NameAssertion.new
444
+ n.select(value_id)
445
+ self.names << n
446
+ end
419
447
 
420
448
  def add_event(options)
421
449
  self.events ||= []
@@ -424,12 +452,20 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
424
452
  self.events << e
425
453
  end
426
454
 
455
+ def select_event_summary(type,value_id)
456
+ self.events ||= []
457
+ e = EventAssertion.new
458
+ e.select(type,value_id)
459
+ self.events << e
460
+ end
461
+
427
462
  def add_ordinance(options)
428
463
  self.ordinances ||= []
429
464
  o = OrdinanceAssertion.new
430
465
  o.add_value(options)
431
466
  self.ordinances << o
432
467
  end
468
+
433
469
  end
434
470
 
435
471
  class CharacteristicAssertion
@@ -529,6 +565,22 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
529
565
  end
530
566
  end
531
567
 
568
+ class ParentsReference
569
+ def select_parent(parent_id, gender)
570
+ add_parents!
571
+ self.action = 'Select'
572
+ parent = PersonReference.new
573
+ parent.gender = gender
574
+ parent.id = parent_id
575
+ self.parents << parent
576
+ end
577
+
578
+ private
579
+ def add_parents!
580
+ self.parents ||= []
581
+ end
582
+ end
583
+
532
584
  class PersonRelationships
533
585
  def initialize
534
586
  @parents = []
@@ -665,6 +717,23 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
665
717
  assertions.add_name(value)
666
718
  end
667
719
 
720
+ # Select the name for the summary view. This should be called on a Person record that
721
+ # contains a person id and version.
722
+ #
723
+ # ====Params
724
+ # <tt>value_id</tt> - the value id of a name assertion that you would like to set as the summary
725
+ #
726
+ # ===Example
727
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
728
+ # person.select_name_summary('1000134')
729
+ # com.familytree_v2.save_person person
730
+ #
731
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
732
+ def select_name_summary(value_id)
733
+ add_assertions!
734
+ assertions.select_name(value_id)
735
+ end
736
+
668
737
  def births
669
738
  select_events('Birth')
670
739
  end
@@ -702,6 +771,23 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
702
771
  options[:type] = 'Birth'
703
772
  assertions.add_event(options)
704
773
  end
774
+
775
+ # Select the birth for the summary view. This should be called on a Person record that
776
+ # contains a person id and version.
777
+ #
778
+ # ====Params
779
+ # <tt>value_id</tt> - the value id of a birth assertion that you would like to set as the summary
780
+ #
781
+ # ===Example
782
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
783
+ # person.select_birth_summary('1000134')
784
+ # com.familytree_v2.save_person person
785
+ #
786
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
787
+ def select_birth_summary(value_id)
788
+ add_assertions!
789
+ assertions.select_event_summary('Birth',value_id)
790
+ end
705
791
 
706
792
  # Add an event with type of Birth
707
793
  #
@@ -717,6 +803,69 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
717
803
  assertions.add_event(options)
718
804
  end
719
805
 
806
+ # Select the death for the summary view. This should be called on a Person record that
807
+ # contains a person id and version.
808
+ #
809
+ # ====Params
810
+ # <tt>value_id</tt> - the value id of a death assertion that you would like to set as the summary
811
+ #
812
+ # ===Example
813
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
814
+ # person.select_death_summary('1000134')
815
+ # com.familytree_v2.save_person person
816
+ #
817
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
818
+ def select_death_summary(value_id)
819
+ add_assertions!
820
+ assertions.select_event_summary('Death',value_id)
821
+ end
822
+
823
+ # Select the mother for the summary view. This should be called on a Person record that
824
+ # contains a person id and version.
825
+ #
826
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
827
+ # set a single parent as the summary.
828
+ #
829
+ # ====Params
830
+ # <tt>person_id</tt> - the person id of the mother that you would like to set as the summary
831
+ #
832
+ # ===Example
833
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
834
+ # person.select_mother_summary('KWQS-BBQ')
835
+ # person.select_father_summary('KWQS-BBT')
836
+ # com.familytree_v2.save_person person
837
+ #
838
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
839
+ def select_mother_summary(person_id)
840
+ add_parents!
841
+ couple = parents[0] || ParentsReference.new
842
+ couple.select_parent(person_id,'Female')
843
+ parents << couple
844
+ end
845
+
846
+ # Select the father for the summary view. This should be called on a Person record that
847
+ # contains a person id and version.
848
+ #
849
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
850
+ # set a single parent as the summary.
851
+ #
852
+ # ====Params
853
+ # <tt>person_id</tt> - the person id of the father that you would like to set as the summary
854
+ #
855
+ # ===Example
856
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
857
+ # person.select_father_summary('KWQS-BBQ')
858
+ # person.select_mother_summary('KWQS-BBT')
859
+ # com.familytree_v2.save_person person
860
+ #
861
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
862
+ def select_father_summary(person_id)
863
+ add_parents!
864
+ couple = parents[0] || ParentsReference.new
865
+ couple.select_parent(person_id,'Male')
866
+ parents << couple
867
+ end
868
+
720
869
  def baptisms
721
870
  select_ordinances('Baptism')
722
871
  end
@@ -844,6 +993,10 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
844
993
 
845
994
  private
846
995
 
996
+ def add_parents!
997
+ self.parents ||= []
998
+ end
999
+
847
1000
  def add_relationships!
848
1001
  self.relationships ||= PersonRelationships.new
849
1002
  end
@@ -7,12 +7,12 @@ class FsUtils
7
7
  v.collect do |k2,v2|
8
8
  k2 = k2.to_s
9
9
  v2 = v2.to_s
10
- url_encode(v2)
10
+ v2 = url_encode(v2)
11
11
  "#{k}.#{k2}=#{v2}"
12
12
  end.join('&')
13
13
  else
14
14
  v = v.to_s
15
- self.url_encode(v)
15
+ v = self.url_encode(v)
16
16
  k + '=' + v
17
17
  end
18
18
  end
@@ -22,6 +22,6 @@ class FsUtils
22
22
  private
23
23
  def self.url_encode(string)
24
24
  # Taken from http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/156044
25
- string.gsub!( /[^a-zA-Z0-9\-_\.!~*'()]/n ) {|x| sprintf('%%%02x', x[0]) }
25
+ string.gsub( /[^a-zA-Z0-9\-_\.!~*'()]/n ) {|x| sprintf('%%%02x', x[0]) }
26
26
  end
27
27
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-fs-stack}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jimmy Zimmerman"]
12
- s.date = %q{2009-12-18}
12
+ s.date = %q{2010-01-07}
13
13
  s.description = %q{A library that enables you to read and update information with the new.familysearch.org API.}
14
14
  s.email = %q{jimmy.zimmerman@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -274,7 +274,7 @@ describe FamilytreeV2::Communicator do
274
274
  end
275
275
 
276
276
  it "should first try to read the relationship" do
277
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
277
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR?events=none').and_return(@res)
278
278
  @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
279
279
  end
280
280
 
@@ -339,7 +339,7 @@ describe FamilytreeV2::Communicator do
339
339
  end
340
340
 
341
341
  it "should first try to read the relationship" do
342
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
342
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR?events=none').and_return(@res)
343
343
  @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
344
344
  end
345
345
 
@@ -274,6 +274,104 @@ describe Org::Familysearch::Ws::Familytree::V2::Schema::Person do
274
274
  end
275
275
  end
276
276
 
277
+ describe "selecting summaries" do
278
+ before(:each) do
279
+ @person = parse_person('KJ86-3VD_version.js')
280
+ end
281
+
282
+ describe "select_name_summary" do
283
+
284
+ it "should accept a value ID" do
285
+ @person.select_name_summary('10001')
286
+ end
287
+
288
+ it "should add a name assertion with action, value, and id" do
289
+ @person.select_name_summary('10001')
290
+ @person.assertions.names[0].value.id.should == '10001'
291
+ @person.assertions.names[0].action.should == 'Select'
292
+ end
293
+
294
+ end
295
+
296
+ describe "select_birth_summary" do
297
+
298
+ it "should accept a value ID" do
299
+ @person.select_birth_summary('10001')
300
+ end
301
+
302
+ it "should add a name assertion with action, value, and id" do
303
+ @person.select_birth_summary('10001')
304
+ @person.births[0].value.id.should == '10001'
305
+ @person.births[0].action.should == 'Select'
306
+ end
307
+
308
+ end
309
+
310
+ describe "select_death_summary" do
311
+
312
+ it "should accept a value ID" do
313
+ @person.select_death_summary('10001')
314
+ end
315
+
316
+ it "should add a name assertion with action, value, and id" do
317
+ @person.select_death_summary('10002')
318
+ @person.deaths[0].value.id.should == '10002'
319
+ @person.deaths[0].action.should == 'Select'
320
+ end
321
+
322
+ end
323
+
324
+ describe "select_mother_summary" do
325
+
326
+ it "should accept a parent ID" do
327
+ @person.select_mother_summary('KWQS-BBR')
328
+ end
329
+
330
+ it "should set the parents with given mother as a selected parent" do
331
+ @person.select_mother_summary('KWQS-BBR')
332
+ @person.parents[0].parents[0].id.should == 'KWQS-BBR'
333
+ @person.parents[0].parents[0].gender.should == 'Female'
334
+ @person.parents[0].action.should == 'Select'
335
+ end
336
+
337
+ end
338
+
339
+ describe "select_father_summary" do
340
+
341
+ it "should accept a parent ID" do
342
+ @person.select_father_summary('KWQS-BBQ')
343
+ end
344
+
345
+ it "should set the parents with given mother as a selected parent" do
346
+ @person.select_father_summary('KWQS-BBQ')
347
+ @person.parents[0].parents[0].id.should == 'KWQS-BBQ'
348
+ @person.parents[0].parents[0].gender.should == 'Male'
349
+ @person.parents[0].action.should == 'Select'
350
+ end
351
+
352
+ end
353
+
354
+ describe "select_father_summary and select_mother_summary" do
355
+
356
+ it "should accept a parent ID" do
357
+ @person.select_mother_summary('KWQS-BBR')
358
+ @person.select_father_summary('KWQS-BBQ')
359
+ end
360
+
361
+ it "should set the parents with given mother as a selected parent" do
362
+ @person.select_mother_summary('KWQS-BBR')
363
+ @person.select_father_summary('KWQS-BBQ')
364
+ @person.parents[0].parents[0].id.should == 'KWQS-BBR'
365
+ @person.parents[0].parents[1].id.should == 'KWQS-BBQ'
366
+ @person.parents[0].parents[0].gender.should == 'Female'
367
+ @person.parents[0].parents[1].gender.should == 'Male'
368
+ @person.parents[0].action.should == 'Select'
369
+ end
370
+
371
+ end
372
+
373
+ end
374
+
277
375
  describe "baptisms" do
278
376
  describe "for persons with at least one baptism" do
279
377
  before(:each) do
@@ -19,8 +19,10 @@ describe FsUtils do
19
19
  end
20
20
 
21
21
  it "should url_encode all of the hash values" do
22
- qstring = FsUtils.querystring_from_hash :name => "Parker Felch"
22
+ hash = {:name => "Parker Felch"}
23
+ qstring = FsUtils.querystring_from_hash hash
23
24
  qstring.should == 'name=Parker%20Felch'
25
+ hash[:name].should_not == 'Parker%20Felch'
24
26
  end
25
27
 
26
28
  it "should convert sub-hashes into key.subkey=value" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fs-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Zimmerman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-18 00:00:00 -07:00
12
+ date: 2010-01-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency