### Initialize GENI JS Client SDK Source: https://github.com/geni/geni-js-sdk/blob/master/samples/last_name_directory.html Initializes the GENI JS Client SDK with provided application ID, cookie settings, and logging preferences. This is a prerequisite for using other SDK functionalities. ```javascript Geni.init({ app_id: 'GTFF5ZmAkEDMykFAd6EtazPzWZpJA0rm0eCZerNj', cookie: false, logging: false }); ``` -------------------------------- ### Connect to GENI and Load Family Directory Source: https://github.com/geni/geni-js-sdk/blob/master/samples/last_name_directory.html Handles the connection to GENI, checks authorization status, and triggers the loading of family names if authorized. It also manages UI element visibility based on the connection status. ```javascript function connectWithGeni() { Geni.connect(function(response) { if(response.status == 'authorized') { $("login_link").style.display = "none"; $("loading").style.display = ""; loadFamilyNames(); } else { $("login_link").style.display = ""; } }); } ``` -------------------------------- ### Load Family Names from GENI API Source: https://github.com/geni/geni-js-sdk/blob/master/samples/last_name_directory.html Recursively loads family name data from the GENI API. It processes profiles to count last names and makes subsequent calls if more pages are available, eventually triggering directory generation. ```javascript function loadFamilyNames(url) { if (!url) { url = '/user/max-family'; } url = url.replace("https://www.geni.com/api", ""); Geni.api(url, function (response) { for (var i=0; i" + name + "" + " (" + name_counts[name] + ")"); } var summary = "
Your family has " + total_count + " members.
"; $("name_directory").innerHTML = summary + html.join(" "); $("loading").style.display = "none"; } ``` -------------------------------- ### Helper Function: Get Element by ID Source: https://github.com/geni/geni-js-sdk/blob/master/samples/first_name_cloud.html A simple JavaScript helper function to retrieve an HTML element by its ID. This is commonly used for DOM manipulation in web applications. ```javascript function $(id) { return document.getElementById(id); } ``` -------------------------------- ### Get Specific Profile Fields via Geni.api() Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Illustrates how to request specific fields of the current user's profile. The second argument to `Geni.api()` is an object containing parameters like 'fields', followed by a callback function to handle the partial data. ```javascript Geni.api('/profile', { fields : 'first_name'}, function(data) { // only returns first name of profile current users profile alert("Welcome + " " + response.first_name); }); ``` -------------------------------- ### Get Current User's Profile Data via Geni.api() Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Shows how to retrieve the current user's profile data by omitting IDs in the API path. The `Geni.api()` method with '/profile' returns the user's information, processed by the provided callback function. ```javascript Geni.api('/profile', function(response) { // returns current user's profile data // alert(response.name) }); ``` -------------------------------- ### Initialize Geni SDK Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Initializes the Geni JavaScript SDK with your application key. Optional parameters include host, cookie settings for access token storage, and logging for debugging. Place this script at the bottom of your page before the closing tag. ```javascript ``` ```javascript ``` -------------------------------- ### Connect to Geni and Load Name Cloud Source: https://github.com/geni/geni-js-sdk/blob/master/samples/first_name_cloud.html Establishes a connection with the Geni platform and handles the response. If authorized, it hides the login link, shows a loading indicator, and initiates loading the name cloud. Otherwise, it displays the login link. ```javascript function connectWithGeni() { Geni.connect(function(response) { if(response.status == 'authorized') { $("login_link").style.display = "none"; $("loading").style.display = ""; loadNameCloud(); } else { $("login_link").style.display = ""; } }); } ``` -------------------------------- ### Initialize Geni JS Client SDK Source: https://github.com/geni/geni-js-sdk/blob/master/samples/first_name_cloud.html Initializes the Geni JS SDK with provided application credentials. It can be configured to manage cookies and logging behavior. Ensure you replace 'PROVIDE YOUR APP KEY HERE' with your actual application ID. ```javascript Geni.init({ app_id: 'PROVIDE YOUR APP KEY HERE', cookie: false, logging: false }); ``` -------------------------------- ### Prompt Geni User Login and Authorization Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Prompts the user to log in to Geni and authorize your application by opening a popup window. It uses a callback function to handle the response, indicating if the user authorized the application or canceled the popup. This method should be called in response to a user action. ```javascript Geni.connect(function(response) { if(response.status == 'authorized') { // User is logged in and has authorized your application. // You can now make authorized calls to the API. } else { // User canceled the popup } }); ``` -------------------------------- ### Update User Profile via POST Request with Geni.api() Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Explains how to perform a POST request to update user profile information using `Geni.api()`. The second argument object must include 'method: 'post'', along with the data to be updated and a callback for the response. ```javascript Geni.api('/profile', { method:'post', first_name: 'John' }, function(response) { // the current users first name is now set to 'John' }); ``` -------------------------------- ### Load Family First Names from Geni API Source: https://github.com/geni/geni-js-sdk/blob/master/samples/first_name_cloud.html Fetches family first names from the Geni API, optionally using a provided URL. It recursively calls itself for subsequent pages if available and then triggers the generation of the name cloud once all data is loaded. ```javascript function loadNameCloud(url) { if (!url) { url = '/user/max-family'; } url = url.replace("https://www.geni.com/api", ""); Geni.api(url, function (response) { for (var i=0; i" + name + ""); } var summary = "
Your family has " + total_count + " members. The following name cloud shows your family first name distribution.
"; $("name_cloud").innerHTML = summary + html.join(" "); $("loading").style.display = "none"; } ``` -------------------------------- ### Subscribe to Geni Authentication Status Changes Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Subscribes to the 'auth:statusChange' event, which fires whenever the user's authentication status changes as a result of SDK methods like Geni.getStatus() or Geni.connect(). The callback function receives the new status ('authorized', 'unauthorized', or 'unknown'). ```javascript Geni.Event.bind('auth:statusChange',function(status) { // status will be either 'authorized', 'unauthorized' or 'unknown' }); ``` -------------------------------- ### Check Geni Authentication Status Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Checks the current authentication status of the user with Geni. It uses a callback function to process the response, which can be 'authorized', 'unauthorized', or 'unknown'. This is useful for determining if API calls can be made. ```javascript Geni.getStatus(function(response) { if (response.status == 'authorized') { // User is logged in and has authorized your application. // You can now make authorized calls to the API. } else { // User is either logged out, has not authorized the app or both. } }); ``` -------------------------------- ### Log Out User from Geni Source: https://github.com/geni/geni-js-sdk/blob/master/README.markdown Logs the current user out of Geni. After this method is called, your application will no longer be able to make API calls on behalf of the user until they log back in. It takes a callback function that executes once the logout is complete. ```javascript Geni.logout(function() { // The user is now logged out of Geni // Your application will no longer be able to make api calls on the users behalf until they log back in }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.