Skip to content

Commit 8366e2d

Browse files
author
Josh Freeman
committed
Flesh out rest of xivapi-php library logic
1 parent 04947ae commit 8366e2d

File tree

10 files changed

+459
-1
lines changed

10 files changed

+459
-1
lines changed

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,137 @@ Install vis composer:
1111
- `composer require xivapi/xivapi-php`
1212

1313
## Usage
14+
15+
The `xivapi-php` library is a very simple wrapper around Guzzle.
16+
17+
**Initialize**
18+
```php
19+
$api = new \XIVAPI\XIVAPI();
20+
```
21+
22+
**Setting your key if you have one**
23+
24+
You can set the environment variable: `XIVAPI_KEY` Or via:
25+
26+
```php
27+
$api->environment->key('my_api_key');
28+
```
29+
30+
**Using global queries**
31+
32+
The following global queries are supported:
33+
34+
- `columns`
35+
36+
```php
37+
$columns = [
38+
'ID',
39+
'Name',
40+
'Icon
41+
];
42+
43+
$api->columns($columns)->content->Item()->list();
44+
```
45+
46+
- `language`
47+
48+
```php
49+
$api->language('en')->content->Item()->list();
50+
```
51+
52+
- `snake_case`
53+
54+
```php
55+
$api->snakeCase()->content->Item()->list();
56+
```
57+
58+
- `tags`
59+
60+
```php
61+
$tags = [
62+
'one',
63+
'two',
64+
'three'
65+
];
66+
$api->tags($tags)->content->Item()->list();
67+
```
68+
69+
### Content
70+
71+
Content is dynamically driven based on what content is available in the game files, thus it has a method method for invoking the different types, eg:
72+
73+
- `item()`
74+
- `instanceContent()`
75+
- `tripleTriadCard()`
76+
77+
```php
78+
$api->content->[contentName]()->list();
79+
$api->content->[contentName]()->one($id);
80+
81+
$api->content->list();
82+
$api->content->servers();
83+
$api->content->serversByDataCenter();
84+
```
85+
86+
### Search
87+
88+
```php
89+
$api->search->find($string)->results();
90+
```
91+
92+
The following search modify methods are available:
93+
```php
94+
$api->search->column($column);
95+
$api->search->algorithm($searchStringAlgorithm);
96+
$api->search->page($number);
97+
$api->search->sort($field, $order);
98+
$api->search->limit($limit);
99+
$api->search->columns($columns);
100+
$api->search->bool($bool);
101+
```
102+
103+
Filters are additive, multiple can be added, eg:
104+
105+
```php
106+
$api->search
107+
->filter('LevelItem', 30, SearchFilters::GREATER_THAN)
108+
->filter('ItemSearchCategory', 10, SearchFilters::GREATER_THAN_OR_EQUAL_TO);
109+
```
110+
111+
112+
### Character
113+
114+
```php
115+
$api->character->search($name, $server, $page);
116+
$api->character->get($id, $data = [], $extended = false);
117+
$api->character->verify($id);
118+
$api->character->update($id);
119+
$api->character->delete($id);
120+
```
121+
122+
### Free Company
123+
124+
```php
125+
$api->freecompany->search($name, $server, $page);
126+
$api->freecompany->get($id, $data = []);
127+
$api->freecompany->update($id);
128+
$api->freecompany->delete($id);
129+
```
130+
131+
### Linkshell
132+
133+
```php
134+
$api->linkshell->search($name, $server, $page);
135+
$api->linkshell->get($id, $data = []);
136+
$api->linkshell->update($id);
137+
$api->linkshell->delete($id);
138+
```
139+
140+
### PvPTeam
141+
142+
```php
143+
$api->pvpteam->search($name, $server, $page);
144+
$api->pvpteam->get($id, $data = []);
145+
$api->pvpteam->update($id);
146+
$api->pvpteam->delete($id);
147+
```

src/XIVAPI/Api/Character.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use XIVAPI\Guzzle\Guzzle;
7+
8+
class Character
9+
{
10+
public function search(string $name, string $server, int $page = 1)
11+
{
12+
return Guzzle::get("/freecompany/search", [
13+
RequestOptions::QUERY => [
14+
'name' => $name,
15+
'server' => ucwords($server),
16+
'page' => $page,
17+
]
18+
]);
19+
}
20+
21+
public function get(int $id, array $data = [], bool $extended = false)
22+
{
23+
$options = [
24+
RequestOptions::QUERY
25+
];
26+
27+
if ($data) {
28+
$options[RequestOptions::QUERY]['data'] = implode(",", $data);
29+
}
30+
31+
if ($extended) {
32+
$options[RequestOptions::QUERY]['extended'] = 1;
33+
}
34+
35+
return Guzzle::get("/character/{$id}", $options);
36+
}
37+
38+
public function verify(int $id)
39+
{
40+
return Guzzle::get("/character/{$id}/verification");
41+
}
42+
43+
public function update(int $id)
44+
{
45+
return Guzzle::get("/character/{$id}/update");
46+
}
47+
48+
public function delete(int $id)
49+
{
50+
return Guzzle::get("/character/{$id}/delete");
51+
}
52+
}

src/XIVAPI/Api/FreeCompany.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use XIVAPI\Guzzle\Guzzle;
7+
8+
class FreeCompany
9+
{
10+
public function search(string $name, string $server, int $page = 1)
11+
{
12+
return Guzzle::get("/freecompany/search", [
13+
RequestOptions::QUERY => [
14+
'name' => $name,
15+
'server' => ucwords($server),
16+
'page' => $page,
17+
]
18+
]);
19+
}
20+
21+
public function get(int $id, array $data = [])
22+
{
23+
$options = [
24+
RequestOptions::QUERY
25+
];
26+
27+
if ($data) {
28+
$options[RequestOptions::QUERY]['data'] = implode(",", $data);
29+
}
30+
31+
return Guzzle::get("/freecompany/{$id}", $options);
32+
}
33+
34+
public function update(int $id)
35+
{
36+
return Guzzle::get("/freecompany/{$id}/update");
37+
}
38+
39+
public function delete(int $id)
40+
{
41+
return Guzzle::get("/freecompany/{$id}/delete");
42+
}
43+
}

src/XIVAPI/Api/Linkshell.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use XIVAPI\Guzzle\Guzzle;
7+
8+
class Linkshell
9+
{
10+
public function search(string $name, string $server, int $page = 1)
11+
{
12+
return Guzzle::get("/linkshell/search", [
13+
RequestOptions::QUERY => [
14+
'name' => $name,
15+
'server' => ucwords($server),
16+
'page' => $page,
17+
]
18+
]);
19+
}
20+
21+
public function get(int $id, array $data = [])
22+
{
23+
$options = [
24+
RequestOptions::QUERY
25+
];
26+
27+
if ($data) {
28+
$options[RequestOptions::QUERY]['data'] = implode(",", $data);
29+
}
30+
31+
return Guzzle::get("/linkshell/{$id}", $options);
32+
}
33+
34+
public function update(int $id)
35+
{
36+
return Guzzle::get("/linkshell/{$id}/update");
37+
}
38+
39+
public function delete(int $id)
40+
{
41+
return Guzzle::get("/linkshell/{$id}/delete");
42+
}
43+
}

src/XIVAPI/Api/Lodestone.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use XIVAPI\Guzzle\Guzzle;
6+
7+
class Lodestone
8+
{
9+
public function all()
10+
{
11+
return Guzzle::get("/lodestone");
12+
}
13+
14+
public function news()
15+
{
16+
return Guzzle::get("/lodestone/news");
17+
}
18+
19+
public function notices()
20+
{
21+
return Guzzle::get("/lodestone/notices");
22+
}
23+
24+
public function maintenance()
25+
{
26+
return Guzzle::get("/lodestone/maintenance");
27+
}
28+
29+
public function updates()
30+
{
31+
return Guzzle::get("/lodestone/updates");
32+
}
33+
34+
public function status()
35+
{
36+
return Guzzle::get("/lodestone/status");
37+
}
38+
39+
public function worldstatus()
40+
{
41+
return Guzzle::get("/lodestone/worldstatus");
42+
}
43+
44+
public function devblogs()
45+
{
46+
return Guzzle::get("/lodestone/devblogs");
47+
}
48+
49+
public function devposts()
50+
{
51+
return Guzzle::get("/lodestone/devposts");
52+
}
53+
54+
public function feasts(int $season = 4)
55+
{
56+
return Guzzle::get("/lodestone/feasts");
57+
}
58+
59+
public function deepdungeon()
60+
{
61+
return Guzzle::get("/lodestone/news");
62+
}
63+
64+
}

src/XIVAPI/Api/Market.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use XIVAPI\Guzzle\Guzzle;
7+
8+
class Market
9+
{
10+
public function price(string $server, int $itemId)
11+
{
12+
return Guzzle::get("/market/{$server}/items/{$itemId}");
13+
}
14+
15+
public function history(string $server, int $itemId)
16+
{
17+
return Guzzle::get("/market/{$server}/items/{$itemId}/history");
18+
}
19+
20+
public function stock(string $server, int $categoryId)
21+
{
22+
return Guzzle::get("/market/{$server}/category/{$categoryId}");
23+
}
24+
25+
public function categories()
26+
{
27+
return Guzzle::get("/market/categories");
28+
}
29+
30+
public function tokens($password)
31+
{
32+
return Guzzle::get("/market/categories", [
33+
RequestOptions::QUERY => [
34+
'password' => $password
35+
]
36+
]);
37+
}
38+
}

src/XIVAPI/Api/PatchList.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace XIVAPI\Api;
4+
5+
use XIVAPI\Guzzle\Guzzle;
6+
7+
class PatchList
8+
{
9+
public function list()
10+
{
11+
return Guzzle::get("/patchlist");
12+
}
13+
}

0 commit comments

Comments
 (0)