/// <summary> /// Reads the preferred relationship for the specified person. /// </summary> /// <param name="rel">The rel name of the link to use to perform this operation.</param> /// <param name="treeUserId">The <see cref="P:User.TreeUserId" /> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified /// is someone other than the current tree user (due to a lack of permissions).</param> /// <param name="personId">The person ID for which the preferred relationship will be read.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response. /// </returns> /// <remarks> /// Tree users can have varying relationship preferences; therefore, this method will only read what the specified user prefers to /// see for the specified relationship. /// </remarks> protected IPreferredRelationshipState ReadPreferredRelationship(String rel, String treeUserId, String personId, IStateTransitionOption[] options) { Link link = GetLink(rel); if (link == null || link.Template == null) { return(null); } String template = link.Template; String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("uid", treeUserId).Resolve(); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET); IRestResponse response = Invoke(request, options); if (response.StatusCode == HttpStatusCode.NoContent) { return(null); } FamilySearchPlatform fsp = response.ToIRestResponse <FamilySearchPlatform>().Data; if (fsp != null && fsp.ChildAndParentsRelationships != null && fsp.ChildAndParentsRelationships.Count > 0) { return(((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, response, this.Client, this.CurrentAccessToken)); } else { return((IPreferredRelationshipState)((FamilyTreeStateFactory)this.stateFactory).NewRelationshipStateInt(request, response, this.Client, this.CurrentAccessToken)); } }
/// <summary> /// Prepares a merge state for the specified person and the current person. /// </summary> /// <param name="method">The HTTP method to use for the operation.</param> /// <param name="candidate">The person which will be merged with the current person.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="PersonMergeState"/> instance containing the REST API response. /// </returns> /// <exception cref="System.ArgumentException"> /// The current <see cref="P:FamilyTreePersonState.Person"/> or <see cref="P:Person.Id"/> was null. /// or /// The specified candidate.Person or candidate.Person.Id was null. /// </exception> protected PersonMergeState TransitionToPersonMerge(Method method, FamilyTreePersonState candidate, params IStateTransitionOption[] options) { Link link = GetLink(Rel.MERGE); if (link == null || link.Template == null) { return(null); } Person person = Person; if (person == null || person.Id == null) { throw new ArgumentException("Cannot read merge options: no person id available."); } String personId = person.Id; person = candidate.Person; if (person == null || person.Id == null) { throw new ArgumentException("Cannot read merge options: no person id provided on the candidate."); } String candidateId = person.Id; String template = link.Template; String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("dpid", candidateId).Resolve(); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, method); return(((FamilyTreeStateFactory)this.stateFactory).NewPersonMergeState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
//TODO: Create FamilysearchSourceReferencesQueryState class, add it to FamilySearchStateFactory when link is created /* * public FamilySearchSourceReferencesQueryState ReadSourceReferencesQuery() * { * Link link = GetLink( //TODO: Put Rel here when added ); * if (link == null || link.Href = null) * { * return null; * } * * IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); * return ((FamilySearchStateFactory)this.stateFactory).NewFamilySearchSourceReferencesQueryState(request, Invoke(request), this.Client, this.CurrentAccessToken); * } */ /// <summary> /// Moves the current source description to the specified collection. /// </summary> /// <param name="collection">The target collection to contain this source description.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilySearchSourceDescriptionState"/> instance containing the REST API response. /// </returns> public FamilySearchSourceDescriptionState MoveToCollection(CollectionState collection, params IStateTransitionOption[] options) { Link link = collection.GetLink(Rel.SOURCE_DESCRIPTIONS); if (link == null || link.Href == null) { return(null); } SourceDescription me = SourceDescription; if (me == null || me.Id == null) { return(null); } Gx.Gedcomx gx = new Gx.Gedcomx(); gx.AddSourceDescription(new SourceDescription() { Id = me.Id }); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(gx).Build(link.Href, Method.POST); return((FamilySearchSourceDescriptionState)((FamilySearchStateFactory)this.stateFactory).NewSourceDescriptionStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Updates the specified discussion. /// </summary> /// <param name="discussion">The discussion to update.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="DiscussionState"/> instance containing the REST API response. /// </returns> public DiscussionState Update(Discussion discussion, params IStateTransitionOption[] options) { FamilySearchPlatform fsp = new FamilySearchPlatform(); fsp.AddDiscussion(discussion); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(fsp).Build(GetSelfUri(), Method.POST); return(((FamilySearchStateFactory)this.stateFactory).NewDiscussionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Creates a REST API request (with appropriate authentication headers). /// </summary> /// <param name="rel">If the value is equal to the discussion references link, the resulting request is built with accept and content-type headers of "application/x-fs-v1+json"; otherwise, "application/x-gedcomx-v1+json" is used.</param> /// <returns> /// A REST API requeset (with appropriate authentication headers). /// </returns> protected override IRestRequest CreateRequestForEmbeddedResource(String rel) { if (Rel.DISCUSSION_REFERENCES.Equals(rel)) { return(RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest())); } else { return(base.CreateRequestForEmbeddedResource(rel)); } }
/// <summary> /// Adds a child and parents relationship to the current relationships collection. /// </summary> /// <param name="chap">The relationship to add to the current relationships collection, with the father, mother, and child set as desired.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="ChildAndParentsRelationshipState"/> instance containing the REST API response. /// </returns> public ChildAndParentsRelationshipState AddChildAndParentsRelationship(ChildAndParentsRelationship chap, params IStateTransitionOption[] options) { FamilySearchPlatform entity = new FamilySearchPlatform(); entity.ChildAndParentsRelationships = new List <ChildAndParentsRelationship>() { chap }; IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(GetSelfUri(), Method.POST); return(((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Reads the discussions on the current collection. /// </summary> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="DiscussionsState"/> instance containing the REST API response. /// </returns> public DiscussionsState ReadDiscussions(params IStateTransitionOption[] options) { Link link = GetLink(Rel.DISCUSSIONS); if (link == null || link.Href == null) { return(null); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); return(((FamilySearchStateFactory)this.stateFactory).NewDiscussionsState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Restore the current person (if it is currently deleted). /// </summary> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilyTreePersonState"/> instance containing the REST API response. /// </returns> public FamilyTreePersonState Restore(params IStateTransitionOption[] options) { Link link = GetLink(Rel.RESTORE); if (link == null || link.Href == null) { return(null); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.POST); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Reads the merge mirror for the current merge. /// </summary> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="PersonMergeState"/> instance containing the REST API response. /// </returns> public PersonMergeState ReadMergeMirror(params IStateTransitionOption[] options) { Link link = GetLink(Rel.MERGE_MIRROR); if (link == null || link.Href == null) { return(null); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); return(((FamilySearchStateFactory)this.stateFactory).NewPersonMergeState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Restores the specified change (if it had been reverted). /// </summary> /// <param name="change">The change to restore.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="ChangeHistoryState"/> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if a link to the required resource cannot be found.</exception> public ChangeHistoryState RestoreChange(Entry change, params IStateTransitionOption[] options) { Link link = change.GetLink(Rel.RESTORE); if (link == null || link.Href == null) { throw new GedcomxApplicationException("Unrestorable change: " + change.Id); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.POST); return(((FamilyTreeStateFactory)this.stateFactory).NewChangeHistoryState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Reads all declared non matches of the current person. /// </summary> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="PersonNonMatchesState"/> instance containing the REST API response. /// </returns> public PersonNonMatchesState ReadNonMatches(params IStateTransitionOption[] options) { Link link = GetLink(Rel.NOT_A_MATCHES); if (link == null || link.Href == null) { return(null); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); return(((FamilyTreeStateFactory)this.stateFactory).NewPersonNonMatchesState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Read the place group by the ID specified. /// </summary> /// <param name="id">The place group ID to read.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="PlaceGroupState"/> instance containing the REST API response. /// </returns> public PlaceGroupState ReadPlaceGroupById(String id, params IStateTransitionOption[] options) { Link link = GetLink(Rel.PLACE_GROUP); if (link == null || link.Template == null) { return(null); } String template = link.Template; String uri = new UriTemplate(template).AddParameter("pgid", id).Resolve(); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET); return(this.stateFactory.NewPlaceGroupState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Deletes the specified discussion reference from the current person. /// </summary> /// <param name="reference">The discussion reference to delete.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilyTreePersonState"/> instance containing the REST API response. /// </returns> /// <exception cref="GedcomxApplicationException">Discussion reference cannot be deleted: missing link.</exception> public FamilyTreePersonState DeleteDiscussionReference(DiscussionReference reference, params IStateTransitionOption[] options) { Link link = reference.GetLink(Rel.DISCUSSION_REFERENCE); link = link == null?reference.GetLink(Rel.SELF) : link; if (link == null || link.Href == null) { throw new GedcomxApplicationException("Discussion reference cannot be deleted: missing link."); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedGedcomxRequest()).Build(link.Href, Method.DELETE); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Reads the child and parents relationship of the current person. /// </summary> /// <param name="relationship">The relationship to be read.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="ChildAndParentsRelationshipState"/> instance containing the REST API response. /// </returns> public ChildAndParentsRelationshipState ReadChildAndParentsRelationship(ChildAndParentsRelationship relationship, params IStateTransitionOption[] options) { Link link = relationship.GetLink(Rel.RELATIONSHIP); link = link == null?relationship.GetLink(Rel.SELF) : link; if (link == null || link.Href == null) { return(null); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); return(((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Deletes the specified comment from the current discussion. /// </summary> /// <param name="comment">The comment to delete.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="DiscussionState"/> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Comment cannot be deleted: missing link.</exception> public DiscussionState DeleteComment(Comment comment, params IStateTransitionOption[] options) { Link link = comment.GetLink(Rel.COMMENT); link = link == null?comment.GetLink(Rel.SELF) : link; if (link == null || link.Href == null) { throw new GedcomxApplicationException("Comment cannot be deleted: missing link."); } IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.DELETE); return(((FamilySearchStateFactory)this.stateFactory).NewDiscussionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Declares a possible duplicate of the current person as not a duplicate. /// </summary> /// <param name="person">The person that was possibly a duplicate of the current person.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="PersonNonMatchesState"/> instance containing the REST API response. /// </returns> public PersonNonMatchesState AddNonMatch(Person person, params IStateTransitionOption[] options) { Link link = GetLink(Rel.NOT_A_MATCHES); if (link == null || link.Href == null) { return(null); } Gx.Gedcomx entity = new Gx.Gedcomx(); entity.AddPerson(person); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(entity).Build(link.Href, Method.POST); return(((FamilyTreeStateFactory)this.stateFactory).NewPersonNonMatchesState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Deletes the preferred relationship for the specified person. /// </summary> /// <param name="treeUserId">The <see cref="P:User.TreeUserId" /> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified /// is someone other than the current tree user (due to a lack of permissions).</param> /// <param name="personId">The person ID for which the preferred relationship will be read.</param> /// <param name="rel">The rel name of the link to use to perform this operation.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response. /// </returns> /// <remarks> /// Tree users can have varying relationship preferences; therefore, this method will only delete what the specified user prefers to /// see for the specified relationship. /// </remarks> protected FamilyTreePersonState DeletePreferredRelationship(String treeUserId, String personId, String rel, IStateTransitionOption[] options) { Link link = GetLink(rel); if (link == null || link.Template == null) { return(null); } String template = link.Template; String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("uid", treeUserId).Resolve(); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.DELETE); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Reads the person by the specified ID and includes relationship details in the response. /// </summary> /// <param name="id">The ID of the person to read.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilyTreePersonState"/> instance containing the REST API response. /// </returns> public FamilyTreePersonState ReadPersonWithRelationshipsById(String id, params IStateTransitionOption[] options) { Link link = GetLink(Rel.PERSON_WITH_RELATIONSHIPS); if (link == null || link.Template == null) { return(null); } String template = link.Template; String uri = new UriTemplate(template).AddParameter("person", id).Resolve(); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Adds a discussion to the current collection. /// </summary> /// <param name="discussion">The discussion.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="DiscussionState"/> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if a link to the required resource cannot be found.</exception> public DiscussionState AddDiscussion(Discussion discussion, params IStateTransitionOption[] options) { Link link = GetLink(Rel.DISCUSSIONS); if (link == null || link.Href == null) { throw new GedcomxApplicationException("Unable to add discussion: missing link."); } FamilySearchPlatform entity = new FamilySearchPlatform(); entity.AddDiscussion(discussion); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(entity).Build(link.Href, Method.POST); return(((FamilySearchStateFactory)this.stateFactory).NewDiscussionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Adds the child and parents relationships to the collection. /// </summary> /// <param name="chaps">The child and parent relationships to add.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="RelationshipsState"/> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if a link to the required resource cannot be found.</exception> public RelationshipsState AddChildAndParentsRelationships(List <ChildAndParentsRelationship> chaps, params IStateTransitionOption[] options) { Link link = GetLink(Rel.RELATIONSHIPS); if (link == null || link.Href == null) { throw new GedcomxApplicationException(String.Format("FamilySearch Family Tree at {0} didn't provide a 'relationships' link.", GetUri())); } FamilySearchPlatform entity = new FamilySearchPlatform(); entity.ChildAndParentsRelationships = chaps; IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.POST); request.SetEntity(entity); return(((FamilyTreeStateFactory)this.stateFactory).NewRelationshipsStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Updates the discussion reference on the specified person. /// </summary> /// <param name="person">The person with a discussion reference to update.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilyTreePersonState"/> instance containing the REST API response. /// </returns> public FamilyTreePersonState UpdateDiscussionReference(Person person, params IStateTransitionOption[] options) { String target = GetSelfUri(); Link discussionsLink = GetLink(Rel.DISCUSSION_REFERENCES); if (discussionsLink != null && discussionsLink.Href != null) { target = discussionsLink.Href; } Gx.Gedcomx gx = new Gx.Gedcomx(); gx.Persons = new List <Person>() { person }; IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedGedcomxRequest()).SetEntity(gx).Build(target, Method.POST); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Updates the comments on the specified discussion. /// </summary> /// <param name="discussion">The discussion with comments to update.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="DiscussionState"/> instance containing the REST API response. /// </returns> protected DiscussionState UpdateComments(Discussion discussion, params IStateTransitionOption[] options) { String target = GetSelfUri(); Link link = GetLink(Rel.COMMENTS); if (link != null && link.Href != null) { target = link.Href; } FamilySearchPlatform gx = new FamilySearchPlatform(); gx.Discussions = new List <Discussion>() { discussion }; IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(gx).Build(target, Method.POST); return(((FamilySearchStateFactory)this.stateFactory).NewDiscussionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Updates the discussion reference on the specified person. /// </summary> /// <param name="person">The person with a discussion reference to update.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilyTreePersonState"/> instance containing the REST API response. /// </returns> public FamilyTreePersonState UpdateDiscussionReference(Person person, params IStateTransitionOption[] options) { String target = GetSelfUri(); // https://familysearch.org/developers/docs/api/tree/Read_Discussion_References_(Starting_December_2016)_usecase //Link discussionsLink = GetLink(Rel.DISCUSSION_REFERENCES); //if (discussionsLink != null && discussionsLink.Href != null) //{ // target = discussionsLink.Href; //} Gx.Gedcomx gx = new Gx.Gedcomx(); gx.Persons = new List <Person>() { person }; IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedGedcomxRequest()).SetEntity(gx).Build(target, Method.POST); return((FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
/// <summary> /// Creates a REST API request (with appropriate authentication headers). /// </summary> /// <param name="rel">This parameter is currently unused.</param> /// <returns> /// A REST API requeset (with appropriate authentication headers). /// </returns> protected override IRestRequest CreateRequestForEmbeddedResource(String rel) { return(RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest())); }