-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec58273
commit 0eb04ad
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/xonvanetta/tibiadata/internal/httpclient" | ||
) | ||
|
||
type Client interface { | ||
//Guild(ctx context.Context, name string) (*GuildResponse, error) | ||
//Guilds(ctx context.Context, world string) (*GuildsResponse, error) | ||
|
||
World(ctx context.Context, name string) (*WorldResponse, error) | ||
Worlds(ctx context.Context) (*WorldsResponse, error) | ||
|
||
//Character(ctx context.Context, name string) (*CharacterResponse, error) | ||
// | ||
//Highscore(ctx context.Context, world, category string, vocation tibia.Vocation) (*HighscoreResponse, error) | ||
// | ||
//News(context context.Context, newsId int) (*NewsResponse, error) | ||
} | ||
|
||
type client struct { | ||
client httpclient.Client | ||
} | ||
|
||
var ( | ||
URL = "https://api.tibiadata.com/v3/" | ||
ErrNotFound = errors.New("tibiadata: not found") | ||
) | ||
|
||
func NewClient() Client { | ||
return client{ | ||
client: httpclient.New(), | ||
} | ||
} | ||
|
||
func tibiaDataURL(path string) string { | ||
return fmt.Sprintf("%s%s", URL, path) | ||
} | ||
|
||
type Information struct { | ||
APIVersion int `json:"api_version"` | ||
Timestamp time.Time `json:"timestamp"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type WorldResponse struct { | ||
Worlds *struct { | ||
World *struct { | ||
Name string `json:"name"` | ||
Status string `json:"status"` | ||
PlayersOnline int `json:"players_online"` | ||
RecordPlayers int `json:"record_players"` | ||
RecordDate time.Time `json:"record_date"` | ||
CreationDate string `json:"creation_date"` | ||
Location string `json:"location"` | ||
PvpType string `json:"pvp_type"` | ||
PremiumOnly bool `json:"premium_only"` | ||
TransferType string `json:"transfer_type"` | ||
WorldQuestTitles []string `json:"world_quest_titles"` | ||
BattleyeProtected bool `json:"battleye_protected"` | ||
BattleyeDate string `json:"battleye_date"` | ||
GameWorldType string `json:"game_world_type"` | ||
TournamentWorldType string `json:"tournament_world_type"` | ||
OnlinePlayers []*struct { | ||
Name string `json:"name"` | ||
Level int `json:"level"` | ||
Vocation string `json:"vocation"` | ||
} `json:"online_players"` | ||
} `json:"world"` | ||
} `json:"worlds"` | ||
Information *Information `json:"information"` | ||
} | ||
|
||
func (c client) World(context context.Context, name string) (*WorldResponse, error) { | ||
worldResponse := &WorldResponse{} | ||
url := tibiaDataURL(fmt.Sprintf("world/%s", name)) | ||
err := c.client.Get(context, url, worldResponse) | ||
return worldResponse, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type WorldsResponse struct { | ||
Worlds *struct { | ||
PlayersOnline int `json:"players_online"` | ||
RecordPlayers int `json:"record_players"` | ||
RecordDate time.Time `json:"record_date"` | ||
RegularWorlds []*struct { | ||
Name string `json:"name"` | ||
Status string `json:"status"` | ||
PlayersOnline int `json:"players_online"` | ||
Location string `json:"location"` | ||
PvpType string `json:"pvp_type"` | ||
PremiumOnly bool `json:"premium_only"` | ||
TransferType string `json:"transfer_type"` | ||
BattleyeProtected bool `json:"battleye_protected"` | ||
BattleyeDate string `json:"battleye_date"` | ||
GameWorldType string `json:"game_world_type"` | ||
TournamentWorldType string `json:"tournament_world_type"` | ||
} `json:"regular_worlds"` | ||
TournamentWorlds []*struct { | ||
Name string `json:"name"` | ||
Status string `json:"status"` | ||
PlayersOnline int `json:"players_online"` | ||
Location string `json:"location"` | ||
PvpType string `json:"pvp_type"` | ||
PremiumOnly bool `json:"premium_only"` | ||
TransferType string `json:"transfer_type"` | ||
BattleyeProtected bool `json:"battleye_protected"` | ||
BattleyeDate string `json:"battleye_date"` | ||
GameWorldType string `json:"game_world_type"` | ||
TournamentWorldType string `json:"tournament_world_type"` | ||
} `json:"tournament_worlds"` | ||
} `json:"worlds"` | ||
Information *Information `json:"information"` | ||
} | ||
|
||
func (c client) Worlds(context context.Context) (*WorldsResponse, error) { | ||
worldsResponse := &WorldsResponse{} | ||
err := c.client.Get(context, tibiaDataURL("worlds"), worldsResponse) | ||
return worldsResponse, err | ||
} |