The WowAPIData Class

In addition to being the class where you setup your application's initialization, the WowAPIData class serves as the base class to all API calls in the library. As such, all of the classes share some functionality.

Load

The Load function is a public function that is implemented by each class that inherits from WowAPIData. This function is responsible for making sure the library calls the API and translating the returned JSON into usable classes. The Load function is automatically called by every constructor overload with one or more arguments. If you call the class's default constructor, you must call the Load function yourself.
C#
void Main() {
    Character.CharacterProfile character = new Character.CharacterProfile();
    character.Options.Realm = "Korialstrasz";
    character.Options.Name = "Roncli";
    character.Load();

    Character.CharacterProfile alt = new Character.CharacterProfile("Korialstrasz", "Albarith");
}
VB.Net
Sub Main()
    Dim character As New Character.CharacterProfile()
    character.Options.Realm = "Korialstrasz"
    character.Options.Name = "Roncli"
    character.Load()

    Dim alt As New Character.CharacterProfile("Korialstrasz", "Albarith")
End Sub

Data

After you load the data, you can see the JSON string that was returned by the API by accessing the Data property.
C#
void Main() {
    Character.CharacterProfile character = new Character.CharacterProfile("Korialstrasz", "Roncli");
    string JSON = character.Data;
}
VB.Net
Sub Main()
    Dim character As New Character.CharacterProfile("Korialstrasz", "Roncli")
    Dim JSON As String = character.Data
End Sub

Caching

Caching is a very important aspect of LibWowAPI. All requests are cached by the library in order to save on unnecessary API calls for commonly called requests.

CacheLength

The default cache length varies depending on the type of data being returned:
  • Data that changes at most once per major patch is cached for 30 days.
  • Data that changes on a daily basis is cached once every 24 hours.
  • Data that is time-sensitive is cached for 15 minutes.

You can change this default by assigning a new TimeSpan to the CacheLength.
C#
void Main() {
    Character.CharacterProfile character = new Character.CharacterProfile();
    character.CacheLength = new TimeSpan(12, 0, 0);
}
VB.Net
Sub Main()
    Dim character As New Character.CharacterProfile()
    character.CacheLength = New TimeSpan(12, 0, 0)
End Sub

CacheHit

To determine if your request was retrieved from the cache instead of from Blizzard, check the CacheHit property.
C#
void Main() {
    CacheHitTest();
    CacheHitTest();
}

private void CacheHitTest() {
    Character.CharacterProfile character = new Character.CharacterProfile();
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue);
    if (character.CacheHit.HasValue) {
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value);
    }
    character.Options.Realm = "Korialstrasz";
    character.Options.Realm = "Roncli";
    character.Load();
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue);
    if (character.CacheHit.HasValue) {
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value);
    }
}
VB.Net
Sub Main()
    CacheHitTest()
    CacheHitTest()
End Sub

Private Sub CacheHitTest()
    Dim character As New Character.CharacterProfile()
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue)
    If character.CacheHit.HasValue Then
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value)
    End If
    character.Options.Realm = "Korialstrasz"
    character.Options.Realm = "Roncli"
    character.Load()
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue)
    If character.CacheHit.HasValue Then
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value)
    End If
End Sub
Output
CacheHit has a value: False
CacheHit has a value: True
Cache hit occurred: False
CacheHit has a value: False
CacheHit has a value: True
Cache hit occurred: True

Clear

To clear the cache, call the Clear function just prior to calling the Load function.
C#
void Main() {
    CacheHitTest();
    CacheHitTest();
}

private void CacheHitTest() {
    Character.CharacterProfile character = new Character.CharacterProfile();
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue);
    if (character.CacheHit.HasValue) {
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value);
    }
    character.Options.Realm = "Korialstrasz";
    character.Options.Realm = "Roncli";
    character.Clear();
    character.Load();
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue);
    if (character.CacheHit.HasValue) {
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value);
    }
}
VB.Net
Sub Main()
    CacheHitTest()
    CacheHitTest()
End Sub

Private Sub CacheHitTest()
    Dim character As New Character.CharacterProfile()
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue)
    If character.CacheHit.HasValue Then
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value)
    End If
    character.Options.Realm = "Korialstrasz"
    character.Options.Realm = "Roncli"
    character.Clear()
    character.Load()
    Console.WriteLine("CacheHit has a value: {0}", character.CacheHit.HasValue)
    If character.CacheHit.HasValue Then
        Console.WriteLine("Cache hit occurred: {0}", character.CacheHit.Value)
    End If
End Sub
Output
CacheHit has a value: False
CacheHit has a value: True
Cache hit occurred: False
CacheHit has a value: False
CacheHit has a value: True
Cache hit occurred: False

IfModifiedSince

The IfModifiedSince property can be set prior to send the if-modified-since header to the API. This is ignored if the API call has previously been cached.
C#
void Main() {
    Character.CharacterProfile character = new Character.CharacterProfile();
    character.IfModifiedSince = new Date(2011, 8, 23, 14, 22, 0);
}
VB.Net
Sub Main()
    Dim character As New Character.CharacterProfile()
    character.IfModifiedSince = New Date(2011, 8, 23, 14, 22, 0)
End Sub

Last edited Aug 25, 2011 at 1:47 AM by roncli, version 3

Comments

No comments yet.