Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
- Added new AchievementLookup class.
Browse files Browse the repository at this point in the history
- Refactored the classes in the Data.CharacterAchievements and Data.GuildAchievements namespaces to use the schema in the Achievements namespace instead.  Now the AchievementLookup, CharacterAchievements, and GuildAchievements class all use the same schema and LibWowAPI objects to represent individual achievements.
- Improved exception handling.
- Added Achievement Lookup to the demo project.
  • Loading branch information
roncli committed Apr 8, 2014
1 parent e2cadea commit fabf2fd
Show file tree
Hide file tree
Showing 29 changed files with 449 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class achievement

Expand All @@ -18,6 +18,7 @@ Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements.Schema
<DataMember()> Public Property icon As String
<DataMember()> Public Property criteria As criteria()
<DataMember()> Public Property accountWide As Boolean
<DataMember()> Public Property factionId As Integer

End Class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.GuildAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class achievements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.GuildAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class category

<DataMember()> Public Property id As Integer
<DataMember()> Public Property categories As category()
<DataMember()> Public Property name As String
<DataMember()> Public Property achievements As achievement()
<DataMember()> Public Property achievements As Achievement()

End Class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.GuildAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class criteria

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
'
' This source code is released under the GNU Lesser General Public License (LGPL) Version 3.0.

Imports System.Collections.Generic
Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class rewardItem

<DataMember()> Public Property id As Integer
<DataMember()> Public Property name As String
<DataMember()> Public Property icon As String
<DataMember()> Public Property quality As Integer
<DataMember()> Public Property itemLevel As Integer
<DataMember()> Public Property tooltipParams As tooltipParams
<DataMember()> Public Property stats As List(Of stat)
<DataMember()> Public Property armor As Integer

End Class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class tooltipParams
<DataContract()> Friend Class stat
' This class is intentionally left blank.
End Class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Imports System.Runtime.Serialization

Namespace roncliProductions.LibWowAPI.Data.GuildAchievements.Schema
Namespace roncliProductions.LibWowAPI.Achievements.Schema

<DataContract()> Friend Class tooltipParams
' This class is intentionally left blank.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
' This source code is released under the GNU Lesser General Public License (LGPL) Version 3.0.

Imports System.Collections.ObjectModel
Imports roncliProductions.LibWowAPI.Enums

Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements
Namespace roncliProductions.LibWowAPI.Achievements

''' <summary>
''' A class containing information about an achievement.
Expand Down Expand Up @@ -34,7 +35,7 @@ Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements
''' </summary>
''' <value>This property gets or sets the Points field.</value>
''' <returns>Returns the number of achievement points obtained for successfully completing the achievement.</returns>
''' <remarks>Each successfully completed achievement earns a set number of achievement points for the character.</remarks>
''' <remarks>Each successfully completed achievement earns a set number of achievement points for the character or guild.</remarks>
Public Property Points As Integer

''' <summary>
Expand Down Expand Up @@ -95,7 +96,15 @@ Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements
''' <remarks>This represents whether the achievement is account-wide.</remarks>
Public Property AccountWide As Boolean

Friend Sub New(intID As Integer, strTitle As String, intPoints As Integer, strDescription As String, strReward As String, riRewardItems As Collection(Of RewardItem), strIcon As String, cCriteria As Collection(Of Criteria), blnAccountWide As Boolean)
''' <summary>
''' The faction that the achievement is specific to.
''' </summary>
''' <value>This property gets or sets the Faction field.</value>
''' <returns>Returns the faction that the achievement is specific to.</returns>
''' <remarks>This represents the faction that the achievement is specific to. If the achievement is not specific to any given faction, this returns <see cref="Side.Neutral" />.</remarks>
Public Property Faction As Side

Friend Sub New(intID As Integer, strTitle As String, intPoints As Integer, strDescription As String, strReward As String, riRewardItems As Collection(Of RewardItem), strIcon As String, cCriteria As Collection(Of Criteria), blnAccountWide As Boolean, sFaction As Side)
ID = intID
Title = strTitle
Points = intPoints
Expand All @@ -105,6 +114,7 @@ Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements
Icon = strIcon
colCriteria = cCriteria
AccountWide = blnAccountWide
Faction = sFaction
End Sub

End Class
Expand Down
202 changes: 202 additions & 0 deletions LibWowAPI/Achievements/clsAchievementLookup.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
' LibWowAPI
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Lesser General Public License (LGPL) Version 3.0.

Imports System
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.IO
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Json
Imports System.Text.Encoding
Imports roncliProductions.LibWowAPI.Enums
Imports roncliProductions.LibWowAPI.Extensions

Namespace roncliProductions.LibWowAPI.Achievements

''' <summary>
''' A class that looks up achievement information for a single achievement from the Blizzard WoW API.
''' </summary>
''' <remarks>This data class provides a way to retrieve information for a single achievement from the API. This works for both character achievements and guild achievements, since their achievement IDs are unique.</remarks>
''' <example>
''' The following example demonstrates how to make a call to the API to retrieve an achievement.
''' <code>
''' using roncliProductions.LibWowAPI.Achievements;
'''
''' namespace AchievementExample {
'''
''' public class AchievementClass {
'''
''' public Achievement GetAchievement(int achievementID) {
''' AchievementLookup achievement = new AchievementLookup();
''' achievement.Options.AchievementID = achievementID;
''' achievement.Load();
''' return achievement.Achievement;
''' }
'''
''' }
'''
''' }
''' </code>
''' <code lang="vbnet">
''' Imports roncliProductions.LibWowAPI.Achievements
'''
''' Namespace AchievementExample
'''
''' Public Class AchievementClass
'''
''' Public Function GetAchievement(achievementID As Integer) As Achievement
''' Dim achievement As New AchievementLookup()
''' achievement.Options.AchievementID = achievementID
''' achievement.Load()
''' Return achievement.Achievement
''' End Function
'''
''' End Class
'''
''' End Namespace
''' </code>
''' </example>
Public NotInheritable Class AchievementLookup
Inherits WowAPIData

Private alAchievement As New Schema.achievement

#Region "WowAPIData Overrides"

#Region "Properties"

''' <summary>
''' The length of time the data should be cached for, defaulting to 30 days for achievement information.
''' </summary>
''' <value>This property gets or sets the CacheLength field.</value>
''' <returns>Returns the length of time the data should be cached for, defaulting to 30 days for achievement information.</returns>
''' <remarks>The CacheLength is a <see cref="TimeSpan" /> that determines how long an API request should be stored in the cache. The default can be changed at any time before the <see cref="AchievementLookup.Load" /> method is called.</remarks>
Public Overrides Property CacheLength As New TimeSpan(30, 0, 0, 0)

#Region "Protected"

Protected Overrides ReadOnly Property CacheKey As String
Get
Return String.Format(CultureInfo.InvariantCulture, "LibWowAPI.Achievement.{0}", Options.AchievementID)
End Get
End Property

Protected Overrides ReadOnly Property URI As Uri
Get
Return New Uri(String.Format(CultureInfo.InvariantCulture, "/api/wow/achievement/{0}", Options.AchievementID), UriKind.Relative)
End Get
End Property

#End Region

#End Region

''' <summary>
''' Loads the achievement.
''' </summary>
''' <remarks>This method calls the Blizzard WoW API, receives the JSON, and translates it into an <see cref="Achievement" /> object. Each item in the collection represents a category of achievements received from the API.</remarks>
''' <exception cref="LibWowAPIException">If the JSON received from the API is invalid, the exception that caused it is packaged into the <see cref="LibWowAPIException.InnerException" /> of a <see cref="LibWowAPIException" />.</exception>
Public Overrides Sub Load()
MyBase.Retrieve()
If Modified.HasValue AndAlso Not Modified Then
Return
End If
Try
Using msJSON As New MemoryStream(Unicode.GetBytes(Data))
alAchievement = CType(New DataContractJsonSerializer(GetType(Schema.achievement)).ReadObject(msJSON), Schema.achievement)
End Using
Catch sex As SerializationException
Throw New LibWowAPIException("The data returned by the Armory is invalid.", sex)
End Try

aAchievement = New Achievement(
alAchievement.id,
alAchievement.title,
alAchievement.points,
alAchievement.description,
alAchievement.reward,
If(
alAchievement.rewardItems Is Nothing, Nothing, (
From ri In alAchievement.rewardItems
Select New RewardItem(
ri.id,
ri.name,
ri.icon,
CType(ri.quality, Quality),
ri.itemLevel,
ri.armor
)
).ToCollection()
),
alAchievement.icon,
If(
alAchievement.criteria Is Nothing, Nothing, (
From cr In alAchievement.criteria
Order By cr.orderIndex
Select New Criteria(
cr.id,
cr.description,
cr.orderIndex,
cr.max
)
).ToCollection()
),
alAchievement.accountWide,
CType(alAchievement.factionId, Side)
)
End Sub

#End Region

#Region "Properties"

''' <summary>
''' The options for looking up an achievement.
''' </summary>
''' <value>This property gets or sets the Options field.</value>
''' <returns>Returns the options for looking up an achievement.</returns>
''' <remarks>To set the options for the current request, set the appropriate properties on this object.</remarks>
Public Property Options As New AchievementLookupOptions

Private aAchievement As Achievement
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Achievement As Achievement
Get
Return aAchievement
End Get
End Property

#End Region

#Region "Methods"

''' <summary>
''' A default constructor to retrieve information for a single achievement from the Blizzard WoW API.
''' </summary>
''' <remarks>This method creates a new instance of the <see cref="AchievementLookup" /> class. You must call the <see cref="AchievementLookup.Load" /> method to load an achievement.</remarks>
Public Sub New()
End Sub

''' <summary>
''' A constructor to retrieve information for a single achievement from the Blizzard WoW API.
''' </summary>
''' <param name="intAchievementID">The achievement ID to lookup.</param>
''' <remarks>This method creates a new instance of the <see cref="AchievementLookup" /> class and automatically loads the data for the specified achievement ID.</remarks>
Public Sub New(intAchievementID As Integer)
Options.AchievementID = intAchievementID
Load()
End Sub

#End Region

End Class

End Namespace
27 changes: 27 additions & 0 deletions LibWowAPI/Achievements/clsAchievementLookupOptions.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
' LibWowAPI
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Lesser General Public License (LGPL) Version 3.0.

Namespace roncliProductions.LibWowAPI.Achievements

''' <summary>
''' A class that defines options for the achievement lookup.
''' </summary>
''' <remarks>This class allows you to define the achievement ID to look up an achievement. There is no need to create an instance of this class, as the <see cref="AchievementLookup.Options" /> property automatically does so for you.</remarks>
Public Class AchievementLookupOptions

''' <summary>
''' The achievement ID to lookup.
''' </summary>
''' <value>This property gets or sets the AchievementID field.</value>
''' <returns>Returns the achievement ID to lookup.</returns>
''' <remarks>This represents the achievement ID to lookup.</remarks>
Public Property AchievementID As Integer

Friend Sub New()
End Sub

End Class

End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Imports System.Collections.ObjectModel

Namespace roncliProductions.LibWowAPI.Data.CharacterAchievements
Namespace roncliProductions.LibWowAPI.Achievements

''' <summary>
''' A class containing information about an achievement category.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'
' This source code is released under the GNU Lesser General Public License (LGPL) Version 3.0.

Namespace roncliProductions.LibWowAPI.Data.GuildAchievements
Namespace roncliProductions.LibWowAPI.Achievements

''' <summary>
''' A class containing information about criteria for an achievement.
Expand Down
Loading

0 comments on commit fabf2fd

Please sign in to comment.