gw2-api 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -7
- data/lib/gw2/api/version.rb +1 -1
- data/lib/gw2/api.rb +15 -10
- data/lib/gw2/modules/account.rb +1 -2
- data/lib/gw2/modules/achievements.rb +4 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfee0a2b4d24bf1eb08c6e21430fc6ccf8667128b539d0a26ef215c21dbb4069
|
4
|
+
data.tar.gz: a753681723c8cce8d0181a72ecafe9d6d2bcb113ada3d13f215920d2d906bb16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50ea94f82ef032309231568840e7dacdc2e7f305d20cbbcbc9e56735979f9e7d5371f85fd4b3078b982b9e89a0f7185721d6a542b0201bc3324a90cfc49a0cea
|
7
|
+
data.tar.gz: 9f81bc833ea06259dd8338f9120c613339223c543d32c3ddfdc6057e2d3985e9b835b93ac3a54bc33fecaa85d7633ec16f162c63544c3ecbba6e9db6ea1b399c
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,19 +4,41 @@ This is a gem used to make calls to the Guild Wars 2 API.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
-
|
9
7
|
Install the gem and add to the application's Gemfile by executing:
|
10
8
|
|
11
|
-
$ bundle add
|
9
|
+
$ bundle add gw2-api
|
12
10
|
|
13
11
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
12
|
|
15
|
-
$ gem install
|
13
|
+
$ gem install gw2-api
|
16
14
|
|
17
15
|
## Usage
|
18
16
|
|
19
|
-
|
17
|
+
To use the gem, first require it in the application, then create a new instance of the `Gw2::Api::Client` class:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'gw2-api'
|
21
|
+
|
22
|
+
client = Gw2::Api::Client.new(api_key: ENV["GW2_API_KEY"])
|
23
|
+
|
24
|
+
puts client.account.body
|
25
|
+
puts client.achievements(ids: "1840,910")
|
26
|
+
```
|
27
|
+
|
28
|
+
You can replace `ENV["GW2_API_KEY"]` with your own API Key, or set the env variable
|
29
|
+
|
30
|
+
A list of available functions can be found `lib/gw2/modules`.
|
31
|
+
|
32
|
+
You can find valid parameters for each function in the [Guild Wars 2 API documentation](https://wiki.guildwars2.com/wiki/API:Main) or from the public [API-CDI](https://github.com/arenanet/api-cdi) repo.
|
33
|
+
|
34
|
+
## Tests
|
35
|
+
|
36
|
+
To run the tests, execute:
|
37
|
+
|
38
|
+
$ bundle exec rspec
|
39
|
+
|
40
|
+
Note that you need to set a valid API key in the environment variable `GW2_API_KEY` to run the tests.
|
41
|
+
GW2's API Availability can affect the result of the tests (if it's down, the tests will fail).
|
20
42
|
|
21
43
|
## Development
|
22
44
|
|
@@ -26,7 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
26
48
|
|
27
49
|
## Contributing
|
28
50
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nicholasrobertm/gw2-api.
|
30
52
|
|
31
53
|
## License
|
32
54
|
|
@@ -34,4 +56,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
34
56
|
|
35
57
|
## Code of Conduct
|
36
58
|
|
37
|
-
|
59
|
+
Be a decent person, and don't be a jerk, it's that simple!
|
data/lib/gw2/api/version.rb
CHANGED
data/lib/gw2/api.rb
CHANGED
@@ -7,28 +7,34 @@ require_relative "modules/account"
|
|
7
7
|
|
8
8
|
module Gw2
|
9
9
|
module Api
|
10
|
+
# Used to create a client to talk to the Guild Wars 2 API
|
11
|
+
# Arguments
|
12
|
+
# @args [Hash] the arguments to create the client
|
13
|
+
# Valid Arguments
|
14
|
+
# - api_key: [String] the api key to use for the client, defaults to ENV["GW2_API_KEY"]
|
15
|
+
# Variables
|
16
|
+
# @api_key [String] the api key to use for the client
|
17
|
+
# @base_url [String] the base url for the API
|
18
|
+
# See modules for available methods
|
19
|
+
# See https://wiki.guildwars2.com/wiki/API:Main
|
10
20
|
class Client
|
11
|
-
|
12
21
|
include Gw2::Api::Achievements
|
13
22
|
include Gw2::Api::Account
|
14
23
|
|
15
24
|
def initialize(args)
|
16
|
-
@api_key = args[:api_key]
|
25
|
+
@api_key = args[:api_key] || ENV["GW2_API_KEY"]
|
17
26
|
@base_url = "https://api.guildwars2.com/v2"
|
18
27
|
end
|
19
28
|
|
20
29
|
# Executes a request with parameters
|
21
|
-
|
22
|
-
# @params [Hash] the parameters to filter the request
|
23
|
-
# @return [Net::HTTP] the response from the request
|
24
|
-
def execute_with_params(endpoint, params)
|
30
|
+
def execute_with_params(endpoint, parameters)
|
25
31
|
output = endpoint
|
26
32
|
|
27
|
-
return execute_request(output) if
|
33
|
+
return execute_request(output) if parameters.empty?
|
28
34
|
|
29
35
|
output += "?"
|
30
|
-
|
31
|
-
output += "#{key
|
36
|
+
parameters.each do |key, value|
|
37
|
+
output += "#{key}=#{value}&"
|
32
38
|
end
|
33
39
|
execute_request(output)
|
34
40
|
end
|
@@ -45,7 +51,6 @@ module Gw2
|
|
45
51
|
http.request(request)
|
46
52
|
end
|
47
53
|
end
|
48
|
-
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
data/lib/gw2/modules/account.rb
CHANGED
@@ -17,7 +17,7 @@ module Gw2
|
|
17
17
|
# - page: [String] the page number to filter
|
18
18
|
# - page_size: [String] the page size to filter
|
19
19
|
def account_achievements(params = {})
|
20
|
-
execute_with_params(
|
20
|
+
execute_with_params("account/achievements", params)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Returns the account bank
|
@@ -135,7 +135,6 @@ module Gw2
|
|
135
135
|
def account_wallet
|
136
136
|
execute_request("account/wallet")
|
137
137
|
end
|
138
|
-
|
139
138
|
end
|
140
139
|
end
|
141
140
|
end
|
@@ -13,7 +13,7 @@ module Gw2
|
|
13
13
|
# - page: [String] the page number to filter
|
14
14
|
# - page_size: [String] the page size to filter
|
15
15
|
def achievements(params = {})
|
16
|
-
execute_with_params(
|
16
|
+
execute_with_params("achievements", params)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Returns the achievements groups
|
@@ -24,7 +24,7 @@ module Gw2
|
|
24
24
|
# - page: [String] the page number to filter
|
25
25
|
# - page_size: [String] the page size to filter
|
26
26
|
def achievements_groups(params = {})
|
27
|
-
execute_with_params(
|
27
|
+
execute_with_params("achievements/groups", params)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns the achievements categories
|
@@ -34,9 +34,8 @@ module Gw2
|
|
34
34
|
# - ids: [String] the ids of the achievements to filter comma seperated
|
35
35
|
# - page: [String] the page number to filter
|
36
36
|
def achievements_categories(params = {})
|
37
|
-
execute_with_params(
|
37
|
+
execute_with_params("achievements/categories", params)
|
38
38
|
end
|
39
|
-
|
40
39
|
end
|
41
40
|
end
|
42
|
-
end
|
41
|
+
end
|