├── .gitignore ├── codecov.yml ├── src ├── V2 │ ├── Endpoint │ │ ├── Guild │ │ │ ├── Exception │ │ │ │ ├── GuildLeaderRequiredException.php │ │ │ │ ├── MembershipRequiredException.php │ │ │ │ └── GuildException.php │ │ │ ├── IRestrictedGuildEndpoint.php │ │ │ ├── SearchEndpoint.php │ │ │ ├── UpgradeEndpoint.php │ │ │ ├── PermissionEndpoint.php │ │ │ ├── Authenticated │ │ │ │ ├── RankEndpoint.php │ │ │ │ ├── StashEndpoint.php │ │ │ │ ├── TeamEndpoint.php │ │ │ │ ├── MemberEndpoint.php │ │ │ │ ├── TreasuryEndpoint.php │ │ │ │ ├── UpgradeEndpoint.php │ │ │ │ └── LogEndpoint.php │ │ │ ├── DetailsEndpoint.php │ │ │ └── RestrictedGuildHandler.php │ │ ├── File │ │ │ └── FileEndpoint.php │ │ ├── Home │ │ │ ├── CatEndpoint.php │ │ │ ├── NodeEndpoint.php │ │ │ └── HomeEndpoint.php │ │ ├── Legend │ │ │ └── LegendEndpoint.php │ │ ├── Quaggan │ │ │ └── QuagganEndpoint.php │ │ ├── Build │ │ │ └── BuildEndpoint.php │ │ ├── Commerce │ │ │ ├── PriceEndpoint.php │ │ │ ├── ListingEndpoint.php │ │ │ ├── ExchangeEndpoint.php │ │ │ ├── Transaction │ │ │ │ ├── TransactionEndpoint.php │ │ │ │ ├── TypeEndpoint.php │ │ │ │ └── ListEndpoint.php │ │ │ └── CommerceEndpoint.php │ │ ├── Backstory │ │ │ ├── BackstoryEndpoint.php │ │ │ ├── AnswerEndpoint.php │ │ │ └── QuestionEndpoint.php │ │ ├── Achievement │ │ │ ├── DailyTomorrowEndpoint.php │ │ │ ├── GroupEndpoint.php │ │ │ ├── CategoryEndpoint.php │ │ │ ├── DailyEndpoint.php │ │ │ └── AchievementEndpoint.php │ │ ├── Pet │ │ │ └── PetEndpoint.php │ │ ├── Pvp │ │ │ ├── HeroEndpoint.php │ │ │ ├── RankEndpoint.php │ │ │ ├── AmuletEndpoint.php │ │ │ ├── SeasonEndpoint.php │ │ │ ├── GameEndpoint.php │ │ │ ├── StatsEndpoint.php │ │ │ ├── StandingEndpoint.php │ │ │ ├── LeaderboardEndpoint.php │ │ │ ├── LeaderboardRegionEndpoint.php │ │ │ └── PvpEndpoint.php │ │ ├── WvW │ │ │ ├── RankEndpoint.php │ │ │ ├── ObjectiveEndpoint.php │ │ │ ├── AbilityEndpoint.php │ │ │ ├── UpgradeEndpoint.php │ │ │ ├── ScoreEndpoint.php │ │ │ ├── StatEndpoint.php │ │ │ ├── OverviewEndpoint.php │ │ │ ├── WvWEndpoint.php │ │ │ └── MatchEndpoint.php │ │ ├── Color │ │ │ └── ColorEndpoint.php │ │ ├── Mount │ │ │ ├── SkinEndpoint.php │ │ │ ├── TypeEndpoint.php │ │ │ └── MountEndpoint.php │ │ ├── Traits │ │ │ └── TraitEndpoint.php │ │ ├── World │ │ │ └── WorldEndpoint.php │ │ ├── Currency │ │ │ └── CurrencyEndpoint.php │ │ ├── Material │ │ │ └── MaterialEndpoint.php │ │ ├── WorldBoss │ │ │ └── WorldBossEndpoint.php │ │ ├── Mini │ │ │ └── MiniEndpoint.php │ │ ├── Quest │ │ │ └── QuestEndpoint.php │ │ ├── Title │ │ │ └── TitleEndpoint.php │ │ ├── Outfit │ │ │ └── OutfitEndpoint.php │ │ ├── Mastery │ │ │ └── MasteryEndpoint.php │ │ ├── Novelty │ │ │ └── NoveltyEndpoint.php │ │ ├── Story │ │ │ ├── SeasonEndpoint.php │ │ │ └── StoryEndpoint.php │ │ ├── Finisher │ │ │ └── FinisherEndpoint.php │ │ ├── Itemstat │ │ │ └── ItemstatEndpoint.php │ │ ├── Mapchest │ │ │ └── MapchestEndpoint.php │ │ ├── Mailcarrier │ │ │ └── MailcarrierEndpoint.php │ │ ├── Map │ │ │ └── MapEndpoint.php │ │ ├── Item │ │ │ └── ItemEndpoint.php │ │ ├── Skin │ │ │ └── SkinEndpoint.php │ │ ├── DailyCrafting │ │ │ └── DailyCraftingEndpoint.php │ │ ├── Recipe │ │ │ ├── SearchEndpoint.php │ │ │ └── RecipeEndpoint.php │ │ ├── Skill │ │ │ └── SkillEndpoint.php │ │ ├── Race │ │ │ └── RaceEndpoint.php │ │ ├── Raid │ │ │ └── RaidEndpoint.php │ │ ├── Glider │ │ │ └── GliderEndpoint.php │ │ ├── Dungeon │ │ │ └── DungeonEndpoint.php │ │ ├── Profession │ │ │ └── ProfessionEndpoint.php │ │ ├── Emblem │ │ │ ├── EmblemEndpoint.php │ │ │ └── LayerEndpoint.php │ │ ├── Specialization │ │ │ └── SpecializationEndpoint.php │ │ ├── Account │ │ │ ├── DyeEndpoint.php │ │ │ ├── BankEndpoint.php │ │ │ ├── MiniEndpoint.php │ │ │ ├── RaidEndpoint.php │ │ │ ├── SkinEndpoint.php │ │ │ ├── TitleEndpoint.php │ │ │ ├── GliderEndpoint.php │ │ │ ├── OutfitEndpoint.php │ │ │ ├── RecipeEndpoint.php │ │ │ ├── WalletEndpoint.php │ │ │ ├── DungeonEndpoint.php │ │ │ ├── FinisherEndpoint.php │ │ │ ├── Home │ │ │ │ ├── CatEndpoint.php │ │ │ │ ├── NodeEndpoint.php │ │ │ │ └── HomeEndpoint.php │ │ │ ├── MapchestEndpoint.php │ │ │ ├── MasteryEndpoint.php │ │ │ ├── MaterialEndpoint.php │ │ │ ├── NoveltyEndpoint.php │ │ │ ├── Pvp │ │ │ │ ├── HeroEndpoint.php │ │ │ │ └── PvpEndpoint.php │ │ │ ├── InventoryEndpoint.php │ │ │ ├── MailcarrierEndpoint.php │ │ │ ├── Mount │ │ │ │ ├── SkinEndpoint.php │ │ │ │ ├── TypeEndpoint.php │ │ │ │ └── MountEndpoint.php │ │ │ ├── DailyCraftingEndpoint.php │ │ │ ├── LuckEndpoint.php │ │ │ └── AchievementEndpoint.php │ │ ├── Continent │ │ │ ├── ContinentEndpoint.php │ │ │ ├── FloorEndpoint.php │ │ │ ├── RegionEndpoint.php │ │ │ ├── TaskEndpoint.php │ │ │ ├── PoiEndpoint.php │ │ │ ├── SectorEndpoint.php │ │ │ └── MapEndpoint.php │ │ ├── Tokeninfo │ │ │ └── TokeninfoEndpoint.php │ │ └── Character │ │ │ ├── CoreEndpoint.php │ │ │ ├── SabEndpoint.php │ │ │ ├── QuestEndpoint.php │ │ │ ├── HeropointEndpoint.php │ │ │ ├── RecipeEndpoint.php │ │ │ ├── SkillEndpoint.php │ │ │ ├── InventoryEndpoint.php │ │ │ ├── BackstoryEndpoint.php │ │ │ ├── CraftingEndpoint.php │ │ │ ├── EquipmentEndpoint.php │ │ │ ├── TrainingEndpoint.php │ │ │ └── SpecializationEndpoint.php │ ├── Pagination │ │ ├── Exception │ │ │ └── PageOutOfRangeException.php │ │ ├── IPaginatedEndpoint.php │ │ └── PaginationHandler.php │ ├── Authentication │ │ ├── Exception │ │ │ ├── AuthenticationException.php │ │ │ └── InvalidPermissionsException.php │ │ ├── IAuthenticatedEndpoint.php │ │ ├── AuthenticatedEndpoint.php │ │ └── AuthenticationHandler.php │ ├── Localization │ │ ├── ILocalizedEndpoint.php │ │ ├── LocalizedEndpoint.php │ │ ├── Exception │ │ │ └── InvalidLanguageException.php │ │ └── LocalizationHandler.php │ ├── Bulk │ │ ├── IBulkEndpoint.php │ │ └── BulkEndpoint.php │ ├── Schema │ │ └── SchemaHandler.php │ ├── IEndpoint.php │ ├── ApiResponse.php │ ├── EndpointTrait.php │ └── ApiHandler.php ├── Exception │ └── ApiException.php └── Middleware │ └── EffectiveUrlMiddleware.php ├── tests ├── Stubs │ ├── LocalizedEndpointStub.php │ ├── AuthenticatedEndpointStub.php │ ├── PaginatedEndpointStub.php │ ├── EndpointStub.php │ ├── BulkEndpointStub.php │ └── GW2ApiStub.php ├── V2 │ ├── BuildEndpointTest.php │ ├── ColorEndpointTest.php │ ├── FileEndpointTest.php │ ├── TitleEndpointTest.php │ ├── TraitEndpointTest.php │ ├── CurrencyEndpointTest.php │ ├── GliderEndpointTest.php │ ├── RaidEndpointTest.php │ ├── SkinEndpointTest.php │ ├── FinisherEndpointTest.php │ ├── ItemEndpointTest.php │ ├── OutfitEndpointTest.php │ ├── QuagganEndpointTest.php │ ├── MasteryEndpointTest.php │ ├── LegendEndpointTest.php │ ├── QuestEndpointTest.php │ ├── SkillEndpointTest.php │ ├── WorldEndpointTest.php │ ├── MailcarrierEndpointTest.php │ ├── NoveltyEndpointTest.php │ ├── PetEndpointTest.php │ ├── WorldBossEndpointTest.php │ ├── ItemstatEndpointTest.php │ ├── RaceEndpointTest.php │ ├── SpecializationEndpointTest.php │ ├── MiniEndpointTest.php │ ├── DailyCraftingEndpointTest.php │ ├── MapchestEndpointTest.php │ ├── DungeonEndpointTest.php │ ├── MaterialEndpointTest.php │ ├── CharacterInventoryEndpointTest.php │ ├── ProfessionEndpointTest.php │ ├── TokeninfoEndpointTest.php │ ├── CharacterEquipmentEndpointTest.php │ ├── CharacterSpecializationEndpointTest.php │ ├── MapEndpointTest.php │ ├── HomeEndpointTest.php │ ├── StoryEndpointTest.php │ ├── BackstoryEndpointTest.php │ ├── RecipeEndpointTest.php │ ├── MountEndpointTest.php │ ├── EmblemEndpointTest.php │ ├── CommerceEndpointTest.php │ └── AchievementEndpointTest.php ├── EndpointTest.php ├── GW2ApiTest.php ├── SchemaTest.php ├── LocalizedEndpointTest.php └── AuthenticatedEndpointTest.php ├── phpunit.xml ├── composer.json ├── LICENSE └── .travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | vendor/ 3 | .idea/ 4 | composer.lock 5 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | notify: 3 | gitter: 4 | default: 5 | threshold: 0 6 | url: https://webhooks.gitter.im/e/65c5153b2ad5cf17d675 7 | 8 | comment: off 9 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Exception/GuildLeaderRequiredException.php: -------------------------------------------------------------------------------- 1 | api()->build(); 6 | 7 | $this->assertEndpointUrl( 'v2/build', $endpoint ); 8 | 9 | $this->mockResponse( '{"id":1337}' ); 10 | $this->assertEquals( 1337, $endpoint->get() ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/V2/Authentication/IAuthenticatedEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/V2/Endpoint/File/FileEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->colors(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/colors', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9,10]'); 12 | $this->assertCount( 10, $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/FileEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->files(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointUrl( 'v2/files', $endpoint ); 9 | 10 | $this->mockResponse('["map_complete","map_dungeon","map_heart_empty","map_heart_full"]'); 11 | $this->assertContainsEquals( 'map_heart_empty', $endpoint->ids() ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/V2/TitleEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->titles(); 6 | 7 | $this->assertEndpointIsBulk($endpoint); 8 | $this->assertEndpointIsLocalized($endpoint); 9 | $this->assertEndpointUrl('v2/titles', $endpoint); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9]'); 12 | $this->assertEquals([1,2,3,4,5,6,7,8,9], $endpoint->ids()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/TraitEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->traits(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/traits', $endpoint ); 10 | 11 | $this->mockResponse('[214,221,222,223]'); 12 | $this->assertEquals( [214,221,222,223], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/CurrencyEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->currencies(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/currencies', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5]'); 12 | $this->assertEquals( [1,2,3,4,5], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/GliderEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->gliders(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/gliders', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9]'); 12 | $this->assertEquals([1,2,3,4,5,6,7,8,9], $endpoint->ids()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/RaidEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->raids(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/raids', $endpoint ); 10 | 11 | $this->mockResponse('["forsaken_thicket"]'); 12 | $this->assertEquals( ["forsaken_thicket"], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/SkinEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->skins(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/skins', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9,10]'); 12 | $this->assertEquals( [1,2,3,4,5,6,7,8,9,10], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/FinisherEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->finishers(); 6 | 7 | $this->assertEndpointIsBulk($endpoint); 8 | $this->assertEndpointIsLocalized($endpoint); 9 | $this->assertEndpointUrl('v2/finishers', $endpoint); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9]'); 12 | $this->assertEquals([1,2,3,4,5,6,7,8,9], $endpoint->ids()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/ItemEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->items(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/items', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,6,11,24,56,57,58,59]'); 12 | $this->assertEquals( [1,2,6,11,24,56,57,58,59], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/OutfitEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->outfits(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/outfits', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,8,12,13]'); 12 | $this->assertEquals( [1,2,3,4,5,6,8,12,13], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/QuagganEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->quaggans(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointUrl( 'v2/quaggans', $endpoint ); 9 | 10 | $this->mockResponse('{"id":"cheer","url":"https://static.staticwars.com/quaggans/cheer.jpg"}'); 11 | $this->assertStringEndsWith( 'cheer.jpg', $endpoint->get('cheer')->url ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/V2/MasteryEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->masteries(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/masteries', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,8,12,13]'); 12 | $this->assertEquals( [1,2,3,4,5,6,8,12,13], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Home/HomeEndpoint.php: -------------------------------------------------------------------------------- 1 | api ); 17 | } 18 | 19 | public function nodes() { 20 | return new NodeEndpoint( $this->api ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/V2/LegendEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->legends(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointUrl( 'v2/legends', $endpoint ); 9 | 10 | $this->mockResponse('{"id":"Legend1","swap":28229,"heal":27220,"elite":27760,"utilities":[28379,27014,26644]}'); 11 | $this->assertEquals('27220', $endpoint->get('Legend1')->heal); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Build/BuildEndpoint.php: -------------------------------------------------------------------------------- 1 | request()->json()->id; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/V2/QuestEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->quests(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/quests', $endpoint ); 10 | 11 | $this->mockResponse('{"id":"15", "name": "Explosive Intellect"}'); 12 | $this->assertEquals('Explosive Intellect', $endpoint->get(15)->name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/SkillEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->skills(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/skills', $endpoint ); 10 | 11 | $this->mockResponse('[1175,5487,5489,5490,5491,5492]'); 12 | $this->assertEquals( [1175,5487,5489,5490,5491,5492], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/WorldEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->worlds(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/worlds', $endpoint ); 10 | 11 | $this->mockResponse('[{"id":1001,"name":"Anvil Rock"}]'); 12 | $this->assertEquals( 'Anvil Rock', $endpoint->many([1001])[0]->name ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/MailcarrierEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->mailcarriers(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/mailcarriers', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,8,12,13]'); 12 | $this->assertEquals( [1,2,3,4,5,6,8,12,13], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/NoveltyEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->novelties(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/novelties', $endpoint ); 10 | 11 | $this->mockResponse('{"id":1,"name":"Embellished Kite"}'); 12 | $this->assertEquals('Embellished Kite', $endpoint->get(1)->name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/PetEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->pets(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/pets', $endpoint ); 10 | 11 | $this->mockResponse('{"id":1,"name":"Juvenile Jungle Stalker"}'); 12 | $this->assertEquals('Juvenile Jungle Stalker', $endpoint->get(1)->name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/WorldBossEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->worldbosses(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/worldbosses', $endpoint ); 10 | 11 | $this->mockResponse('{"id":"karka_queen"}'); 12 | $this->assertEquals('karka_queen', $endpoint->get('karka_queen')->id); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/ItemstatEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->itemstats(); 6 | 7 | $this->assertEndpointIsBulk($endpoint); 8 | $this->assertEndpointIsLocalized($endpoint); 9 | $this->assertEndpointUrl('v2/itemstats', $endpoint); 10 | 11 | $this->mockResponse('{"id":137,"name":"Mighty","attributes":{"Power":0.35}}'); 12 | $this->assertEquals('Mighty', $endpoint->get(137)->name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/SearchEndpoint.php: -------------------------------------------------------------------------------- 1 | request([ 'name' => $name ])->json(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/V2/Localization/ILocalizedEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->races(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/races', $endpoint ); 10 | 11 | $this->mockResponse('["Human","Asura","Sylvari","Charr","Norn"]'); 12 | $this->assertEquals( ["Human","Asura","Sylvari","Charr","Norn"], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/SpecializationEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->specializations(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/specializations', $endpoint ); 10 | 11 | $this->mockResponse('[1,2,3,4,5,6,7,8,9,10]'); 12 | $this->assertEquals( [1,2,3,4,5,6,7,8,9,10], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/Stubs/AuthenticatedEndpointStub.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/V2/MiniEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->minis(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/minis', $endpoint ); 10 | 11 | $this->mockResponse('{"id":1,"name":"Miniature Rytlock","order":1,"item_id":21047}'); 12 | $this->assertEquals('Miniature Rytlock', $endpoint->get(1)->name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/DailyCraftingEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->dailycrafting(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/dailycrafting', $endpoint ); 10 | 11 | $this->mockResponse('{"id":"lump_of_mithrilium"}'); 12 | $this->assertEquals('lump_of_mithrilium', $endpoint->get('lump_of_mithrilium')->id); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/V2/MapchestEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->mapchests(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/mapchests', $endpoint ); 10 | 11 | $this->mockResponse('{"id":"auric_basin_heros_choice_chest"}'); 12 | $this->assertEquals('auric_basin_heros_choice_chest', $endpoint->get('auric_basin_heros_choice_chest')->id); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/PriceEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->dungeons(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/dungeons', $endpoint ); 10 | 11 | $this->mockResponse('{"id":"ascalonian_catacombs","paths":[{"id":"hodgins"},{"id":"detha"},{"id":"tzark"}]}'); 12 | $this->assertCount(3, $endpoint->get('ascalonian_catacombs')->paths); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/ListingEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->materials(); 10 | 11 | $this->assertEndpointIsBulk( $endpoint ); 12 | $this->assertEndpointIsLocalized( $endpoint ); 13 | $this->assertEndpointUrl( 'v2/materials', $endpoint ); 14 | 15 | $this->mockResponse('{"id":5,"name":"Cooking Materials","items":[12134,12238,12147]}'); 16 | $this->assertCount(3, $endpoint->get(5)->items); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Backstory/BackstoryEndpoint.php: -------------------------------------------------------------------------------- 1 | api); 19 | } 20 | 21 | public function questions() { 22 | return new QuestionEndpoint($this->api); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Achievement/DailyTomorrowEndpoint.php: -------------------------------------------------------------------------------- 1 | request()->json(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Stubs/PaginatedEndpointStub.php: -------------------------------------------------------------------------------- 1 | maxPageSize = $maxPageSize; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pet/PetEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->characters('test')->inventoryOf('char'); 10 | 11 | $this->assertEndpointIsAuthenticated( $endpoint ); 12 | $this->assertEndpointUrl( 'v2/characters/char/inventory', $endpoint ); 13 | 14 | $this->mockResponse('{"bags":[{"id":8941,"size":4,"inventory":[null,{"id":32134,"count":1},null,null]},null]}'); 15 | $this->assertEquals(32134, $endpoint->get()[0]->inventory[1]->id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/V2/Endpoint/WvW/ObjectiveEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->professions(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/professions', $endpoint ); 10 | 11 | $this->mockResponse('["Guardian","Warrior","Engineer","Ranger","Thief","Elementalist","Mesmer","Necromancer","Revenant"]'); 12 | $this->assertEquals( ["Guardian","Warrior","Engineer","Ranger","Thief","Elementalist","Mesmer","Necromancer","Revenant"], $endpoint->ids() ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/V2/Bulk/IBulkEndpoint.php: -------------------------------------------------------------------------------- 1 | request()->json(); 14 | } 15 | 16 | public function testMany( $count = 2 ) { 17 | $requests = array_fill( 0, $count, [] ); 18 | $responses = $this->requestMany( $requests ); 19 | 20 | $result = []; 21 | foreach( $responses as $response ) { 22 | $result = array_merge( $result, $response->json() ); 23 | } 24 | 25 | return $result; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/UpgradeEndpoint.php: -------------------------------------------------------------------------------- 1 | request([ 'input' => $id ])->json(); 22 | } 23 | 24 | /** 25 | * @param int $id 26 | * @return int[] 27 | */ 28 | public function output( $id ) { 29 | return $this->request([ 'output' => $id ])->json(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Skill/SkillEndpoint.php: -------------------------------------------------------------------------------- 1 | request(['world' => $id])->json(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V2/Endpoint/WvW/StatEndpoint.php: -------------------------------------------------------------------------------- 1 | request(['world' => $id])->json(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Stubs/BulkEndpointStub.php: -------------------------------------------------------------------------------- 1 | supportsIdsAll = $supportsIdsAll; 20 | $this->maxPageSize = $maxPageSize; 21 | 22 | parent::__construct( $api ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Recipe/RecipeEndpoint.php: -------------------------------------------------------------------------------- 1 | getApi() ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V2/Endpoint/WvW/OverviewEndpoint.php: -------------------------------------------------------------------------------- 1 | request(['world' => $id])->json(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V2/Localization/LocalizedEndpoint.php: -------------------------------------------------------------------------------- 1 | language = $lang; 21 | return $this; 22 | } 23 | 24 | /** 25 | * Get the current language. 26 | * 27 | * @return string 28 | */ 29 | public function getLang() { 30 | return $this->language; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Mount/MountEndpoint.php: -------------------------------------------------------------------------------- 1 | api ); 21 | } 22 | 23 | public function skins() { 24 | return new SkinEndpoint( $this->api ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/V2/Authentication/Exception/InvalidPermissionsException.php: -------------------------------------------------------------------------------- 1 | missingScope = $missingScope; 13 | 14 | parent::__construct( $message, $response ); 15 | } 16 | 17 | /** 18 | * Get the scope that was missing. 19 | * 20 | * @return string 21 | */ 22 | public function getMissingScope() { 23 | return $this->missingScope; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/SeasonEndpoint.php: -------------------------------------------------------------------------------- 1 | api, $season); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Race/RaceEndpoint.php: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./src 15 | 16 | 17 | 18 | 19 | ./tests/ 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/V2/TokeninfoEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->tokeninfo('api_key'); 6 | 7 | $this->assertEndpointIsAuthenticated( $endpoint ); 8 | $this->assertEndpointUrl( 'v2/tokeninfo', $endpoint ); 9 | 10 | $this->mockResponse('{ 11 | "id": "017A2B0C-A6C5-CC4D-A055-680F427CE8FD", 12 | "name": "public key", 13 | "permissions": [ 14 | "account", 15 | "characters" 16 | ] 17 | }'); 18 | $tokeninfo = $endpoint->get(); 19 | $this->assertEquals( 'public key', $tokeninfo->name ); 20 | $this->assertContainsEquals( 'characters', $tokeninfo->permissions ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Profession/ProfessionEndpoint.php: -------------------------------------------------------------------------------- 1 | api); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Emblem/EmblemEndpoint.php: -------------------------------------------------------------------------------- 1 | api, LayerEndpoint::TYPE_BACKGROUNDS); 23 | } 24 | 25 | /** 26 | * Get foregrounds layers. 27 | * 28 | * @return LayerEndpoint 29 | */ 30 | public function foregrounds() { 31 | return new LayerEndpoint($this->api, LayerEndpoint::TYPE_FOREGROUNDS); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Specialization/SpecializationEndpoint.php: -------------------------------------------------------------------------------- 1 | getEndpoint()->getSchema(); 24 | 25 | return $request->withHeader( 'X-Schema-Version', $schema ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/DyeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/dyes'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Achievement/DailyEndpoint.php: -------------------------------------------------------------------------------- 1 | request()->json(); 24 | } 25 | 26 | /** 27 | * Get tomorrows daily achievements. 28 | * 29 | * @return DailyTomorrowEndpoint 30 | */ 31 | public function tomorrow() { 32 | return new DailyTomorrowEndpoint($this->api); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Pagination/IPaginatedEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/bank'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/MiniEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/minis'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/RaidEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/raids'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/SkinEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/skins'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/TitleEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/titles'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/GliderEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/gliders'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/OutfitEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/outfits'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/RecipeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/recipes'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/WalletEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/wallet'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/DungeonEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/dungeons'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/FinisherEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/finishers'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Home/CatEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/home/cats'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/MapchestEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/mapchests'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/MasteryEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/masteries'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/MaterialEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/materials'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/NoveltyEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/novelties'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Pvp/HeroEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/pvp/heroes'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/WvW/WvWEndpoint.php: -------------------------------------------------------------------------------- 1 | api ); 17 | } 18 | 19 | public function matches() { 20 | return new MatchEndpoint( $this->api ); 21 | } 22 | 23 | public function objectives() { 24 | return new ObjectiveEndpoint( $this->api ); 25 | } 26 | 27 | public function ranks() { 28 | return new RankEndpoint( $this->api ); 29 | } 30 | 31 | public function upgrades() { 32 | return new UpgradeEndpoint( $this->api ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Home/NodeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/home/nodes'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/InventoryEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/inventory'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/MailcarrierEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/mailcarriers'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Mount/SkinEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/mounts/skins'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Mount/TypeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/mounts/types'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/DailyCraftingEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/dailycrafting'; 24 | } 25 | 26 | public function get() { 27 | return $this->request()->json(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/V2/IEndpoint.php: -------------------------------------------------------------------------------- 1 | api()->characters('test')->equipmentOf('char'); 10 | 11 | $this->assertEndpointIsAuthenticated( $endpoint ); 12 | $this->assertEndpointUrl( 'v2/characters/char/equipment', $endpoint ); 13 | 14 | $this->mockResponse('{"equipment":[{"id":6472,"slot":"Coat"},{"id":6470,"slot":"Boots"}]}'); 15 | $this->assertEquals(6472, $endpoint->get()[0]->id); 16 | } 17 | 18 | public function testCharacterNameEncoding() { 19 | $endpoint = $this->api()->characters('test')->equipmentOf('Character Namè'); 20 | 21 | $this->assertEndpointUrl( 'v2/characters/Character%20Nam%C3%A8/equipment', $endpoint ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/LuckEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function url() { 23 | return 'v2/account/luck'; 24 | } 25 | 26 | public function get() { 27 | $result = $this->request()->json(); 28 | return (isset($result[0]) ? $result[0]->value : false); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Pvp/PvpEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * The url of this endpoint. 21 | * 22 | * @return string 23 | */ 24 | public function url() { 25 | return 'v2/account/pvp'; 26 | } 27 | 28 | public function heroes() { 29 | return new HeroEndpoint($this->api, $this->apiKey); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Exception/ApiException.php: -------------------------------------------------------------------------------- 1 | response = $response; 14 | 15 | parent::__construct( $message, $response->getStatusCode() ); 16 | } 17 | 18 | /** 19 | * @return ResponseInterface 20 | */ 21 | public function getResponse() { 22 | return $this->response; 23 | } 24 | 25 | public function __toString() { 26 | $status = $this->response->getStatusCode(); 27 | $url = $this->response->getHeaderLine('X-GUZZLE-EFFECTIVE-URL'); 28 | 29 | return "$this->message (status: $status; url: $url)"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/V2/CharacterSpecializationEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->characters('test')->specializationsOf('char'); 10 | 11 | $this->assertEndpointIsAuthenticated( $endpoint ); 12 | $this->assertEndpointUrl( 'v2/characters/char/specializations', $endpoint ); 13 | 14 | $this->mockResponse('{"specializations":{"pve":[{"id":41,"traits":[232,214,226]}]}}'); 15 | $this->assertEquals(41, $endpoint->get()->pve[0]->id); 16 | } 17 | 18 | public function testCharacterNameEncoding() { 19 | $endpoint = $this->api()->characters('test')->specializationsOf('Character Namè'); 20 | 21 | $this->assertEndpointUrl( 'v2/characters/Character%20Nam%C3%A8/specializations', $endpoint ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/V2/ApiResponse.php: -------------------------------------------------------------------------------- 1 | response = $response; 13 | } 14 | 15 | /** 16 | * Get the response. 17 | * 18 | * @return ResponseInterface 19 | */ 20 | public function getResponse() { 21 | return $this->response; 22 | } 23 | 24 | /** 25 | * Get the response as json object. 26 | * 27 | * @param array $config 28 | * @return mixed 29 | */ 30 | public function json( array $config = [] ) { 31 | $options = isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0; 32 | return json_decode($this->response->getBody(), false, 512, $options); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/ContinentEndpoint.php: -------------------------------------------------------------------------------- 1 | getApi(), $continent ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/EndpointTest.php: -------------------------------------------------------------------------------- 1 | api() ); 8 | } 9 | 10 | public function testToString() { 11 | $endpoint = $this->getEndpoint(); 12 | 13 | $string = $endpoint->__toString(); 14 | 15 | $this->assertNotFalse( strstr( $string, 'EndpointStub' ), 16 | 'Endpoint::toString() should contain class name'); 17 | 18 | $this->assertNotFalse( strstr( $string, $endpoint->url() ), 19 | 'Endpoint::toString() should contain endpoint url'); 20 | 21 | $this->mockResponse('{}'); 22 | $endpoint->test(); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertNotNull( $request ); 26 | $this->assertEquals( 'https://api.guildwars2.com/' . $endpoint->url(), $request->getUri() ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function url() { 24 | return 'v2/tokeninfo'; 25 | } 26 | 27 | /** 28 | * Get info about the used api key. 29 | * 30 | * @return mixed 31 | */ 32 | public function get() { 33 | return $this->request()->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/ExchangeEndpoint.php: -------------------------------------------------------------------------------- 1 | request([ 'quantity' => $quantity ], $this->url() . '/gems' )->json(); 24 | } 25 | 26 | /** 27 | * Current coins to gems exchange rate. 28 | * 29 | * @param int $quantity coins 30 | * @return mixed 31 | */ 32 | public function coins( $quantity ) { 33 | return $this->request([ 'quantity' => $quantity ], $this->url() . '/coins' )->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/V2/MapEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->maps(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/maps', $endpoint ); 10 | 11 | $this->mockResponse('{ 12 | "id": 15, 13 | "name": "Queensdale", 14 | "min_level": 1, 15 | "max_level": 15, 16 | "default_floor": 1, 17 | "floors": [0,1,2], 18 | "region_id": 4, 19 | "region_name": "Kryta", 20 | "continent_id": 1, 21 | "continent_name": "Tyria", 22 | "map_rect": [[-43008,-27648],[43008,30720]], 23 | "continent_rect": [[9856,11648],[13440,14080]] 24 | }'); 25 | $this->assertEquals( 'Queensdale', $endpoint->get(15)->name ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/GameEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | 22 | parent::__construct($api); 23 | } 24 | 25 | /** 26 | * The url of this endpoint. 27 | * 28 | * @return string 29 | */ 30 | public function url() { 31 | return 'v2/pvp/games'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Home/HomeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * The url of this endpoint. 21 | * 22 | * @return string 23 | */ 24 | public function url() { 25 | return 'v2/account/home'; 26 | } 27 | 28 | public function cats() { 29 | return new CatEndpoint($this->api, $this->apiKey); 30 | } 31 | public function nodes() { 32 | return new NodeEndpoint($this->api, $this->apiKey); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/CoreEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/core'; 27 | } 28 | 29 | /** 30 | * @return mixed 31 | */ 32 | public function get() { 33 | return $this->request()->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/SabEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/sab'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/QuestEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/quests'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/V2/HomeEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->home(); 6 | 7 | $this->assertEndpointUrl( 'v2/home', $endpoint ); 8 | } 9 | 10 | public function testHomeCats() { 11 | $endpoint = $this->api()->home()->cats(); 12 | 13 | $this->assertEndpointIsBulk( $endpoint ); 14 | $this->assertEndpointUrl( 'v2/home/cats', $endpoint ); 15 | 16 | $this->mockResponse('{"hint":"chicken","id":1}'); 17 | $this->assertEquals('chicken', $endpoint->get(1)->hint); 18 | } 19 | 20 | public function testHomeNodes() { 21 | $endpoint = $this->api()->home()->nodes(); 22 | 23 | $this->assertEndpointIsBulk( $endpoint ); 24 | $this->assertEndpointUrl( 'v2/home/nodes', $endpoint ); 25 | 26 | $this->mockResponse('{"id":"advanced_cloth_rack"}'); 27 | $this->assertEquals('advanced_cloth_rack', $endpoint->get('advanced_cloth_rack')->id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gw2treasures/gw2api", 3 | "type": "library", 4 | "description": "PHP wrapper for the Guild Wars 2 API.", 5 | "keywords": ["guildwars2","guild wars 2","api","wrapper"], 6 | "homepage": "https://github.com/GW2Treasures/gw2api", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "darthmaim", 11 | "email": "darth.maim@arcor.de" 12 | } 13 | ], 14 | "support": { 15 | "issues": "https://github.com/GW2Treasures/gw2api/issues", 16 | "source": "https://github.com/GW2Treasures/gw2api" 17 | }, 18 | "require": { 19 | "php": ">=7.2.5", 20 | "guzzlehttp/guzzle": "^7.0" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "^8.0 || ^9.0", 24 | "mtdowling/burgomaster": "^0.0.2" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "GW2Treasures\\GW2Api\\": "src" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "classmap": [ "tests/" ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/Mount/MountEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * The url of this endpoint. 21 | * 22 | * @return string 23 | */ 24 | public function url() { 25 | return 'v2/account/mounts'; 26 | } 27 | 28 | public function skins() { 29 | return new SkinEndpoint( $this->api, $this->apiKey ); 30 | } 31 | 32 | public function types() { 33 | return new TypeEndpoint( $this->api, $this->apiKey ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/HeropointEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/heropoints'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/RecipeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/recipes'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->recipes; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/SkillEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/skills'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->skills; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/WvW/MatchEndpoint.php: -------------------------------------------------------------------------------- 1 | request(['world' => $id])->json(); 27 | } 28 | 29 | public function overview() { 30 | return new OverviewEndpoint($this->api); 31 | } 32 | 33 | public function scores() { 34 | return new ScoreEndpoint($this->api); 35 | } 36 | 37 | public function stats() { 38 | return new StatEndpoint($this->api); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/InventoryEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/inventory'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->bags; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/BackstoryEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/backstory'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->backstory; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/CraftingEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/crafting'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->crafting; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/EquipmentEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/equipment'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->equipment; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/TrainingEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/training'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function get() { 33 | return $this->request()->json()->training; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/StatsEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | 20 | parent::__construct($api); 21 | } 22 | 23 | /** 24 | * The url of this endpoint. 25 | * 26 | * @return string 27 | */ 28 | public function url() { 29 | return 'v2/pvp/stats'; 30 | } 31 | 32 | /** 33 | * Get pvp stats. 34 | * 35 | * @return mixed 36 | */ 37 | public function get() { 38 | return $this->request()->json(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Character/SpecializationEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | $this->character = $character; 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function url() { 26 | return 'v2/characters/' . rawurlencode( $this->character ) . '/specializations'; 27 | } 28 | 29 | /** 30 | * @return mixed 31 | */ 32 | public function get() { 33 | return $this->request()->json()->specializations; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/StandingEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 19 | 20 | parent::__construct($api); 21 | } 22 | 23 | /** 24 | * The url of this endpoint. 25 | * 26 | * @return string 27 | */ 28 | public function url() { 29 | return 'v2/pvp/standings'; 30 | } 31 | 32 | /** 33 | * Get your standing pvp info. 34 | * 35 | * @return mixed 36 | */ 37 | public function get() { 38 | return $this->request()->json(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/V2/StoryEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->stories(); 6 | 7 | $this->assertEndpointIsBulk($endpoint); 8 | $this->assertEndpointIsLocalized($endpoint); 9 | $this->assertEndpointUrl('v2/stories', $endpoint); 10 | 11 | $this->mockResponse('{"id":1,"season":"215AAA0F-CDAC-4F93-86DA-C155A99B5784","name":"My Story"}'); 12 | $this->assertEquals('My Story', $endpoint->get(1)->name); 13 | } 14 | 15 | public function testSeasons() { 16 | $endpoint = $this->api()->stories()->seasons(); 17 | 18 | $this->assertEndpointIsBulk($endpoint); 19 | $this->assertEndpointIsLocalized($endpoint); 20 | $this->assertEndpointUrl('v2/stories/seasons', $endpoint); 21 | 22 | $this->mockResponse('{"id":"B8901E58-DC9D-4525-ADB2-79C93593291E","name":"Heart of Thorns"}'); 23 | $this->assertEquals('Heart of Thorns', $endpoint->get('B8901E58-DC9D-4525-ADB2-79C93593291E')->name); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/LeaderboardEndpoint.php: -------------------------------------------------------------------------------- 1 | season = $season; 19 | } 20 | 21 | /** 22 | * The url of this endpoint. 23 | * 24 | * @return string 25 | */ 26 | public function url() { 27 | return 'v2/pvp/seasons/'.$this->season.'/leaderboards'; 28 | } 29 | 30 | /** 31 | * Get a list of available leaderboards. 32 | * 33 | * @return string[] 34 | */ 35 | public function ids() { 36 | return $this->request()->json(); 37 | } 38 | 39 | public function get($leaderboard, $region) { 40 | return new LeaderboardRegionEndpoint($this->api, $this->season, $leaderboard, $region); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Stubs/GW2ApiStub.php: -------------------------------------------------------------------------------- 1 | isIncludedInPhar = $isIncludedInPhar; 13 | 14 | parent::__construct($options); 15 | } 16 | 17 | /** 18 | * Checks if the library is included as phar file. 19 | * 20 | * @return bool 21 | */ 22 | public function isIncludedAsPhar() { 23 | return $this->isIncludedInPhar; 24 | } 25 | 26 | /** 27 | * Returns the path to cacert.pem. 28 | * 29 | * @return string 30 | */ 31 | public function getCacertFilePath() { 32 | return parent::getCacertFilePath(); 33 | } 34 | 35 | /** 36 | * Copies the phar cacert from the phar into the temp directory. 37 | */ 38 | public function extractCacertFile() { 39 | parent::extractCacertFile(); 40 | } 41 | 42 | public function getRealOptions() { 43 | return $this->options; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 gw2treasures.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /tests/V2/BackstoryEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->backstory(); 6 | 7 | $this->assertEndpointUrl('v2/backstory', $endpoint); 8 | } 9 | 10 | public function testQuestions() { 11 | $endpoint = $this->api()->backstory()->questions(); 12 | 13 | $this->assertEndpointIsBulk($endpoint); 14 | $this->assertEndpointIsLocalized($endpoint); 15 | $this->assertEndpointUrl('v2/backstory/questions', $endpoint); 16 | 17 | $this->mockResponse('[1,2,3,4,5,6,8,12,13]'); 18 | $this->assertEquals([1,2,3,4,5,6,8,12,13], $endpoint->ids()); 19 | } 20 | 21 | public function testAnswers() { 22 | $endpoint = $this->api()->backstory()->answers(); 23 | 24 | $this->assertEndpointIsBulk($endpoint); 25 | $this->assertEndpointIsLocalized($endpoint); 26 | $this->assertEndpointUrl('v2/backstory/answers', $endpoint); 27 | 28 | $this->mockResponse('["7-54","188-189","22-109","15-84"]'); 29 | $this->assertEquals(["7-54","188-189","22-109","15-84"], $endpoint->ids()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/RankEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/ranks'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/StashEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/stash'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/TeamEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/teams'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/EndpointTrait.php: -------------------------------------------------------------------------------- 1 | getResponseAsJson( $response ); 28 | if( !is_null( $json ) && isset( $json->text )) { 29 | if( strpos( $json->text, 'page out of range.' ) === 0 ) { 30 | throw new PageOutOfRangeException( $json->text, $response ); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/MemberEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/members'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/TreasuryEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/treasury'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/UpgradeEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/upgrades'; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function get() { 37 | return $this->request()->json(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/DetailsEndpoint.php: -------------------------------------------------------------------------------- 1 | guildId = $guildId; 27 | $this->apiKey = $apiKey; 28 | } 29 | 30 | /** 31 | * The url of this endpoint. 32 | * 33 | * @return string 34 | */ 35 | public function url() { 36 | return 'v2/guild/'.$this->guildId; 37 | } 38 | 39 | /** 40 | * Get the guild details. 41 | * 42 | * @return mixed 43 | */ 44 | public function get() { 45 | return $this->request()->json(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/Transaction/TransactionEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 17 | } 18 | 19 | /** 20 | * {@inheritdoc} 21 | * @codeCoverageIgnore 22 | */ 23 | public function url() { 24 | return 'v2/commerce/transactions'; 25 | } 26 | 27 | /** 28 | * Get current transactions. 29 | * 30 | * @return TypeEndpoint 31 | */ 32 | public function current() { 33 | return new TypeEndpoint( $this->getApi(), $this->apiKey, 'current' ); 34 | } 35 | 36 | /** 37 | * Get transaction history. 38 | * 39 | * @return TypeEndpoint 40 | */ 41 | public function history() { 42 | return new TypeEndpoint( $this->getApi(), $this->apiKey, 'history' ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | dist: trusty 3 | 4 | php: 5 | - 5.5 6 | - 5.6 7 | - 7.0 8 | - 7.1 9 | - 7.2 10 | - 7.3 11 | - 7.4 12 | 13 | env: 14 | global: 15 | - setup=basic 16 | 17 | matrix: 18 | include: 19 | - php: 5.5 20 | env: setup=lowest 21 | - php: 5.5 22 | env: setup=stable 23 | - php: 5.6 24 | env: setup=phar 25 | 26 | install: 27 | - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-source; fi 28 | - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi 29 | - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi 30 | - if [[ $setup = 'phar' ]]; then travis_retry composer install --no-interaction --prefer-source; fi 31 | 32 | before_script: 33 | - phpenv config-rm xdebug.ini 34 | - if [[ $setup = 'phar' ]]; then php build/build.php; fi 35 | 36 | script: 37 | - if [[ $setup != 'phar' ]]; then vendor/bin/phpunit --configuration phpunit.xml --coverage-clover clover.xml; fi 38 | - if [[ $setup = 'phar' ]]; then vendor/bin/phpunit --configuration phpunit.xml --bootstrap build/autoload.php; fi 39 | 40 | after_script: 41 | - bash <(curl -s https://codecov.io/bash) 42 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php: -------------------------------------------------------------------------------- 1 | season = $season; 32 | $this->leaderboard = $leaderboard; 33 | $this->region = $region; 34 | } 35 | 36 | 37 | /** 38 | * The url of this endpoint. 39 | * 40 | * @return string 41 | */ 42 | public function url() { 43 | return 'v2/pvp/seasons/'.$this->season.'/leaderboards/'.$this->leaderboard.'/'.$this->region; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/FloorEndpoint.php: -------------------------------------------------------------------------------- 1 | continent = $continent; 24 | 25 | parent::__construct( $api ); 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function url() { 32 | return 'v2/continents/'.$this->continent.'/floors'; 33 | } 34 | 35 | /** 36 | * Get the floors regions. 37 | * 38 | * @param int $floor 39 | * 40 | * @return RegionEndpoint 41 | */ 42 | public function regionsOf( $floor ) { 43 | return new RegionEndpoint( $this->api, $this->continent, $floor ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/V2/RecipeEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->recipes(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointUrl( 'v2/recipes', $endpoint ); 9 | 10 | $this->mockResponse( '[1,2,3,4,5,6,7,8,9,10]' ); 11 | $this->assertEquals( [1,2,3,4,5,6,7,8,9,10], $endpoint->ids() ); 12 | } 13 | 14 | public function testSearchInput() { 15 | $endpoint = $this->api()->recipes()->search(); 16 | 17 | $this->assertEndpointUrl( 'v2/recipes/search', $endpoint ); 18 | 19 | $this->mockResponse( '[7259,7260,7261,7262,7263,7264,7265,7266,7267,7268,7269,7270,7271,7272,7273,7274,7275]' ); 20 | $this->assertContainsEquals( 7267, $endpoint->input(43775) ); 21 | $this->assertEquals('input=43775', $this->getLastRequest()->getUri()->getQuery()); 22 | } 23 | 24 | public function testSearchOutput() { 25 | $endpoint = $this->api()->recipes()->search(); 26 | 27 | $this->assertEndpointUrl( 'v2/recipes/search', $endpoint ); 28 | 29 | $this->mockResponse( '[7237]' ); 30 | $this->assertEquals( [7237], $endpoint->output(43775) ); 31 | $this->assertEquals('output=43775', $this->getLastRequest()->getUri()->getQuery()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Emblem/LayerEndpoint.php: -------------------------------------------------------------------------------- 1 | type = $type; 39 | } 40 | 41 | /** 42 | * {@inheritdoc} 43 | */ 44 | public function url() { 45 | return 'v2/emblem/'.$this->type; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/CommerceEndpoint.php: -------------------------------------------------------------------------------- 1 | getApi() ); 25 | } 26 | 27 | /** 28 | * Current trading post listings. 29 | * 30 | * @return ListingEndpoint 31 | */ 32 | public function listings() { 33 | return new ListingEndpoint( $this->getApi() ); 34 | } 35 | 36 | /** 37 | * Current trading post prices. 38 | * 39 | * @return PriceEndpoint 40 | */ 41 | public function prices() { 42 | return new PriceEndpoint( $this->getApi() ); 43 | } 44 | 45 | /** 46 | * Current and completed transactions. 47 | * 48 | * @param string $apiKey 49 | * @return TransactionEndpoint 50 | */ 51 | public function transactions( $apiKey ) { 52 | return new TransactionEndpoint( $this->getApi(), $apiKey ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/V2/MountEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->mounts(); 6 | 7 | $this->assertEndpointUrl( 'v2/mounts', $endpoint ); 8 | } 9 | 10 | public function testMountTypes() { 11 | $endpoint = $this->api()->mounts()->types(); 12 | 13 | $this->assertEndpointIsBulk( $endpoint ); 14 | $this->assertEndpointIsLocalized( $endpoint ); 15 | $this->assertEndpointUrl( 'v2/mounts/types', $endpoint ); 16 | 17 | $this->mockResponse('{"id":"raptor","name":"Raptor","default_skin":1,"skins":[21,24,1,29,81,13,32,99,94,58,35,86,17,88,76,48],"skills":[{"id":40409,"slot":"Weapon_1"}]}'); 18 | $this->assertEquals('Raptor', $endpoint->get('raptor')->name); 19 | } 20 | 21 | public function testMountSkins() { 22 | $endpoint = $this->api()->mounts()->skins(); 23 | 24 | $this->assertEndpointIsBulk( $endpoint ); 25 | $this->assertEndpointIsLocalized( $endpoint ); 26 | $this->assertEndpointUrl( 'v2/mounts/skins', $endpoint ); 27 | 28 | $this->mockResponse('{"id":1,"name":"Raptor","icon":"https://render.guildwars2.com/file/2F4AAA52F573C5425BFCD7525FB70C9E6DCAD791/1766903.png","mount":"raptor","dye_slots":[{"color_id":19,"material":"leather"}]}'); 29 | $this->assertEquals('Raptor', $endpoint->get(1)->name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/V2/Localization/Exception/InvalidLanguageException.php: -------------------------------------------------------------------------------- 1 | requestLanguage = $requestLanguage; 24 | $this->responseLanguage = $responseLanguage; 25 | 26 | parent::__construct( $message, $response ); 27 | } 28 | 29 | /** 30 | * Get the requested language. 31 | * 32 | * @return string 33 | */ 34 | public function getRequestLanguage() { 35 | return $this->requestLanguage; 36 | } 37 | 38 | /** 39 | * Get the language the api responded with. 40 | * 41 | * @return string 42 | */ 43 | public function getResponseLanguage() { 44 | return $this->responseLanguage; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Achievement/AchievementEndpoint.php: -------------------------------------------------------------------------------- 1 | api); 33 | } 34 | 35 | /** 36 | * Get daily achievements. 37 | * 38 | * @return DailyEndpoint 39 | */ 40 | public function daily() { 41 | return new DailyEndpoint($this->api); 42 | } 43 | 44 | /** 45 | * Get achievement groups. 46 | * 47 | * @return GroupEndpoint 48 | */ 49 | public function groups() { 50 | return new GroupEndpoint($this->api); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/V2/EmblemEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->emblem(); 8 | 9 | $this->assertEndpointUrl('v2/emblem', $endpoint); 10 | 11 | $this->assertInstanceOf(LayerEndpoint::class, $endpoint->backgrounds()); 12 | $this->assertInstanceOf(LayerEndpoint::class, $endpoint->foregrounds()); 13 | } 14 | 15 | public function testForeground() { 16 | $endpoint = $this->api()->emblem()->foregrounds(); 17 | 18 | $this->assertEndpointUrl('v2/emblem/foregrounds', $endpoint); 19 | $this->assertEndpointIsBulk($endpoint); 20 | 21 | $this->mockResponse('{"id": 1,"layers":["1.png","2.png","3.png"]}'); 22 | 23 | $this->assertEquals(1, $endpoint->get(1)->id); 24 | } 25 | 26 | public function testTypes() { 27 | $backgrounds = $this->api()->emblem()->backgrounds(); 28 | $foregrounds = $this->api()->emblem()->foregrounds(); 29 | 30 | $this->assertEndpointUrl('v2/emblem/backgrounds', $backgrounds); 31 | $this->assertEndpointUrl('v2/emblem/foregrounds', $foregrounds); 32 | } 33 | 34 | /** */ 35 | public function testInvalidLayerType() { 36 | $this->expectException(\InvalidArgumentException::class); 37 | 38 | new LayerEndpoint($this->api(), 'invalid'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/Authenticated/LogEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 21 | $this->guildId = $guildId; 22 | } 23 | 24 | /** 25 | * The url of this endpoint. 26 | * 27 | * @return string 28 | */ 29 | public function url() { 30 | return 'v2/guild/'.$this->guildId.'/log'; 31 | } 32 | 33 | /** 34 | * Get log entries. 35 | * 36 | * @return array 37 | */ 38 | public function get() { 39 | return $this->request()->json(); 40 | } 41 | 42 | /** 43 | * Get log entries newer than `$lastId`. 44 | * 45 | * @param int $lastId 46 | * @return array 47 | */ 48 | public function since($lastId) { 49 | return $this->request(['since' => $lastId])->json(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/RegionEndpoint.php: -------------------------------------------------------------------------------- 1 | continent = $continent; 28 | $this->floor = $floor; 29 | 30 | parent::__construct( $api ); 31 | } 32 | 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | public function url() { 37 | return 'v2/continents/'.$this->continent.'/floors/'.$this->floor.'/regions'; 38 | } 39 | 40 | /** 41 | * Get the regions maps. 42 | * 43 | * @param int $region 44 | * 45 | * @return MapEndpoint 46 | */ 47 | public function mapsOf( $region ) { 48 | return new MapEndpoint( $this->api, $this->continent, $this->floor, $region ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Guild/RestrictedGuildHandler.php: -------------------------------------------------------------------------------- 1 | getResponseAsJson( $response ); 30 | if( !is_null( $json ) && isset( $json->text )) { 31 | if( $json->text === 'access restricted to guild leaders' ) { 32 | throw new GuildLeaderRequiredException( $json->text, $response ); 33 | } elseif( $json->text === 'membership required' ) { 34 | throw new MembershipRequiredException( $json->text, $response ); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/TaskEndpoint.php: -------------------------------------------------------------------------------- 1 | continent = $continent; 36 | $this->floor = $floor; 37 | $this->region = $region; 38 | $this->map = $map; 39 | 40 | parent::__construct( $api ); 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public function url() { 47 | return 'v2/continents/'.$this->continent.'/floors/'.$this->floor.'/regions/'.$this->region.'/maps/'.$this->map.'/tasks'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/PoiEndpoint.php: -------------------------------------------------------------------------------- 1 | continent_id = $continent; 36 | $this->floor = $floor; 37 | $this->region = $region; 38 | $this->map = $map; 39 | 40 | parent::__construct( $api ); 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public function url() { 47 | return 'v2/continents/'.$this->continent_id.'/floors/'.$this->floor.'/regions/'.$this->region.'/maps/'.$this->map.'/pois'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/SectorEndpoint.php: -------------------------------------------------------------------------------- 1 | continent = $continent; 36 | $this->floor = $floor; 37 | $this->region = $region; 38 | $this->map = $map; 39 | 40 | parent::__construct( $api ); 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public function url() { 47 | return 'v2/continents/'.$this->continent.'/floors/'.$this->floor.'/regions/'.$this->region.'/maps/'.$this->map.'/sectors'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/GW2ApiTest.php: -------------------------------------------------------------------------------- 1 | assertTrue( $api->isIncludedAsPhar(), 'should simulate being included as phar' ); 8 | 9 | $path = $api->getCacertFilePath(); 10 | $sourcePath = __DIR__ . '/../src/cacert.pem'; 11 | 12 | $this->assertStringStartsWith( sys_get_temp_dir(), $path, 13 | 'file path of cacert should be in temp directory'); 14 | 15 | // delete extracted cacert if it exists 16 | if( file_exists( $path )) { 17 | unlink( $path ); 18 | } 19 | 20 | $this->assertFileNotExists( $path, 'extracted cacert file should not exist before extracting' ); 21 | 22 | $api->extractCacertFile(); 23 | 24 | $this->assertFileExists( $path, 'extracted cacert file should exist after extracting' ); 25 | $this->assertFileEquals( $sourcePath, $path, 'extracted cacert file should match source cacert file' ); 26 | } 27 | 28 | public function testOverrideOptions() { 29 | $api1 = new \Stubs\GW2ApiStub(false, []); 30 | $options1 = $api1->getRealOptions(); 31 | $this->assertEquals($options1['base_uri'], 'https://api.guildwars2.com/'); 32 | 33 | $testBaseUrl = 'http://localhost:8080/'; 34 | $api2 = new \Stubs\GW2ApiStub(false, ['base_uri' => $testBaseUrl]); 35 | $options2 = $api2->getRealOptions(); 36 | $this->assertEquals($options2['base_uri'], $testBaseUrl); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Account/AchievementEndpoint.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 24 | } 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | public function url() { 30 | return 'v2/account/achievements'; 31 | } 32 | 33 | public function get($id = null) { 34 | if($id == null) { 35 | return $this->all(); 36 | } else { 37 | return $this->bulkGet($id); 38 | } 39 | } 40 | 41 | /** 42 | * This endpoint doesn't support ids()! 43 | * 44 | * @deprecated This endpoint doesn't support ids()! 45 | * @throws Exception 46 | * @return void 47 | */ 48 | public function ids() { 49 | throw new Exception($this->url()." doesn't support ids()."); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/V2/Localization/LocalizationHandler.php: -------------------------------------------------------------------------------- 1 | getUri(), 'lang', $this->getEndpoint()->getLang() ); 28 | return $request->withUri($localizedUri); 29 | } 30 | 31 | public function onResponse( ResponseInterface $response, RequestInterface $request ) { 32 | $query = $this->getQueryAsArray($request); 33 | $languageHeader = $response->getHeader( 'Content-Language' ); 34 | 35 | $requestLanguage = isset($query['lang']) ? $query['lang'] : null; 36 | $responseLanguage = array_shift($languageHeader); 37 | 38 | if( $requestLanguage !== $responseLanguage) { 39 | $message = 'Invalid language (expected: ' . $requestLanguage . '; actual: ' . $responseLanguage . ')'; 40 | throw new InvalidLanguageException( $message, $requestLanguage, $responseLanguage, $response ); 41 | } 42 | 43 | return $response; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/Transaction/TypeEndpoint.php: -------------------------------------------------------------------------------- 1 | type = $type; 27 | $this->apiKey = $apiKey; 28 | 29 | parent::__construct( $api ); 30 | } 31 | 32 | 33 | /** 34 | * {@inheritdoc} 35 | * @codeCoverageIgnore 36 | */ 37 | public function url() { 38 | return 'v2/commerce/transactions/' . $this->type; 39 | } 40 | 41 | /** 42 | * Get pending/completed buy transactions. 43 | * 44 | * @return ListEndpoint 45 | */ 46 | public function buys() { 47 | return new ListEndpoint( $this->getApi(), $this->apiKey, $this->type, 'buys' ); 48 | } 49 | 50 | /** 51 | * Get pending/completed sell transactions. 52 | * 53 | * @return ListEndpoint 54 | */ 55 | public function sells() { 56 | return new ListEndpoint( $this->getApi(), $this->apiKey, $this->type, 'sells' ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Commerce/Transaction/ListEndpoint.php: -------------------------------------------------------------------------------- 1 | type = $type; 39 | $this->list = $list; 40 | $this->apiKey = $apiKey; 41 | 42 | parent::__construct( $api ); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function url() { 49 | return 'v2/commerce/transactions/' . $this->type . '/' . $this->list; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Pvp/PvpEndpoint.php: -------------------------------------------------------------------------------- 1 | api); 25 | } 26 | 27 | /** 28 | * @param string $apiKey 29 | * @return GameEndpoint 30 | */ 31 | public function games($apiKey) { 32 | return new GameEndpoint($this->api, $apiKey); 33 | } 34 | 35 | /** 36 | * @param string $apiKey 37 | * @return HeroEndpoint 38 | */ 39 | public function heroes($apiKey) { 40 | return new HeroEndpoint($this->api, $apiKey); 41 | } 42 | 43 | /** 44 | * @return RankEndpoint 45 | */ 46 | public function ranks() { 47 | return new RankEndpoint($this->api); 48 | } 49 | 50 | /** 51 | * @return SeasonEndpoint 52 | */ 53 | public function seasons() { 54 | return new SeasonEndpoint($this->api); 55 | } 56 | 57 | /** 58 | * @param string $apiKey 59 | * @return StandingEndpoint 60 | */ 61 | public function standings($apiKey) { 62 | return new StandingEndpoint($this->api, $apiKey); 63 | } 64 | 65 | /** 66 | * @param string $apiKey 67 | * @return StatsEndpoint 68 | */ 69 | public function stats($apiKey) { 70 | return new StatsEndpoint($this->api, $apiKey); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/SchemaTest.php: -------------------------------------------------------------------------------- 1 | api() ); 12 | } 13 | 14 | public function testDefaultSchema() { 15 | $this->mockResponse('[]'); 16 | 17 | $endpoint = $this->getEndpoint(); 18 | 19 | $this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); 20 | 21 | $endpoint->test(); 22 | 23 | $request = $this->getLastRequest(); 24 | $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_DEFAULT_SCHEMA); 25 | } 26 | 27 | public function testCustomSchema() { 28 | $this->mockResponse('[]'); 29 | 30 | $endpoint = $this->getEndpoint()->schema(EXPECTED_CUSTOM_SCHEMA); 31 | 32 | $this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); 33 | 34 | $endpoint->test(); 35 | 36 | $request = $this->getLastRequest(); 37 | $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); 38 | } 39 | 40 | public function testGlobalSchema() { 41 | $this->mockResponse('[]'); 42 | 43 | $endpoint = $this->getEndpoint(); 44 | $this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); 45 | 46 | $this->api()->schema(EXPECTED_CUSTOM_SCHEMA); 47 | 48 | $this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); 49 | 50 | $endpoint->test(); 51 | 52 | $request = $this->getLastRequest(); 53 | $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); 54 | 55 | // clean up schema for other tests 56 | $this->resetApi(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/V2/CommerceEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->commerce(); 6 | 7 | $this->assertEndpointUrl( 'v2/commerce', $endpoint ); 8 | } 9 | 10 | public function testExchangeCoins() { 11 | $endpoint = $this->api()->commerce()->exchange(); 12 | 13 | $this->assertEndpointUrl( 'v2/commerce/exchange', $endpoint ); 14 | 15 | $this->mockResponse( '{"coins_per_gem":2000,"quantity":5}' ); 16 | $this->assertEquals( 5, $endpoint->coins(10000)->quantity ); 17 | } 18 | 19 | public function testExchangeGems() { 20 | $endpoint = $this->api()->commerce()->exchange(); 21 | 22 | $this->assertEndpointUrl( 'v2/commerce/exchange', $endpoint ); 23 | 24 | $this->mockResponse( '{"coins_per_gem":1269,"quantity":63489}' ); 25 | $this->assertEquals( 1269, $endpoint->gems(50)->coins_per_gem ); 26 | } 27 | 28 | public function testListings() { 29 | $endpoint = $this->api()->commerce()->listings(); 30 | 31 | $this->assertEndpointIsBulk( $endpoint ); 32 | $this->assertEndpointUrl( 'v2/commerce/listings', $endpoint ); 33 | 34 | $this->mockResponse('{"id":24,"buys":[{"listings":1,"unit_price":110,"quantity":141}]}'); 35 | $this->assertEquals( 110, $endpoint->get(24)->buys[0]->unit_price ); 36 | } 37 | 38 | public function testPrices() { 39 | $endpoint = $this->api()->commerce()->prices(); 40 | 41 | $this->assertEndpointIsBulk( $endpoint ); 42 | $this->assertEndpointUrl( 'v2/commerce/prices', $endpoint ); 43 | 44 | $this->mockResponse('{"id":24,"buys":{"quantity":21362,"unit_price":110},"sells":{"quantity":15145,"unit_price":115}}'); 45 | $this->assertEquals( 15145, $endpoint->get(24)->sells->quantity ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/LocalizedEndpointTest.php: -------------------------------------------------------------------------------- 1 | api() ); 9 | } 10 | 11 | public function testBasic() { 12 | $this->mockResponse('[]'); 13 | 14 | $endpoint = $this->getLocalizedEndpoint(); 15 | 16 | $this->assertEndpointIsLocalized( $endpoint ); 17 | 18 | $endpoint->lang('en')->test(); 19 | 20 | $request = $this->getLastRequest(); 21 | $this->assertHasQuery( $request, 'lang', 'en' ); 22 | } 23 | 24 | public function testRepeated() { 25 | $this->mockResponse('[]', 'de'); 26 | $this->mockResponse('[]', 'de'); 27 | 28 | $endpoint_de = $this->getLocalizedEndpoint()->lang('de'); 29 | 30 | $this->assertEndpointIsLocalized( $endpoint_de ); 31 | 32 | $endpoint_de->test(); 33 | $endpoint_de->test(); 34 | 35 | $request = $this->getLastRequest(); 36 | 37 | $this->assertHasQuery( $request, 'lang', 'de' ); 38 | } 39 | 40 | public function testNested() { 41 | $this->mockResponse('[]', 'fr'); 42 | 43 | $this->getLocalizedEndpoint()->lang('es')->lang('fr')->test(); 44 | 45 | $request = $this->getLastRequest(); 46 | 47 | $this->assertHasQuery( $request, 'lang', 'fr' ); 48 | } 49 | 50 | public function testInvalidLanguage() { 51 | $this->mockResponse('[]', 'en'); 52 | 53 | try { 54 | $this->getLocalizedEndpoint()->lang('invalid')->test(); 55 | } catch( InvalidLanguageException $ex ) { 56 | $this->assertEquals( 'en', $ex->getResponseLanguage() ); 57 | $this->assertEquals( 'invalid', $ex->getRequestLanguage() ); 58 | 59 | $this->assertTrue( strstr( $ex->getMessage(), 'Invalid language' ) !== false ); 60 | 61 | return; 62 | } 63 | 64 | $this->fail(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/V2/Authentication/AuthenticationHandler.php: -------------------------------------------------------------------------------- 1 | getEndpoint()->getApiKey(); 29 | 30 | if($apiKey !== null) { 31 | $request = $request->withHeader( 'Authorization', 'Bearer '.$apiKey); 32 | } 33 | 34 | return $request; 35 | } 36 | 37 | /** 38 | * Handle invalid/wrong key and invalid permission scope errors. 39 | * 40 | * @param ResponseInterface $response 41 | * @param RequestInterface $request 42 | * 43 | * @throws AuthenticationException 44 | * @throws InvalidPermissionsException 45 | */ 46 | public function onError( ResponseInterface $response, RequestInterface $request ) { 47 | $json = $this->getResponseAsJson( $response ); 48 | if( !is_null( $json ) && isset( $json->text )) { 49 | if( $json->text === 'invalid key' || $json->text === 'endpoint requires authentication' ) { 50 | throw new AuthenticationException( $json->text, $response ); 51 | } elseif( preg_match('/^requires scope (.*)$/', $json->text, $match )) { 52 | throw new InvalidPermissionsException( $json->text, $match[1], $response ); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Middleware/EffectiveUrlMiddleware.php: -------------------------------------------------------------------------------- 1 | nextHandler = $nextHandler; 28 | $this->headerName = $headerName; 29 | } 30 | 31 | /** 32 | * Inject effective-url header into response. 33 | * 34 | * @param RequestInterface $request 35 | * @param array $options 36 | * 37 | * @return RequestInterface 38 | */ 39 | public function __invoke(RequestInterface $request, array $options) { 40 | $fn = $this->nextHandler; 41 | return $fn($request, $options)->then(function(ResponseInterface $response) use ($request, $options) { 42 | return $response->withAddedHeader($this->headerName, $request->getUri()->__toString()); 43 | }); 44 | } 45 | 46 | /** 47 | * Prepare a middleware closure to be used with HandlerStack 48 | * 49 | * @param string $headerName The header name to use for storing effective url 50 | * 51 | * @return \Closure 52 | */ 53 | public static function middleware($headerName = 'X-GUZZLE-EFFECTIVE-URL') { 54 | return function(callable $handler) use (&$headerName) { 55 | return new static($handler, $headerName); 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/V2/Endpoint/Continent/MapEndpoint.php: -------------------------------------------------------------------------------- 1 | continent = $continent; 32 | $this->floor = $floor; 33 | $this->region = $region; 34 | 35 | parent::__construct( $api ); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function url() { 42 | return 'v2/continents/'.$this->continent.'/floors/'.$this->floor.'/regions/'.$this->region.'/maps'; 43 | } 44 | 45 | /** 46 | * Get the maps points of interest. 47 | * 48 | * @param int $map 49 | * 50 | * @return PoiEndpoint 51 | */ 52 | public function poisOf( $map ) { 53 | return new PoiEndpoint( $this->api, $this->continent, $this->floor, $this->region, $map ); 54 | } 55 | 56 | /** 57 | * Get the maps tasks. 58 | * 59 | * @param int $map 60 | * 61 | * @return TaskEndpoint 62 | */ 63 | public function tasksOf( $map ) { 64 | return new TaskEndpoint( $this->api, $this->continent, $this->floor, $this->region, $map ); 65 | } 66 | 67 | /** 68 | * Get the maps sectors. 69 | * 70 | * @param int $map 71 | * 72 | * @return SectorEndpoint 73 | */ 74 | public function sectorsOf( $map ) { 75 | return new SectorEndpoint( $this->api, $this->continent, $this->floor, $this->region, $map ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/V2/AchievementEndpointTest.php: -------------------------------------------------------------------------------- 1 | api()->achievements(); 6 | 7 | $this->assertEndpointIsBulk( $endpoint ); 8 | $this->assertEndpointIsLocalized( $endpoint ); 9 | $this->assertEndpointUrl( 'v2/achievements', $endpoint ); 10 | 11 | $this->mockResponse('{"id":1,"name":"Centaur Slayer"}'); 12 | $this->assertEquals('Centaur Slayer', $endpoint->get(1)->name); 13 | } 14 | 15 | public function testCategories() { 16 | $endpoint = $this->api()->achievements()->categories(); 17 | 18 | $this->assertEndpointUrl('v2/achievements/categories', $endpoint); 19 | $this->assertEndpointIsBulk($endpoint); 20 | $this->assertEndpointIsLocalized($endpoint); 21 | 22 | $this->mockResponse('{"id":50,"name":"Twilight Assault","description":"","order":0,"achievements":[947]}'); 23 | $this->assertEquals(947, $endpoint->get(50)->achievements[0]); 24 | } 25 | 26 | public function testDaily() { 27 | $endpoint = $this->api()->achievements()->daily(); 28 | 29 | $this->assertEndpointUrl( 'v2/achievements/daily', $endpoint ); 30 | 31 | $this->mockResponse('{"pve":[{"id":1984,"level":{"min":1,"max":80}}]}'); 32 | $this->assertEquals(1984, $endpoint->get()->pve[0]->id); 33 | } 34 | 35 | public function testDailyTomorrow() { 36 | $endpoint = $this->api()->achievements()->daily()->tomorrow(); 37 | 38 | $this->assertEndpointUrl( 'v2/achievements/daily/tomorrow', $endpoint ); 39 | 40 | $this->mockResponse('{"pve":[{"id":1837,"level":{"min":1,"max":80}}]}'); 41 | $this->assertEquals(1837, $endpoint->get()->pve[0]->id); 42 | } 43 | 44 | public function testGroups() { 45 | $endpoint = $this->api()->achievements()->groups(); 46 | 47 | $this->assertEndpointUrl( 'v2/achievements/groups', $endpoint ); 48 | $this->assertEndpointIsBulk($endpoint); 49 | $this->assertEndpointIsLocalized($endpoint); 50 | 51 | $this->mockResponse('{"id":"65B4B678-607E-4D97-B458-076C3E96A810","name":"Heart of Thorns"}'); 52 | $this->assertEquals('Heart of Thorns', $endpoint->get('65B4B678-607E-4D97-B458-076C3E96A810')->name); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V2/Bulk/BulkEndpoint.php: -------------------------------------------------------------------------------- 1 | supportsIdsAll ) ? $this->supportsIdsAll : true; 21 | } 22 | 23 | /** 24 | * All ids of this BulkEndpoint. 25 | * 26 | * @return string[]|int[] 27 | */ 28 | public function ids() { 29 | return $this->request()->json(); 30 | } 31 | 32 | /** 33 | * Single entry by id. 34 | * 35 | * @param int|string $id 36 | * @return mixed 37 | */ 38 | public function get( $id ) { 39 | return $this->request([ 'id' => $id ])->json(); 40 | } 41 | 42 | /** 43 | * Multiple entries by ids. 44 | * 45 | * @param string[]|int[] $ids 46 | * @return array 47 | */ 48 | public function many( array $ids = [] ) { 49 | if( count( $ids ) === 0 ) { 50 | return []; 51 | } 52 | 53 | $pages = array_chunk( $ids, $this->maxPageSize() ); 54 | 55 | $requests = []; 56 | foreach( $pages as $page ) { 57 | $requests[] = [ 'ids' => implode( ',', $page ) ]; 58 | } 59 | 60 | $responses = $this->requestMany( $requests ); 61 | 62 | $result = []; 63 | foreach( $responses as $response ) { 64 | $result = array_merge( $result, $response->json() ); 65 | } 66 | 67 | return $result; 68 | } 69 | 70 | /** 71 | * All entries. 72 | * 73 | * If this endpoints supports ?ids=all it will be used, otherwise it will first get all ids and then request 74 | * the entries with multiple requests. 75 | * 76 | * @return array 77 | */ 78 | public function all() { 79 | if( $this->supportsIdsAll() ) { 80 | return $this->request([ 'ids' => 'all' ])->json(); 81 | } else { 82 | return $this->allPaginated(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/V2/ApiHandler.php: -------------------------------------------------------------------------------- 1 | endpoint = $endpoint; 15 | } 16 | 17 | /** 18 | * Get the underlying endpoint that gets handled by this handler. 19 | * 20 | * @return IEndpoint 21 | */ 22 | protected function getEndpoint() { 23 | return $this->endpoint; 24 | } 25 | 26 | /** 27 | * Returns the json object if the response contains valid json, otherwise null. 28 | * 29 | * @param ResponseInterface $response 30 | * @return mixed|null 31 | */ 32 | protected function getResponseAsJson( ResponseInterface $response ) { 33 | if( $response->hasHeader('Content-Type') ) { 34 | $typeHeader = $response->getHeader('Content-Type'); 35 | $contentType = array_shift($typeHeader); 36 | 37 | if( stripos( $contentType, 'application/json' ) === 0 ) { 38 | return json_decode($response->getBody(), false); 39 | } 40 | } 41 | 42 | return null; 43 | } 44 | 45 | /** 46 | * Returns the parsed query string for the passed request as key-value array. 47 | * 48 | * @param RequestInterface $request 49 | * 50 | * @return array 51 | */ 52 | protected function getQueryAsArray( RequestInterface $request ) { 53 | return Query::parse($request->getUri()->getQuery()); 54 | } 55 | 56 | /** 57 | * Return an updated request that should be send. 58 | * 59 | * @param RequestInterface $request 60 | * 61 | * @return RequestInterface 62 | */ 63 | public function onRequest( RequestInterface $request ) { 64 | return $request; 65 | } 66 | 67 | /** 68 | * Modify response before it gets processed. 69 | * 70 | * @param ResponseInterface $response 71 | * @param RequestInterface $request 72 | * 73 | * @return ResponseInterface 74 | */ 75 | public function onResponse( ResponseInterface $response, RequestInterface $request ) { 76 | return $response; 77 | } 78 | 79 | /** 80 | * Handle errors by the api. 81 | * 82 | * @param ResponseInterface $response 83 | * @param RequestInterface $request 84 | */ 85 | public function onError( ResponseInterface $response, RequestInterface $request ) { } 86 | } 87 | -------------------------------------------------------------------------------- /tests/AuthenticatedEndpointTest.php: -------------------------------------------------------------------------------- 1 | api(), $apiKey ); 11 | } 12 | 13 | public function testBasic() { 14 | $this->mockResponse('[]'); 15 | 16 | $endpoint = $this->getAuthenticatedEndpoint('test'); 17 | 18 | $this->assertEndpointIsAuthenticated( $endpoint ); 19 | 20 | $endpoint->test(); 21 | 22 | $request = $this->getLastRequest(); 23 | $this->assertHasHeader($request, 'Authorization', 'Bearer test'); 24 | } 25 | 26 | /** 27 | */ 28 | public function testInvalidKey() { 29 | $this->expectException(\GW2Treasures\GW2Api\V2\Authentication\Exception\AuthenticationException::class, 'invalid key'); 30 | 31 | $this->mockResponse( new Response( 32 | 400, [ 'Content-Type' => 'application/json; charset=utf-8' ], 33 | Utils::streamFor( '{"text":"invalid key"}' ) 34 | )); 35 | 36 | $this->getAuthenticatedEndpoint('invalid')->test(); 37 | } 38 | 39 | public function testInvalidPermissions() { 40 | $this->mockResponse( new Response( 41 | 400, [ 'Content-Type' => 'application/json; charset=utf-8' ], 42 | Utils::streamFor( '{"text":"requires scope characters"}' ) 43 | )); 44 | 45 | try { 46 | $this->getAuthenticatedEndpoint('invalid')->test(); 47 | } catch( InvalidPermissionsException $ex ) { 48 | $this->assertEquals( 'requires scope characters', $ex->getMessage(), 49 | 'InvalidPermissionsException has correct error message.' ); 50 | $this->assertEquals( 'characters', $ex->getMissingScope(), 51 | 'InvalidPermissionsException has correct missing scope' ); 52 | 53 | return; 54 | } 55 | 56 | $this->fail('Accessing IAuthenticatedEndpoint with an api_key that is missing scopes throws InvalidPermissionsException'); 57 | } 58 | 59 | /** 60 | */ 61 | public function testUnknownError() { 62 | $this->expectException(\GW2Treasures\GW2Api\Exception\ApiException::class, 'unknown error'); 63 | 64 | $this->mockResponse( new Response( 65 | 400, [ 'Content-Type' => 'application/json; charset=utf-8' ], 66 | Utils::streamFor( '{"text":"unknown error"}' ) 67 | )); 68 | 69 | $this->getAuthenticatedEndpoint('invalid')->test(); 70 | } 71 | 72 | public function testNullKey() { 73 | $this->mockResponse('[]'); 74 | 75 | $this->getAuthenticatedEndpoint(null)->test(); 76 | 77 | $request = $this->getLastRequest(); 78 | $this->assertHasNotHeader($request, 'Authorization'); 79 | } 80 | } 81 | --------------------------------------------------------------------------------