lib/ruby-fs-stack/familytree.rb in ruby-fs-stack-0.4.0 vs lib/ruby-fs-stack/familytree.rb in ruby-fs-stack-0.4.2
- old
+ new
@@ -190,20 +190,46 @@
def relationship(base_id,options)
begin
r_type = get_relationship_type(options)
with_id = options[r_type.to_sym]
url = "#{Base}person/#{base_id}/#{r_type}/#{with_id}"
+ options.reject!{|k,v| k.to_s == 'spouse'}
url += add_querystring(options)
res = @fs_communicator.get(url)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(res.body)
- person = familytree.persons.find{|p|p.id == base_id}
+ person = familytree.persons.find{|p|p.requestedId == base_id}
return person
rescue RubyFsStack::NotFound
return nil
end
end
+ # Writes a note attached to the value ID of the specific person or relationship.
+ #
+ # ====Params
+ # * <tt>options</tt> - Options for the note including the following:
+ # * <tt>:personId</tt> - the person ID if attaching to a person assertion.
+ # * <tt>:spouseIds</tt> - an Array of spouse IDs if creating a note attached to a spouse
+ # relationship assertion.
+ # * <tt>:parentIds</tt> - an Array of parent IDs if creating a note attached to a parent
+ # relationship assertion. If creating a note for a child-parent or parent-child
+ # relationship, you will need only one parent ID in the array along with a :childId option.
+ # * <tt>:childId</tt> - a child ID.
+ # * <tt>:text</tt> - the text of the note (required).
+ # * <tt>:assertionId</tt> - the valueId of the assertion you are attaching this note to.
+ #
+ def write_note(options)
+ url = "#{Base}note"
+ note = Org::Familysearch::Ws::Familytree::V2::Schema::Note.new
+ note.build(options)
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
+ familytree.notes = [note]
+ res = @fs_communicator.post(url,familytree.to_json)
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(res.body)
+ return familytree.notes.first
+ end
+
# Combines person into a new person
#
# ====Params
# * <tt>person_array</tt> - an array of person IDs.
def combine(person_array)
@@ -225,11 +251,11 @@
key = keys.find{|k| ['parent','child','spouse'].include? k}
key
end
def add_querystring(options)
- params = options.reject{|k,v| ['parent','child','spouse','lineage','event'].include? k.to_s }
+ params = options.reject{|k,v| ['parent','child','lineage','event'].include? k.to_s }
(params.empty?) ? '' : "?" + FsUtils.querystring_from_hash(params)
end
end
end
@@ -771,10 +797,15 @@
death = deaths.find{|b|!b.selected.nil?}
death ||= deaths[0]
death
end
+ # This should only be called on a person containing relationships
+ def marriages(for_person)
+ select_spouse_events('Marriage',for_person)
+ end
+
# Add an event with type of Birth
#
# ====Params
# * <tt>options</tt> - accepts a :date and :place option
#
@@ -853,11 +884,11 @@
# This is the recommended approach, to start with a "Version" person (no names, genders, or events)
def select_mother_summary(person_id)
add_parents!
couple = parents[0] || ParentsReference.new
couple.select_parent(person_id,'Female')
- parents << couple
+ parents[0] = couple
end
# Select the father for the summary view. This should be called on a Person record that
# contains a person id and version.
#
@@ -876,11 +907,11 @@
# This is the recommended approach, to start with a "Version" person (no names, genders, or events)
def select_father_summary(person_id)
add_parents!
couple = parents[0] || ParentsReference.new
couple.select_parent(person_id,'Male')
- parents << couple
+ parents[0] = couple
end
# Select the spouse for the summary view. This should be called on a Person record that
# contains a person id and version.
#
@@ -1051,10 +1082,19 @@
else
[]
end
end
+ def select_spouse_events(type,for_person)
+ spouse = relationships.spouses.find{|s|s.requestedId=for_person}
+ if spouse.assertions && spouse.assertions.events
+ spouse.assertions.events.select{|e| e.value.type == type}
+ else
+ []
+ end
+ end
+
def select_ordinances(type)
if assertions && assertions.ordinances
assertions.ordinances.select{|e| e.value.type == type}
else
[]
@@ -1096,8 +1136,55 @@
parents.find{|p|p.gender == 'Male'}
end
def mother
parents.find{|p|p.gender == 'Female'}
+ end
+ end
+
+ class Note
+
+ #Builds out the elements needed for the note.
+ # ====Params
+ # * <tt>options</tt> - Options for the note including the following:
+ # * <tt>:personId</tt> - the person ID if attaching to a person assertion.
+ # * <tt>:spouseIds</tt> - an Array of spouse IDs if creating a note attached to a spouse
+ # relationship assertion.
+ # * <tt>:parentIds</tt> - an Array of parent IDs if creating a note attached to a parent
+ # relationship assertion. If creating a note for a child-parent or parent-child
+ # relationship, you will need only one parent ID in the array along with a :childId option.
+ # * <tt>:childId</tt> - a child ID.
+ # * <tt>:text</tt> - the text of the note (required).
+ # * <tt>:assertionId</tt> - the valueId of the assertion you are attaching this note to.
+ def build(options)
+ if spouseIds = options[:spouseIds]
+ self.spouses = spouseIds.collect do |id|
+ s = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
+ s.id = id
+ s
+ end
+ end
+ if parentIds = options[:parentIds]
+ self.parents = parentIds.collect do |id|
+ p = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
+ p.id = id
+ p
+ end
+ end
+ if personId = options[:personId]
+ self.person = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
+ self.person.id = personId
+ end
+ if childId = options[:childId]
+ self.child = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
+ self.child.id = childId
+ end
+ if assertionId = options[:assertionId]
+ self.assertion = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
+ self.assertion.id = assertionId
+ end
+ if text = options[:text]
+ self.text = text
+ end
end
end
end
\ No newline at end of file