Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Idea IDE files
.idea/
7 changes: 7 additions & 0 deletions .idea/dictionaries/Nick.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/go-bnet-fork.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/libraries/GOPATH__go_bnet_fork_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/Go_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

765 changes: 765 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestAccountService_User(t *testing.T) {
})

actual, _, err := client.Account().User()
fmt.Print(actual)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (c *Client) Account() *AccountService {
return &AccountService{client: c}
}

func (c *Client) Profile() *ProfileService {
return &ProfileService{client: c}
}

// NewRequest creates an API request. A relative URL can be provided in urlStr,
// in which case it is resolved relative to the BaseURL of the Client.
// Relative URLs should always be specified without a preceding slash. If
Expand Down
28 changes: 28 additions & 0 deletions profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bnet

// ProfileService has OAuth Profile APIs. See Client.
type ProfileService struct {
client *Client
}

// SC2Profile represents the profile information for a user's Starcraft 2 profile.
type SC2Profile struct {
Characters []SC2Character `json:"characters"`
}

// SC2() calls the /sc2/profile/user endpoint. This endpoint uses OAuth2
// to retrieve a user's Starcraft 2 profile. See Battle.net docs.
func (s *ProfileService) SC2() (*SC2Profile, *Response, error) {
req, err := s.client.NewRequest("GET", "sc2/profile/user", nil)
if err != nil {
return nil, nil, err
}

var profile SC2Profile
resp, err := s.client.Do(req, &profile)
if err != nil {
return nil, resp, err
}

return &profile, resp, nil
}
94 changes: 94 additions & 0 deletions sc2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package bnet

// SC2Service has Starcraft2-related APIs. See Client.
type SC2Service struct {
client *Client
}

// TODO: Create a 'Campaign' struct to represent a character's campaign progress.

// CharacterImage is a character's portrait or avatar.
type CharacterImage struct {
X int `json:"x"`
Y int `json:"y"`
W int `json:"w"`
H int `json:"h"`
Offset int `json:"offset"`
Url string `json:"url"`
}

// Career represents game statistics for a character's Battle.net career.
type Career struct {
PrimaryRace string `json:"primaryRace"`
TerranWins int `json:"terranWins"`
ProtossWins int `json:"protossWins"`
ZergWins int `json:"zergWins"`
Highest1v1Rank string `json:"highest1v1Rank"`
SeasonTotalGames int `json:"seasonTotalGames"`
CareerTotalGames int `json:"careerTotalGames"`
}

// Level is the current level and XP a character has earned.
type Level struct {
Level int `json:"level"`
TotalLevelXP int `json:"totalLevelXP"`
CurrentLevelXP int `json:"currentLevelXP"`
}

// SwarmLevels represents a character's level for each swarm (race) as well as their overall level.
type SwarmLevels struct {
Level int `json:"level"`
Terran Level `json:"terran"`
Zerg Level `json:"zerg"`
Protoss Level `json:"protoss"`
}

// Season is the current Starcraft 2 online multiplayer season.
type Season struct {
ID int `json:"seasonId"`
Number int `json:"seasonNumber"`
Year int `json:"seasonYear"`
TotalGames int `json:"totalGamesThisSeason"`
}

// Rewards represents selected and earned rewards for a profile.
type Rewards struct {
Selected []int `json:"selected"`
Earned []int `json:"earned"`
}

// Points holds a character's total achievement points.
type Points struct {
Total int `json:"totalPoints"`
}

// Achievement represents a single Starcraft 2 achievement.
type Achievement struct {
ID int `json:"achievementId"`
CompletionDate int `json:"completionDate"`
}

// Achievements represents achievement information for a Starcraft 2 profile.
type Achievements struct {
Points Points `json:"points"`
Achievements []Achievement `json:"achievements"`
}

// SC2Character represents a character in a user's Starcraft 2 profile.
type SC2Character struct {
ID int `json:"id"`
Realm int `json:"realm"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
ClanName string `json:"clanName"`
ClanTag string `json:"clanTag"`
ProfilePath string `json:"profilePath"`
Portrait CharacterImage `json:"portrait"`
Avatar CharacterImage `json:"avatar"`
Career Career `json:"career"`
SwarmLevels SwarmLevels `json:"swarmLevels"`
Season Season `json:"season"`
Rewards Rewards `json:"rewards"`
Achievements Achievements `json:"achievements"`
}