Skip to content

Commit c31b1ab

Browse files
Update README.md
Add usage details
1 parent 5a35a38 commit c31b1ab

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

README.md

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,125 @@ $ bundle install
1818

1919
## Usage
2020

21-
Coming soon.
21+
Start by initializing a client. You can obtain an API key by creating a new XIVAPI application [here](http://www.xivapi.com/app).
22+
23+
```rb
24+
require 'xivapi'
25+
26+
# Basic configuration
27+
client = XIVAPI::Client.new(api_key: 'abc123')
28+
29+
# Advanced configuration
30+
client = XIVAPI::Client.new(api_key: 'abc123', language: 'en', poll_rate: 30, tags: ['cool', 'dude'])
31+
```
32+
33+
Now that you have a client, you can use it to contact the API. Examples have been provided below for the various endpoints. For the full list of endpoints and their parameters, please reference the [requests](https://github.com/mattantonelli/xivapi-ruby/blob/master/lib/xivapi/request.rb) code and accompanying documentation.
34+
35+
### Response data
36+
The data returned from the API is automatically converted into [OpenStruct](https://ruby-doc.org/stdlib-2.0.0/libdoc/ostruct/rdoc/OpenStruct.html) objects with snake_cased keys. If the request returns multiple results (e.g. character search), it will be provided to you in the form of an `XIVAPI::Paginator` object. The paginator is [Enumerable](https://ruby-doc.org/core-2.4.1/Enumerable.html), allowing you to access the data with methods like `first`, `each`, `map` and `to_a`.
37+
38+
See the examples below to get a better idea of how to access the data.
39+
40+
### Examples
41+
##### Search
42+
```rb
43+
>> achievements = client.search(indexes: 'achievement', string: 'tankless')
44+
=> ...
45+
>> achievements.map(&:name)
46+
=> ["A Tankless Job II (Dark Knight)", "A Tankless Job I (Paladin)", "A Tankless Job I (Warrior)", "A Tankless Job II (Warrior)", "A Tankless Job I (Dark Knight)", "A Tankless Job II (Paladin)"]
47+
>> achievements.first.points
48+
=> 10
49+
```
50+
51+
##### Content
52+
```rb
53+
>> client.content
54+
=> ["Achievement", "AchievementCategory", "AchievementKind", ...]
55+
56+
>> achievement = client.content(name: 'Achievement', limit: 1).first
57+
=> ...
58+
>> achievement.name
59+
=> "To Crush Your Enemies I"
60+
61+
>> achievements = client.content(name: 'Achievement', ids: 4..5)
62+
=> ...
63+
>> achievements.map(&:name)
64+
=> ["To Crush Your Enemies IV", "To Crush Your Enemies V"]
65+
```
66+
67+
##### Servers
68+
```rb
69+
>> client.servers
70+
=> ["Adamantoise", "Aegis", "Alexander", ...]
71+
```
72+
73+
##### Character
74+
```rb
75+
>> characters = client.character_search(name: 'raelys skyborn', server: 'behemoth')
76+
=> ...
77+
>> id = characters.first.id
78+
=> 7660136
79+
>> character = client.character(id: id, all_data: true)
80+
=> ...
81+
>> character.character.name
82+
=> "Raelys Skyborn"
83+
>> character.achievements.list.last.id
84+
=> 692
85+
```
86+
87+
##### Free Company
88+
```rb
89+
>> fcs = client.free_company_search(name: 'lodestone', server: 'behemoth')
90+
=> ...
91+
>> id = fcs.first.id
92+
=> "9234349560946590421"
93+
>> fc = client.free_company(id: id, members: true)
94+
=> ...
95+
>> fc.free_company.name
96+
=> "Lodestone"
97+
>> fc.free_company_members.first.name
98+
=> "Raelys Skyborn"
99+
```
100+
101+
##### Linkshell
102+
```rb
103+
>> linkshells = client.linkshell_search(name: 'thunderbirds', server: 'behemoth')
104+
=> ...
105+
>> id = linkshells.first.id
106+
=> "21955048183495181"
107+
>> linkshell = client.linkshell(id: id, poll: true).linkshell
108+
=> ...
109+
>> linkshell.name
110+
=> "Thunderbirds"
111+
```
112+
113+
##### PVP Team
114+
```rb
115+
>> teams = client.pvp_team_search(name: 'kill', server: 'chaos')
116+
=> ...
117+
>> team = client.pvp_team(id: teams.first.id).pvp_team
118+
=> ...
119+
>> team.name
120+
=> "!Kill_For_A_Friend!"
121+
```
122+
123+
##### Lodestone
124+
```rb
125+
>> updates = client.lodestone(:updates)
126+
=> ...
127+
>> updates.first.title
128+
=> "Companion App Updated (Sep. 18)"
129+
```
130+
131+
##### Patch List
132+
```rb
133+
>> patch = client.patch_list.last
134+
=> ...
135+
>> patch.name
136+
=> "Patch 4.4: Prelude In Violet"
137+
>> Time.at(patch.release_date.to_i)
138+
=> 2018-09-18 10:00:00 +0000
139+
```
22140

23141
## Development
24142

0 commit comments

Comments
 (0)