1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi; |
4
|
|
|
|
5
|
|
|
use Kubinashi\BattlenetApi\Model\AuthenticationModel; |
6
|
|
|
use Kubinashi\BattlenetApi\Model\Franchises; |
7
|
|
|
use Kubinashi\BattlenetApi\Model\RequestModel; |
8
|
|
|
use Kubinashi\BattlenetApi\Service\RequestService; |
9
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Achievement\Model\AchievementsValueObject; |
10
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Appearance\Model\AppearanceValueObject; |
11
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Service\CollectionService; |
12
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Guild\Service\GuildService; |
13
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\HunterPet\Service\HunterPetService; |
14
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Audit\Model\AuditValueObject; |
15
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\CharacterProfile\Model\CharacterProfileValueObject; |
16
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Feed\FeedObjectFactory; |
17
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Quest\Model\QuestsValueObject; |
18
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Reputation\Model\ReputationValueObject; |
19
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Title\Model\TitleValueObject; |
20
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\PetSlot\Model\PetSlotsValueObject; |
21
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Profession\Service\ProfessionService; |
22
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Progression\Service\ProgressionService; |
23
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Pvp\Service\PvpService; |
24
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Item\Service\ItemService; |
25
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Statistic\Service\StatisticService; |
26
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Stat\Service\StatService; |
27
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Talent\Service\TalentService; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @author Willy Reiche |
31
|
|
|
* @since 2017-07-19 |
32
|
|
|
* @version 1.0 |
33
|
|
|
*/ |
34
|
|
|
class CharacterProfileApi{ |
35
|
|
|
/** |
36
|
|
|
* @var AuthenticationModel |
37
|
|
|
*/ |
38
|
|
|
private $authenticationModel; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var RequestService |
42
|
|
|
*/ |
43
|
|
|
private $requestService; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $charName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $realm; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param AuthenticationModel $authenticationModel |
57
|
|
|
* @param RequestService $requestService |
58
|
|
|
* @param string $charName |
59
|
|
|
* @param string $realm |
60
|
|
|
*/ |
61
|
9 |
|
public function __construct( |
62
|
|
|
AuthenticationModel $authenticationModel, |
63
|
|
|
RequestService $requestService, |
64
|
|
|
$charName, |
65
|
|
|
$realm |
66
|
|
|
) { |
67
|
9 |
|
$this->requestService = $requestService; |
68
|
9 |
|
$this->authenticationModel = $authenticationModel; |
69
|
9 |
|
$this->charName = $charName; |
70
|
9 |
|
$this->realm = $realm; |
71
|
9 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The basic character data |
75
|
|
|
* |
76
|
|
|
* @return CharacterProfileValueObject |
77
|
|
|
*/ |
78
|
1 |
|
public function getCharacterProfile() |
79
|
|
|
{ |
80
|
1 |
|
$responseObject = $this->prepareResponseObject(); |
81
|
|
|
|
82
|
1 |
|
$characterProfile = new CharacterProfileValueObject( |
83
|
1 |
|
$responseObject->lastModified, |
84
|
1 |
|
$responseObject->name, |
85
|
1 |
|
$responseObject->realm, |
86
|
1 |
|
$responseObject->battlegroup, |
87
|
1 |
|
$responseObject->class, |
88
|
1 |
|
$responseObject->race, |
89
|
1 |
|
$responseObject->gender, |
90
|
1 |
|
$responseObject->level, |
91
|
1 |
|
$responseObject->achievementPoints, |
92
|
1 |
|
$responseObject->thumbnail, |
93
|
1 |
|
$responseObject->calcClass, |
94
|
1 |
|
$responseObject->faction, |
95
|
1 |
|
$responseObject->totalHonorableKills |
96
|
1 |
|
); |
97
|
|
|
|
98
|
1 |
|
return $characterProfile; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* A map of achievement data including completion timestamps and criteria information |
103
|
|
|
* |
104
|
|
|
* @return AchievementsValueObject |
105
|
|
|
*/ |
106
|
1 |
|
public function getAchievements() |
107
|
|
|
{ |
108
|
1 |
|
$responseObject = $this->prepareResponseObject('achievements'); |
109
|
|
|
|
110
|
1 |
|
$achievements = new AchievementsValueObject( |
111
|
1 |
|
$responseObject->achievements->achievementsCompleted, |
112
|
1 |
|
$responseObject->achievements->achievementsCompletedTimestamp, |
113
|
1 |
|
$responseObject->achievements->criteria, |
114
|
1 |
|
$responseObject->achievements->criteriaQuantity, |
115
|
1 |
|
$responseObject->achievements->criteriaTimestamp, |
116
|
1 |
|
$responseObject->achievements->criteriaCreated |
117
|
1 |
|
); |
118
|
|
|
|
119
|
1 |
|
return $achievements; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* A map of a character's appearance settings such as which face texture they've selected and whether or not a healm is visible |
124
|
|
|
* |
125
|
|
|
* @return AppearanceValueObject |
126
|
|
|
*/ |
127
|
1 |
|
public function getAppearance() |
128
|
|
|
{ |
129
|
1 |
|
$responseObject = $this->prepareResponseObject('appearance'); |
130
|
|
|
|
131
|
1 |
|
$appearance = new AppearanceValueObject( |
132
|
1 |
|
$responseObject->appearance->faceVariation, |
133
|
1 |
|
$responseObject->appearance->skinColor, |
134
|
1 |
|
$responseObject->appearance->hairVariation, |
135
|
1 |
|
$responseObject->appearance->hairColor, |
136
|
1 |
|
$responseObject->appearance->featureVariation, |
137
|
1 |
|
$responseObject->appearance->showHelm, |
138
|
1 |
|
$responseObject->appearance->showCloak, |
139
|
1 |
|
$responseObject->appearance->customDisplayOptions |
140
|
1 |
|
); |
141
|
|
|
|
142
|
1 |
|
return $appearance; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* The activity feed of the character |
147
|
|
|
* Based on the type you get a different Object to access |
148
|
|
|
* - Achievement = FeedAchievementValueObject |
149
|
|
|
* - Bosskill = FeedBosskillValueObject |
150
|
|
|
* - Loot = FeedLootValueObject |
151
|
|
|
* |
152
|
|
|
* @return array |
153
|
|
|
*/ |
154
|
|
|
public function getFeed() |
155
|
|
|
{ |
156
|
|
|
$responseObject = $this->prepareResponseObject('feed'); |
157
|
|
|
|
158
|
|
|
$feedObjectFactory = new FeedObjectFactory(); |
159
|
|
|
$feedObj = []; |
160
|
|
|
|
161
|
|
|
foreach ($responseObject->feed as $feed) { |
162
|
|
|
$feedObj[] = $feedObjectFactory->getFeedObject($feed); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $feedObj; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* A summary of the guild that the character belongs to |
170
|
|
|
* |
171
|
|
|
* @return Guild\Model\GuildValueObject |
172
|
|
|
*/ |
173
|
1 |
|
public function getGuild() |
174
|
|
|
{ |
175
|
1 |
|
$responseObject = $this->prepareResponseObject('guild'); |
176
|
1 |
|
$guildService = new GuildService(); |
177
|
|
|
|
178
|
1 |
|
return $guildService->prepareGuildValueObject($responseObject->guild); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* A list of all of the combat pets obtained by the character |
183
|
|
|
* |
184
|
|
|
* @return HunterPet\Model\HunterPetValueObject[] |
185
|
|
|
*/ |
186
|
1 |
|
public function getHunterPets() |
187
|
|
|
{ |
188
|
1 |
|
$responseObject = $this->prepareResponseObject('hunterPets'); |
189
|
1 |
|
$hunterPetService = new HunterPetService(); |
190
|
|
|
|
191
|
1 |
|
return $hunterPetService->prepareHunterPets($responseObject); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* A list of items equipped by the character. |
196
|
|
|
* Use of this field will also include the average item level and average item level equipped for the character. |
197
|
|
|
* |
198
|
|
|
* @return Item\Model\ItemValueObject |
199
|
|
|
*/ |
200
|
|
|
public function getItems() |
201
|
|
|
{ |
202
|
|
|
$responseObject = $this->prepareResponseObject('items'); |
203
|
|
|
$itemService = new ItemService(); |
204
|
|
|
|
205
|
|
|
return $itemService->prepareItemValueObject($responseObject->items); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* A list of all of the mounts obtained by the character |
210
|
|
|
* |
211
|
|
|
* @return Collection\Model\CollectionValueObject |
212
|
|
|
*/ |
213
|
1 |
View Code Duplication |
public function getMounts() |
|
|
|
|
214
|
|
|
{ |
215
|
1 |
|
$responseObject = $this->prepareResponseObject('mounts'); |
216
|
1 |
|
$collectionService = new CollectionService(); |
217
|
|
|
|
218
|
1 |
|
return $collectionService->prepareCollectionValueObject($responseObject->mounts, CollectionService::MOUNT); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* A list of the battle pets obtained by the character |
223
|
|
|
* |
224
|
|
|
* @return Collection\Model\CollectionValueObject |
225
|
|
|
*/ |
226
|
1 |
View Code Duplication |
public function getPets() |
|
|
|
|
227
|
|
|
{ |
228
|
1 |
|
$responseObject = $this->prepareResponseObject('pets'); |
229
|
1 |
|
$collectionService = new CollectionService(); |
230
|
|
|
|
231
|
1 |
|
return $collectionService->prepareCollectionValueObject($responseObject->pets, CollectionService::PET); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Data about the current battle pet slots on this characters account |
236
|
|
|
* |
237
|
|
|
* @return PetSlotsValueObject[] |
238
|
|
|
*/ |
239
|
|
|
public function getPetSlots() |
240
|
|
|
{ |
241
|
|
|
$responseObject = $this->prepareResponseObject('petSlots'); |
242
|
|
|
$petSlots = []; |
243
|
|
|
|
244
|
|
|
foreach ($responseObject->petSlots as $petSlot) { |
245
|
|
|
$petSlots[] = new PetSlotsValueObject( |
246
|
|
|
$petSlot->slot, |
247
|
|
|
$petSlot->battlePetGuid, |
248
|
|
|
$petSlot->isEmpty, |
249
|
|
|
$petSlot->isLocked, |
250
|
|
|
$petSlot->abilities |
251
|
|
|
); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return $petSlots; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* A list of the character's professions. Does not include class professions |
259
|
|
|
* |
260
|
|
|
* @return Profession\Model\ProfessionsValueObject |
261
|
|
|
*/ |
262
|
1 |
|
public function getProfessions() |
263
|
|
|
{ |
264
|
1 |
|
$responseObject = $this->prepareResponseObject('professions'); |
265
|
1 |
|
$professionService = new ProfessionService(); |
266
|
|
|
|
267
|
1 |
|
return $professionService->prepareProfessionsValueObject($responseObject->professions); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* A list of raids and bosses indicating raid progression and completeness |
272
|
|
|
* |
273
|
|
|
* @return Progression\Model\ProgressionValueObject |
274
|
|
|
*/ |
275
|
|
|
public function getProgression() |
276
|
|
|
{ |
277
|
|
|
$responseObject = $this->prepareResponseObject('progression'); |
278
|
|
|
$progressionService = new ProgressionService(); |
279
|
|
|
|
280
|
|
|
return $progressionService->prepareProgressionValueObject($responseObject); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* A map of pvp information including arena team membership and rated battlegrounds information |
285
|
|
|
* |
286
|
|
|
* @return Pvp\Model\PvpValueObject |
287
|
|
|
*/ |
288
|
|
|
public function getPvp() |
289
|
|
|
{ |
290
|
|
|
$responseObject = $this->prepareResponseObject('pvp'); |
291
|
|
|
$pvpService = new PvpService(); |
292
|
|
|
|
293
|
|
|
return $pvpService->preparePvpValueObject($responseObject); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* A list of quests completed by the character |
298
|
|
|
* |
299
|
|
|
* @return QuestsValueObject |
300
|
|
|
*/ |
301
|
|
|
public function getQuests() |
302
|
|
|
{ |
303
|
|
|
$responseObject = $this->prepareResponseObject('quests'); |
304
|
|
|
|
305
|
|
|
$quests = new QuestsValueObject( |
306
|
|
|
$responseObject->quests |
307
|
|
|
); |
308
|
|
|
|
309
|
|
|
return $quests; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* A list of the factions that the character has an associated reputation with |
314
|
|
|
* |
315
|
|
|
* @return ReputationValueObject[] |
316
|
|
|
*/ |
317
|
|
|
public function getReputation() |
318
|
|
|
{ |
319
|
|
|
$responseObject = $this->prepareResponseObject('reputation'); |
320
|
|
|
$reputations = []; |
321
|
|
|
|
322
|
|
|
foreach ($responseObject->reputation as $reputation) { |
323
|
|
|
$reputations[] = new ReputationValueObject( |
324
|
|
|
$reputation->id, |
325
|
|
|
$reputation->name, |
326
|
|
|
$reputation->standing, |
327
|
|
|
$reputation->value, |
328
|
|
|
$reputation->max |
329
|
|
|
); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
return $reputations; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* A map of character statistics |
337
|
|
|
* |
338
|
|
|
* @return Statistic\Model\StatisticsValueObject |
339
|
|
|
*/ |
340
|
|
|
public function getStatistics() |
341
|
|
|
{ |
342
|
|
|
$responseObject = $this->prepareResponseObject('statistics'); |
343
|
|
|
$statisticsService = new StatisticService(); |
344
|
|
|
|
345
|
|
|
$statistics = $statisticsService->getStatistics($responseObject->statistics); |
346
|
|
|
|
347
|
|
|
return $statistics; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* A map of character attributes and stats |
352
|
|
|
* |
353
|
|
|
* @return Stat\Model\StatValueObject |
354
|
|
|
*/ |
355
|
|
|
public function getStats() |
356
|
|
|
{ |
357
|
|
|
$responseObject = $this->prepareResponseObject('stats'); |
358
|
|
|
$statService = new StatService(); |
359
|
|
|
|
360
|
|
|
$stats = $statService->getStatValueObject($responseObject->stats); |
361
|
|
|
|
362
|
|
|
return $stats; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* A list of talent structures |
367
|
|
|
* |
368
|
|
|
* @return Talent\Model\TalentValueObject[] |
369
|
|
|
*/ |
370
|
|
|
public function getTalents() |
371
|
|
|
{ |
372
|
|
|
$responseObject = $this->prepareResponseObject('talents'); |
373
|
|
|
$talentService = new TalentService(); |
374
|
|
|
|
375
|
|
|
return $talentService->prepareTalentValueObject($responseObject); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* A list of the titles obtained by the character including the currently selected title |
380
|
|
|
* |
381
|
|
|
* @return ReputationValueObject[] |
382
|
|
|
*/ |
383
|
|
|
public function getTitles() |
384
|
|
|
{ |
385
|
|
|
$responseObject = $this->prepareResponseObject('titles'); |
386
|
|
|
$titles = []; |
387
|
|
|
|
388
|
|
|
foreach ($responseObject->titles as $title) { |
389
|
|
|
$titles[] = new TitleValueObject( |
390
|
|
|
$title->id, |
391
|
|
|
$title->name |
392
|
|
|
); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return $titles; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Raw character audit data that powers the character audit on the game site |
400
|
|
|
* It's broken down to the most recent issues so for example no belt buckle |
401
|
|
|
* |
402
|
|
|
* @return AuditValueObject |
403
|
|
|
*/ |
404
|
|
|
public function getAudit() |
405
|
|
|
{ |
406
|
|
|
$responseObject = $this->prepareResponseObject('audit'); |
407
|
|
|
|
408
|
|
|
$audit = new AuditValueObject( |
409
|
|
|
$responseObject->audit->numberOfIssues, |
410
|
|
|
$responseObject->audit->slots, |
411
|
|
|
$responseObject->audit->unspentTalentPoints, |
412
|
|
|
$responseObject->audit->unenchantedItems, |
413
|
|
|
$responseObject->audit->emptySockets, |
414
|
|
|
$responseObject->audit->itemsWithEmptySockets, |
415
|
|
|
$responseObject->audit->appropriateArmorType |
416
|
|
|
); |
417
|
|
|
|
418
|
|
|
return $audit; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @param string $addition |
423
|
|
|
* @return RequestModel |
424
|
|
|
*/ |
425
|
8 |
|
private function prepareRequestModel($addition) |
426
|
|
|
{ |
427
|
8 |
|
return new RequestModel( |
428
|
8 |
|
$this->authenticationModel->getRegion(), |
429
|
8 |
|
$this->authenticationModel->getApiKey(), |
430
|
8 |
|
$this->authenticationModel->getLocale(), |
431
|
8 |
|
[$this->realm, $this->charName], |
432
|
8 |
|
'character', |
433
|
8 |
|
Franchises::WORLD_OF_WARCRAFT, |
434
|
|
|
$addition |
435
|
8 |
|
); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @param string $addition |
440
|
|
|
* |
441
|
|
|
* @return \StdClass |
442
|
|
|
*/ |
443
|
8 |
|
private function prepareResponseObject($addition = '') |
444
|
|
|
{ |
445
|
8 |
|
$requestModel = $this->prepareRequestModel($addition); |
446
|
8 |
|
$response = $this->requestService->doRequest($requestModel); |
447
|
8 |
|
$responseObject = json_decode($response); |
448
|
|
|
|
449
|
8 |
|
return $responseObject; |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.