gw2api 0.0.0 → 0.1.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/GW2API.gemspec +2 -0
- data/README.md +1 -1
- data/lib/endpoint.rb +53 -0
- data/lib/endpoints/build.rb +13 -0
- data/lib/endpoints/items.rb +12 -0
- data/lib/endpoints/worlds.rb +13 -0
- data/lib/gw2api.rb +13 -0
- data/lib/gw2api/version.rb +1 -1
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d6fd380e453951de882abdc48df07423710381
|
4
|
+
data.tar.gz: e92f3ccd3e3659a65f573bed68ec252bb1aeacc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f28946f367931d98cee1695c6b3f937a64a543300103e1213e3eb2d15661aaae60973b5da25e995a3123f5a4bf4278a6d7bb4755afe17a89026094d34498e86
|
7
|
+
data.tar.gz: 3974b512bb6271deebd58e55bac03a00fb5e3ca6c9adad233745e6ec97a7f79686ff126e22fb51ced1766eb3be36a40ebcfcaaa2e1e8f8e5ca6998cad2478dd8
|
data/GW2API.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
+
spec.add_dependency 'typhoeus'
|
24
|
+
|
23
25
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
24
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GW2API [](https://travis-ci.org/Eearslya/GW2API-gem) [](https://codeclimate.com/github/Eearslya/GW2API-gem/coverage) [](https://codeclimate.com/github/Eearslya/GW2API-gem)
|
1
|
+
# GW2API [](https://rubygems.org/gems/gw2api) [](https://travis-ci.org/Eearslya/GW2API-gem) [](https://codeclimate.com/github/Eearslya/GW2API-gem/coverage) [](https://codeclimate.com/github/Eearslya/GW2API-gem) 
|
2
2
|
|
3
3
|
A gem to allow easy access to all of the data provided by the Guild Wars 2 API.
|
4
4
|
|
data/lib/endpoint.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module GW2API
|
4
|
+
class Endpoint
|
5
|
+
def initialize
|
6
|
+
# The URL of the API endpoint
|
7
|
+
@url = GW2API::BASE_URL
|
8
|
+
# Does this endpoint support ?id= and ?ids=?
|
9
|
+
@bulk_expandable = false
|
10
|
+
# Does this endpoint support ?ids=all?
|
11
|
+
@bulk_expandable_all = false
|
12
|
+
# Does this endpoint support ?page= and ?page_size=?
|
13
|
+
@paginated = false
|
14
|
+
# Does this endpoint support ?language=?
|
15
|
+
@localized = false
|
16
|
+
# Does this endpoint require an API key?
|
17
|
+
@authenticated = false
|
18
|
+
# Does this endpoint optionally allow an API key?
|
19
|
+
@authenticated_optional = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def ids
|
23
|
+
return nil unless @bulk_expandable
|
24
|
+
api_call "#{@url}?ids=all"
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(id = nil)
|
28
|
+
return nil if id.nil? && @bulk_expandable
|
29
|
+
if id.kind_of?(Array)
|
30
|
+
api_call("#{@url}?ids=#{id.join(',')}")
|
31
|
+
else
|
32
|
+
api_call("#{@url}/#{id}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def all
|
37
|
+
return nil unless @bulk_expandable_all
|
38
|
+
api_call("#{@url}?ids=all")
|
39
|
+
end
|
40
|
+
|
41
|
+
def api_call(url)
|
42
|
+
request = Typhoeus::Request.new(url)
|
43
|
+
request.on_complete do |resp|
|
44
|
+
if resp.success?
|
45
|
+
return JSON.parse(resp.body, object_class: OpenStruct)
|
46
|
+
else
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
request.run
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/gw2api.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
require 'gw2api/version'
|
2
|
+
require 'endpoints/build'
|
3
|
+
require 'endpoints/items'
|
4
|
+
require 'endpoints/worlds'
|
2
5
|
|
3
6
|
module GW2API
|
7
|
+
BASE_URL = 'https://api.guildwars2.com/'
|
4
8
|
|
9
|
+
def self.build
|
10
|
+
GW2API::BuildEndpoint.new
|
11
|
+
end
|
12
|
+
def self.items
|
13
|
+
GW2API::ItemsEndpoint.new
|
14
|
+
end
|
15
|
+
def self.worlds
|
16
|
+
GW2API::WorldsEndpoint.new
|
17
|
+
end
|
5
18
|
end
|
data/lib/gw2api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gw2api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eearslya Sleiarion
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +113,10 @@ files:
|
|
99
113
|
- Rakefile
|
100
114
|
- bin/console
|
101
115
|
- bin/setup
|
116
|
+
- lib/endpoint.rb
|
117
|
+
- lib/endpoints/build.rb
|
118
|
+
- lib/endpoints/items.rb
|
119
|
+
- lib/endpoints/worlds.rb
|
102
120
|
- lib/gw2api.rb
|
103
121
|
- lib/gw2api/version.rb
|
104
122
|
homepage: https://github.com/Eearslya/GW2API-gem
|