Skip to content

Commit

Permalink
CharacterProfileSummary Revision Error (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzyStatic authored Jun 4, 2021
1 parent 7c4c863 commit 83d17e0
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 15 deletions.
54 changes: 44 additions & 10 deletions v2/blizzard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/FuzzyStatic/blizzard/v2/wowp"
"github.com/FuzzyStatic/blizzard/v2/wowsearch"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
Expand Down Expand Up @@ -226,14 +228,46 @@ func (c *Client) getStructData(ctx context.Context, pathAndQuery, namespace stri
return dat, nil, errors.New(res.Status)
}

err = json.Unmarshal(body, &dat)
header, err := getHeader(res.Header)
if err != nil {
return dat, nil, err
}

header, err := getHeader(res.Header)
if err != nil {
return dat, nil, err
switch dat.(type) {
case *wowp.CharacterProfileSummary:
bnSchRev, err := strconv.ParseInt(header.BattlenetSchemaRevision, 10, 64)
if err != nil {
return dat, nil, err
}

if bnSchRev < 24 {
fmt.Println("true")
var temp *wowp.CharacterProfileSummaryPreRev24
err = json.Unmarshal(body, &temp)
if err != nil {
return dat, nil, err
}

var activeTitle wowp.ActiveTitlePreRev24
err = json.Unmarshal(body, &activeTitle)
if err != nil {
return dat, nil, err
}

wowp.ConvertCharacterProfileSummaryPreRev24(activeTitle.ActiveTitle,
temp, dat.(*wowp.CharacterProfileSummary))
break
}

err = json.Unmarshal(body, &dat)
if err != nil {
return dat, nil, err
}
default:
err = json.Unmarshal(body, &dat)
if err != nil {
return dat, nil, err
}
}

return dat, header, nil
Expand Down Expand Up @@ -268,12 +302,12 @@ func (c *Client) getStructDataNoNamespace(ctx context.Context, pathAndQuery stri
return dat, nil, errors.New(res.Status)
}

err = json.Unmarshal(body, &dat)
header, err := getHeader(res.Header)
if err != nil {
return dat, nil, err
}

header, err := getHeader(res.Header)
err = json.Unmarshal(body, &dat)
if err != nil {
return dat, nil, err
}
Expand Down Expand Up @@ -306,12 +340,12 @@ func (c *Client) getStructDataNoNamespaceNoLocale(ctx context.Context, pathAndQu
return dat, nil, errors.New(res.Status)
}

err = json.Unmarshal(body, &dat)
header, err := getHeader(res.Header)
if err != nil {
return dat, nil, err
}

header, err := getHeader(res.Header)
err = json.Unmarshal(body, &dat)
if err != nil {
return dat, nil, err
}
Expand Down Expand Up @@ -355,12 +389,12 @@ func (c *Client) getStructDataOAuth(ctx context.Context, pathAndQuery, namespace
return dat, nil, errors.New(res.Status)
}

err = json.Unmarshal(body, &dat)
header, err := getHeader(res.Header)
if err != nil {
return dat, nil, err
}

header, err := getHeader(res.Header)
err = json.Unmarshal(body, &dat)
if err != nil {
return dat, nil, err
}
Expand Down
156 changes: 151 additions & 5 deletions v2/wowp/characterProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,132 @@ type CharacterProfileSummary struct {
Collections struct {
Href string `json:"href"`
} `json:"collections"`
ActiveTitle struct {
ActiveTitle ActiveTitle `json:"active_title"`
Reputations struct {
Href string `json:"href"`
} `json:"reputations"`
}

// ActiveTitle structure
type ActiveTitle struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
DisplayString string `json:"display_string"`
}

// CharacterProfileSummaryPreRev24 structure
type CharacterProfileSummaryPreRev24 struct {
Links struct {
Self struct {
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
ID int `json:"id"`
Name string `json:"name"`
Gender struct {
Type string `json:"type"`
Name string `json:"name"`
} `json:"gender"`
Faction struct {
Type string `json:"type"`
Name string `json:"name"`
} `json:"faction"`
Race struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"race"`
CharacterClass struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"character_class"`
ActiveSpec struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
DisplayString string `json:"display_string"`
} `json:"active_title"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"active_spec"`
Realm struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
Slug string `json:"slug"`
} `json:"realm"`
Guild struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
Realm struct {
Key struct {
Href string `json:"href"`
} `json:"key"`
Name string `json:"name"`
ID int `json:"id"`
Slug string `json:"slug"`
} `json:"realm"`
} `json:"guild"`
Level int `json:"level"`
Experience int `json:"experience"`
AchievementPoints int `json:"achievement_points"`
Achievements struct {
Href string `json:"href"`
} `json:"achievements"`
Titles struct {
Href string `json:"href"`
} `json:"titles"`
PvpSummary struct {
Href string `json:"href"`
} `json:"pvp_summary"`
RaidProgression struct {
Href string `json:"href"`
} `json:"raid_progression"`
Media struct {
Href string `json:"href"`
} `json:"media"`
LastLoginTimestamp int64 `json:"last_login_timestamp"`
AverageItemLevel int `json:"average_item_level"`
EquippedItemLevel int `json:"equipped_item_level"`
Specializations struct {
Href string `json:"href"`
} `json:"specializations"`
Statistics struct {
Href string `json:"href"`
} `json:"statistics"`
MythicKeystoneProfile struct {
Href string `json:"href"`
} `json:"mythic_keystone_profile"`
Equipment struct {
Href string `json:"href"`
} `json:"equipment"`
Appearance struct {
Href string `json:"href"`
} `json:"appearance"`
Collections struct {
Href string `json:"href"`
} `json:"collections"`
Reputations struct {
Href string `json:"href"`
} `json:"reputations"`
}

// ActiveTitlePreRev24 structure
type ActiveTitlePreRev24 struct {
ActiveTitle string `json:"active_title"`
}

// CharacterProfileStatus structure
type CharacterProfileStatus struct {
Links struct {
Expand All @@ -123,3 +236,36 @@ type CharacterProfileStatus struct {
ID int `json:"id"`
IsValid bool `json:"is_valid"`
}

func ConvertCharacterProfileSummaryPreRev24(activeTitle string,
cpspr *CharacterProfileSummaryPreRev24, cps *CharacterProfileSummary) {
cps.Links = cpspr.Links
cps.ID = cpspr.ID
cps.Name = cpspr.Name
cps.Gender = cpspr.Gender
cps.Faction = cpspr.Faction
cps.Race = cpspr.Race
cps.CharacterClass = cpspr.CharacterClass
cps.ActiveSpec = cpspr.ActiveSpec
cps.Realm = cpspr.Realm
cps.Guild = cpspr.Guild
cps.Level = cpspr.Level
cps.Experience = cpspr.Experience
cps.AchievementPoints = cpspr.AchievementPoints
cps.Achievements = cpspr.Achievements
cps.Titles = cpspr.Titles
cps.PvpSummary = cpspr.PvpSummary
cps.RaidProgression = cpspr.RaidProgression
cps.Media = cpspr.Media
cps.LastLoginTimestamp = cpspr.LastLoginTimestamp
cps.AverageItemLevel = cpspr.AverageItemLevel
cps.EquippedItemLevel = cpspr.EquippedItemLevel
cps.Specializations = cpspr.Specializations
cps.Statistics = cpspr.Statistics
cps.MythicKeystoneProfile = cpspr.MythicKeystoneProfile
cps.Equipment = cpspr.Equipment
cps.Appearance = cpspr.Appearance
cps.Collections = cpspr.Collections
cps.ActiveTitle.Name = activeTitle
cps.Reputations = cpspr.Reputations
}

0 comments on commit 83d17e0

Please sign in to comment.