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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0aae6ffe29038a635d7f2dfe410ced6d3199d78
4
- data.tar.gz: 615c5e0f5b55c999fea9e0cb53c27d82ae450a98
3
+ metadata.gz: 78d6fd380e453951de882abdc48df07423710381
4
+ data.tar.gz: e92f3ccd3e3659a65f573bed68ec252bb1aeacc8
5
5
  SHA512:
6
- metadata.gz: f981c226f7d08e3bd7461ad435b0de9f3588f0b01f59321df28e05fc2408b925465ff82e6ecb5fbdbc134faf2be848b29cf228cc149b3d495ee530ad8de22842
7
- data.tar.gz: 531cdf7e406258732c5d244552befe53820051ec937f4f796dad64c6ede511340b0fe6d09a287d87a242167fd53245fee06bc36671f5c5d4209cdc753106e7ca
6
+ metadata.gz: 7f28946f367931d98cee1695c6b3f937a64a543300103e1213e3eb2d15661aaae60973b5da25e995a3123f5a4bf4278a6d7bb4755afe17a89026094d34498e86
7
+ data.tar.gz: 3974b512bb6271deebd58e55bac03a00fb5e3ca6c9adad233745e6ec97a7f79686ff126e22fb51ced1766eb3be36a40ebcfcaaa2e1e8f8e5ca6998cad2478dd8
@@ -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 [![Build Status](https://travis-ci.org/Eearslya/GW2API-gem.svg?branch=master)](https://travis-ci.org/Eearslya/GW2API-gem) [![Test Coverage](https://codeclimate.com/github/Eearslya/GW2API-gem/badges/coverage.svg)](https://codeclimate.com/github/Eearslya/GW2API-gem/coverage) [![Code Climate](https://codeclimate.com/github/Eearslya/GW2API-gem/badges/gpa.svg)](https://codeclimate.com/github/Eearslya/GW2API-gem)
1
+ # GW2API [![Gem Version](https://img.shields.io/gem/v/gw2api.svg)](https://rubygems.org/gems/gw2api) [![Build Status](https://travis-ci.org/Eearslya/GW2API-gem.svg?branch=master)](https://travis-ci.org/Eearslya/GW2API-gem) [![Test Coverage](https://codeclimate.com/github/Eearslya/GW2API-gem/badges/coverage.svg)](https://codeclimate.com/github/Eearslya/GW2API-gem/coverage) [![Code Climate](https://codeclimate.com/github/Eearslya/GW2API-gem/badges/gpa.svg)](https://codeclimate.com/github/Eearslya/GW2API-gem) ![](http://ruby-gem-downloads-badge.herokuapp.com/gw2api)
2
2
 
3
3
  A gem to allow easy access to all of the data provided by the Guild Wars 2 API.
4
4
 
@@ -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
@@ -0,0 +1,13 @@
1
+ require 'endpoint'
2
+
3
+ module GW2API
4
+ class BuildEndpoint < Endpoint
5
+ def initialize
6
+ @url = "#{GW2API::BASE_URL}/build"
7
+ end
8
+
9
+ def id
10
+ api_call(@url)['id']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'endpoint'
2
+
3
+ module GW2API
4
+ class ItemsEndpoint < Endpoint
5
+ def initialize
6
+ super
7
+ @url = "#{GW2API::BASE_URL}/v2/items"
8
+ @bulk_expandable = true
9
+ @paginated = true
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'endpoint'
2
+
3
+ module GW2API
4
+ class WorldsEndpoint < Endpoint
5
+ def initialize
6
+ super
7
+ @url = "#{GW2API::BASE_URL}/v2/worlds"
8
+ @bulk_expandable = true
9
+ @bulk_expandable_all = true
10
+ @paginated = true
11
+ end
12
+ end
13
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GW2API
2
- VERSION = '0.0.0'
2
+ VERSION = '0.1.0'
3
3
  end
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.0.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