ForrstClient

The ForrstClient class is built to access all data in the easiest way possible. All the examples below use the more simplistic lambda syntax for the events.
  • Private
    • User Auth
    • User Info
    • User Posts
    • Post Show
    • Posts All
    • Posts List
    • Post Comments
    • Notifications
    • Post Comments
    • Stats
  • Public (Coming Soon)
  • Classes
    • Forrst Auth

Public

Using the public API allows one to find data a user has marked as public.

User Authentication

Authenticate a user and receive the User Id and oAuth Token.

// Create instance of the ForrstClient passing username and password
ForrstClient forrst = new ForrstClient(Username.Text, Password.Password);
// Add an event to be called when authentication is returned.
forrst.GetUserAuthCompleted += (ForrstAuth auth) =>
 {
    if (auth.Authenticated)
    {
        MessageBox.Show("Load User: " + auth.User.Id);
    }
    else
    {
        MessageBox.Show("Error: " + auth.Error);
    }
};
// Initiate the authentication check.
forrst.GetUserAuthAsync();

User Info

By simply providing a username or username id one can find if a user exists and their username or username id.

private void Info_Click(object sender, RoutedEventArgs e)
{
    ForrstClient forrst = new ForrstClient();
    // Method
    forrst.GetUserInfoCompleted += UserInfo_GetUserInfoCompleted;
    // Or Lambda
    // forrst.GetUserInfoCompleted += (user) => { MessageBox.Show(user.Id + " " + user.Username); };
    forrst.GetUserInfoAsync("kyle");
}

private void UserInfo_GetUserInfoCompleted(ForrstUser user)
{
    if(user.Exists)
    {
        MessageBox.Show(user.Id + " " + user.Username); // "1 kyle"
    }
    else
    {
        MessageBox.Show(user.ErrorMessage); // invalid user
    }
}

Posts (Work in Progress)

By giving a username one can get an array of 10 posts for the user. Optionally they can offset by a post id.

private void Posts_Click(object sender, RoutedEventArgs e)
{
    ForrstClient forrst = new ForrstClient();
    // Method
    forrst.GetUserPostsCompleted += UserPosts_GetUserPostsCompleted;
    // Or Lambda
    // forrst.GetUserPostsCompleted += (posts) => {
    //     foreach (int i in posts)
    //     {
    //         MessageBox.Show(posts[i].Id + " " + posts[i].Username); // ""
    //     }
    // };
    forrst.GetUserPostsAsync("kyle");
    // or using a username id
    // forrst.GetUserPostsAsync(1);
}

private void UserPosts_GetUserPostsCompleted(ForrstPost[] posts)
{
    foreach (int i in posts)
    {
        MessageBox.Show(posts[i].Id + " " + posts[i].Username); // ""
    }
}

Private (not in API yet)

To access this part of the API an OAuth authentication is required.

Notifications

This will implement a search for changes where an event is called for notifications.

// Code

Classes

Below are the public classes.

ForrstAuth

public class ForrstAuth
{
    public ForrstUser User { get; set; }
    public string Token { get; set; }
    public string Error { get; set; }
    public bool Authenticated { get; set; }
}

Last edited Sep 18, 2011 at 12:12 AM by Templarian, version 15

Comments

No comments yet.