gw2 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/gw2.gemspec +2 -2
  3. data/lib/gw2.rb +22 -1
  4. data/lib/gw2/characters.rb +13 -0
  5. data/lib/gw2/colors.rb +13 -0
  6. data/lib/gw2/commerce/exchange.rb +15 -0
  7. data/lib/gw2/commerce/listings.rb +16 -0
  8. data/lib/gw2/commerce/prices.rb +16 -0
  9. data/lib/gw2/commerce/transactions.rb +10 -0
  10. data/lib/gw2/event.rb +2 -2
  11. data/lib/gw2/guild.rb +1 -1
  12. data/lib/gw2/https.rb +6 -4
  13. data/lib/gw2/item.rb +2 -2
  14. data/lib/gw2/map.rb +7 -9
  15. data/lib/gw2/misc.rb +5 -5
  16. data/lib/gw2/quaggans.rb +13 -0
  17. data/lib/gw2/recipe.rb +10 -2
  18. data/lib/gw2/resource.rb +3 -2
  19. data/lib/gw2/skins.rb +13 -0
  20. data/lib/gw2/wvw.rb +1 -1
  21. data/spec/fixtures/GW2_Colors/_colors/returns_all_colors.yml +114 -0
  22. data/spec/fixtures/GW2_Event/_event_names/returns_the_names_of_all_events.yml +20 -2034
  23. data/spec/fixtures/GW2_Event/_world_names/returns_the_names_of_all_worlds.yml +18 -7
  24. data/spec/fixtures/GW2_Guild/_details/returns_the_guild_based_on_id.yml +19 -8
  25. data/spec/fixtures/GW2_Guild/_details/returns_the_guild_based_on_name.yml +19 -8
  26. data/spec/fixtures/GW2_Item/_all/returns_all_items.yml +60909 -11
  27. data/spec/fixtures/GW2_Item/_details/returns_the_details_of_the_item.yml +53 -11
  28. data/spec/fixtures/GW2_Map/_all/returns_all_maps.yml +70 -1078
  29. data/spec/fixtures/GW2_Map/_continents/returns_all_continents.yml +179 -11
  30. data/spec/fixtures/GW2_Map/_map_floor/returns_a_specific_map_floor.yml +20 -3409
  31. data/spec/fixtures/GW2_Misc/_build/returns_the_build.yml +27 -11
  32. data/spec/fixtures/GW2_Misc/_files/returns_all_files.yml +502 -11
  33. data/spec/fixtures/GW2_Quaggans/_all/returns_all_Quaggans.yml +102 -0
  34. data/spec/fixtures/GW2_Quaggans/_details/returns_the_details_of_the_quaggan.yml +67 -0
  35. data/spec/fixtures/GW2_Recipe/_all/returns_all_recipes.yml +11764 -11
  36. data/spec/fixtures/GW2_Recipe/_details/returns_the_details_of_a_recipe_by_id.yml +61 -11
  37. data/spec/fixtures/GW2_Skins/_all/returns_all_Skins.yml +5374 -0
  38. data/spec/fixtures/GW2_Skins/_details/returns_the_details_of_the_skin.yml +78 -0
  39. data/spec/fixtures/GW2_WvW/_match_details/returns_the_details_of_a_match.yml +19 -8
  40. data/spec/fixtures/GW2_WvW/_matches/returns_all_matches.yml +19 -8
  41. data/spec/fixtures/GW2_WvW/_objective_names/returns_all_objectives.yml +88 -27
  42. data/spec/gw2/colors_spec.rb +47 -0
  43. data/spec/gw2/event_spec.rb +1 -14
  44. data/spec/gw2/guild_spec.rb +2 -2
  45. data/spec/gw2/item_spec.rb +7 -7
  46. data/spec/gw2/map_spec.rb +38 -59
  47. data/spec/gw2/misc_spec.rb +3 -44
  48. data/spec/gw2/quaggan_spec.rb +31 -0
  49. data/spec/gw2/recipe_spec.rb +12 -11
  50. data/spec/gw2/skins_spec.rb +40 -0
  51. data/spec/gw2/wvw_spec.rb +9 -9
  52. metadata +42 -24
  53. data/spec/fixtures/GW2_Event/_map_names/returns_the_names_of_all_maps.yml +0 -53
  54. data/spec/fixtures/GW2_Map/_maps/returns_the_map_by_id.yml +0 -41
  55. data/spec/fixtures/GW2_Misc/_colors/returns_all_colors.yml +0 -239
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bc83cd0a1e4bcd78068cdff2c15f1b7b208a17b5
4
- data.tar.gz: d46ddf5395ff09d4b202bbf97bf2728c95866d37
2
+ SHA256:
3
+ metadata.gz: d6ac8dd61d426c0299f39e846ad9417748127ba9d4356b072af28d78e5d43fba
4
+ data.tar.gz: cf6428288351bbd387a6ca9736dd0495c62a5813b03ac1e64f978f1900458a7b
5
5
  SHA512:
6
- metadata.gz: ab4b0b59ba75bb0bd80514a3a0cf383d35850bf91bf401424a412b898114e02d3e22137952a12ce34029c5f957daca34127d809edc2b0daa7704ed228aea6e86
7
- data.tar.gz: e511e7f4faaafade2ab0713478fb72071a65ef40a0ce9c364af3390c7fe371601b330883d9526cdb08c27647a02f150fbf381aa2033e28a5dd7291c95d5d7d3c
6
+ metadata.gz: ac67406923268394feec369b502e74694c322116d16d316f304624eddb7fb07da7ed10cbc11d8787c4c2976ce089e3be2dec5e8e647032e5fa0bdb62c5a8dad6
7
+ data.tar.gz: afc4b16b16d3eb72ea4625c94f5d16e86ab380538580a5d4f51fed77f7b64ab0b92b8364799517d11fc452df1f3b2dd3e484c6e855766f049dd328484b95f12f
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "gw2"
3
- s.version = "1.4.0"
4
- s.date = "2015-02-27"
3
+ s.version = "1.5.0"
4
+ s.date = "2018-06-13"
5
5
  s.summary = "Guild Wars 2 API"
6
6
  s.description = "A ruby gem for accessing the Guild Wars 2 API"
7
7
  s.authors = ["Chris Rosario"]
data/lib/gw2.rb CHANGED
@@ -7,9 +7,30 @@ require "gw2/item"
7
7
  require "gw2/recipe"
8
8
  require "gw2/guild"
9
9
  require "gw2/misc"
10
+ require "gw2/colors"
11
+ require "gw2/quaggans"
12
+ require "gw2/skins"
10
13
  require "gw2/map"
14
+ require "gw2/characters"
15
+ require "gw2/commerce/listings"
16
+ require "gw2/commerce/exchange"
17
+ require "gw2/commerce/prices"
18
+ require "gw2/commerce/transactions"
11
19
  require "gw2/disabled"
12
20
 
13
21
  module GW2
14
- BASE_URL = "https://api.guildwars2.com/v1"
22
+ attr_accessor :api_key
23
+
24
+ BASE_URL_V1 = "https://api.guildwars2.com/v1"
25
+ BASE_URL_V2 = "https://api.guildwars2.com/v2"
26
+ V1_ENDPOINTS = ["world_names", "event_names", "guild_details", "wvw", "map_floor"]
27
+
28
+ def self.api_key
29
+ @api_key
30
+ end
31
+
32
+ def self.api_key=api_key
33
+ @api_key = api_key
34
+ end
35
+
15
36
  end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Characters
3
+ extend Resource
4
+
5
+ def self.all
6
+ get("/characters.json?access_token=#{GW2.api_key}")
7
+ end
8
+
9
+ def self.details(character_name)
10
+ get("/characters/#{character_name}.json?access_token=#{GW2.api_key}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Colors
3
+ extend Resource
4
+
5
+ def self.all
6
+ get("/colors.json")
7
+ end
8
+
9
+ def self.details(color_id)
10
+ get("/colors/#{color_id}.json")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module GW2
2
+ module Commerce
3
+ module Exchange
4
+ extend Resource
5
+
6
+ def self.all
7
+ get("/commerce/exchange.json")
8
+ end
9
+
10
+ def self.details(exchange_type, quantity)
11
+ get("/commerce/exchange/#{exchange_type}.json", {quantity: quantity})
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module GW2
2
+ module Commerce
3
+ module Listings
4
+ extend Resource
5
+
6
+ def self.all
7
+ get("/commerce/listings.json")
8
+ end
9
+
10
+ def self.details(listing_id)
11
+ get("/commerce/listings/#{listing_id}.json")
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module GW2
2
+ module Commerce
3
+ module Prices
4
+ extend Resource
5
+
6
+ def self.all
7
+ get("/commerce/prices.json")
8
+ end
9
+
10
+ def self.details(pricing_id)
11
+ get("/commerce/prices/#{pricing_id}.json")
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module GW2
2
+ module Commerce
3
+ module Transactions
4
+ extend Resource
5
+ def self.current(mode = "buys")
6
+ get("/commerce/transactions/current/#{mode}.json?access_token=#{GW2.api_key}")
7
+ end
8
+ end
9
+ end
10
+ end
@@ -15,11 +15,11 @@ module GW2
15
15
  end
16
16
 
17
17
  def self.event_names
18
- get("/event_names.json")
18
+ raise GW2::Disabled, "This endpoint is disabled."
19
19
  end
20
20
 
21
21
  def self.map_names
22
- get("/map_names.json")
22
+ GW2::Misc.worlds
23
23
  end
24
24
  end
25
25
  end
@@ -3,7 +3,7 @@ module GW2
3
3
  extend Resource
4
4
 
5
5
  def self.details(query = {})
6
- get("/guild_details.json", query)
6
+ get("/guild_details.json", query: query)
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,6 @@ require "net/https"
3
3
  module GW2
4
4
  module HTTPS
5
5
  DEFAULT_REQUEST = { action: "Get", ssl: true }
6
-
7
6
  def query_string(query_hash = {})
8
7
  string = query_hash.collect{ |k,v| "#{k}=#{v}" }.join("&")
9
8
  string.prepend("?") unless string.empty?
@@ -13,18 +12,21 @@ module GW2
13
12
 
14
13
  def request(end_point = "", attr = {})
15
14
  attr = DEFAULT_REQUEST.merge(attr)
16
- uri = URI.parse(BASE_URL + end_point + query_string(attr[:query] || {}))
15
+
16
+ if V1_ENDPOINTS.any? { |word| end_point.include?(word) }
17
+ uri = URI.parse(BASE_URL_V1 + end_point + query_string(attr[:query] || {}))
18
+ else
19
+ uri = URI.parse(BASE_URL_V2 + end_point + query_string(attr[:query] || {}))
20
+ end
17
21
 
18
22
  http = Net::HTTP.new(uri.host, uri.port)
19
23
  http.use_ssl = attr[:ssl]
20
24
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____-
21
25
 
22
- net_http = Net::HTTP
23
26
  request = Net::HTTP.const_get(attr[:action]).new(uri.request_uri)
24
27
  attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
25
28
 
26
29
  request.set_form_data(attr[:form_data]) if attr[:form_data]
27
-
28
30
  http.request(request)
29
31
  end
30
32
  end
@@ -3,11 +3,11 @@ module GW2
3
3
  extend Resource
4
4
 
5
5
  def self.all
6
- get("/items.json")["items"]
6
+ get("/items.json")
7
7
  end
8
8
 
9
9
  def self.details(item_id)
10
- get("/item_details.json", { item_id: item_id })
10
+ get("/items/#{item_id}.json")
11
11
  end
12
12
  end
13
13
  end
@@ -2,22 +2,20 @@ module GW2
2
2
  module Map
3
3
  extend Resource
4
4
 
5
- PARAMS_FILTER = [:map_id]
6
-
7
5
  def self.all
8
- self.where
6
+ get("/maps.json")
9
7
  end
10
8
 
11
- def self.where(query = {})
12
- get("/maps.json", query)["maps"]
9
+ def self.details(map_id)
10
+ get("/maps/#{map_id}.json")
13
11
  end
14
12
 
15
- def self.map_floor(continent_id, floor)
16
- get("/map_floor.json", { continent_id: continent_id, floor: floor })
13
+ def self.floor(continent_id, floor)
14
+ get("/map_floor.json", query: { continent_id: continent_id, floor: floor })
17
15
  end
18
16
 
19
- def self.continents
20
- get("/continents.json")["continents"]
17
+ def self.continents(continent_id="all")
18
+ get("/continents.json", query: { ids: continent_id })
21
19
  end
22
20
  end
23
21
  end
@@ -3,15 +3,15 @@ module GW2
3
3
  extend Resource
4
4
 
5
5
  def self.build
6
- get("/build.json")["build_id"]
6
+ get("/build.json")["id"]
7
7
  end
8
8
 
9
- def self.colors
10
- get("/colors.json")["colors"]
9
+ def self.files
10
+ get("/files.json", query: { ids: "all" })
11
11
  end
12
12
 
13
- def self.files
14
- get("/files.json")
13
+ def self.worlds
14
+ get("/worlds.json", { ids: "all" })
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Quaggans
3
+ extend Resource
4
+
5
+ def self.all
6
+ get("/quaggans.json")
7
+ end
8
+
9
+ def self.details(quaggan_name)
10
+ get("/quaggans/#{quaggan_name}.json")
11
+ end
12
+ end
13
+ end
@@ -3,11 +3,19 @@ module GW2
3
3
  extend Resource
4
4
 
5
5
  def self.all
6
- get("/recipes.json")["recipes"]
6
+ get("/recipes.json")
7
7
  end
8
8
 
9
9
  def self.details(recipe_id)
10
- get("/recipe_details.json", { recipe_id: recipe_id })
10
+ get("/recipes/#{recipe_id}.json")
11
+ end
12
+
13
+ def self.search_input(item_id)
14
+ get("/recipes/search.json", { input: item_id})
15
+ end
16
+
17
+ def self.search_output(item_id)
18
+ get("/recipes/search.json", { output: item_id})
11
19
  end
12
20
  end
13
21
  end
@@ -6,10 +6,11 @@ module GW2
6
6
  include HTTPS
7
7
  include JSON
8
8
 
9
- BASE_URL = "https://api.guildwars2.com/v1"
9
+ BASE_URL_V1 = "https://api.guildwars2.com/v1"
10
+ BASE_URL_V2 = "https://api.guildwars2.com/v2"
10
11
 
11
12
  def get(endpoint, query = {})
12
- parse(request(endpoint, query: query).body)
13
+ parse(request(endpoint, query).body)
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Skins
3
+ extend Resource
4
+
5
+ def self.all
6
+ get("/skins.json")
7
+ end
8
+
9
+ def self.details(skin_id)
10
+ get("/skins/#{skin_id}.json")
11
+ end
12
+ end
13
+ end
@@ -7,7 +7,7 @@ module GW2
7
7
  end
8
8
 
9
9
  def self.match_details(match_id)
10
- get("/wvw/match_details.json", match_id: match_id)["maps"]
10
+ get("/wvw/match_details.json", query: { match_id: match_id })["maps"]
11
11
  end
12
12
 
13
13
  def self.objective_names
@@ -0,0 +1,114 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.guildwars2.com/v2/colors/126.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Wed, 13 Jun 2018 22:10:39 GMT
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - '277'
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - public,max-age=3600
31
+ Content-Language:
32
+ - en
33
+ Expires:
34
+ - Wed, 13 Jun 2018 23:10:39 GMT
35
+ Vary:
36
+ - Accept-Encoding
37
+ Server:
38
+ - Quaggans
39
+ X-Result-Total:
40
+ - '549'
41
+ Access-Control-Expose-Headers:
42
+ - X-Result-Total
43
+ X-Rate-Limit-Limit:
44
+ - '600'
45
+ X-Content-Type-Options:
46
+ - nosniff
47
+ - nosniff
48
+ Access-Control-Allow-Origin:
49
+ - "*"
50
+ X-Powered-By:
51
+ - ARR/2.5
52
+ X-Frame-Options:
53
+ - SAMEORIGIN
54
+ X-Xss-Protection:
55
+ - 1; mode=block
56
+ Strict-Transport-Security:
57
+ - max-age=31536000; includeSubDomains; preload
58
+ body:
59
+ encoding: ASCII-8BIT
60
+ string: |-
61
+ {
62
+ "id": 126,
63
+ "name": "Hot Pink",
64
+ "base_rgb": [
65
+ 128,
66
+ 26,
67
+ 26
68
+ ],
69
+ "cloth": {
70
+ "brightness": 14,
71
+ "contrast": 1.21094,
72
+ "hue": 340,
73
+ "saturation": 0.820313,
74
+ "lightness": 1.44531,
75
+ "rgb": [
76
+ 169,
77
+ 54,
78
+ 94
79
+ ]
80
+ },
81
+ "leather": {
82
+ "brightness": 14,
83
+ "contrast": 1.21094,
84
+ "hue": 340,
85
+ "saturation": 0.703125,
86
+ "lightness": 1.44531,
87
+ "rgb": [
88
+ 160,
89
+ 62,
90
+ 96
91
+ ]
92
+ },
93
+ "metal": {
94
+ "brightness": 14,
95
+ "contrast": 1.21094,
96
+ "hue": 340,
97
+ "saturation": 0.585938,
98
+ "lightness": 1.44531,
99
+ "rgb": [
100
+ 151,
101
+ 69,
102
+ 98
103
+ ]
104
+ },
105
+ "item": 20594,
106
+ "categories": [
107
+ "Red",
108
+ "Vibrant",
109
+ "Rare"
110
+ ]
111
+ }
112
+ http_version:
113
+ recorded_at: Wed, 13 Jun 2018 22:10:39 GMT
114
+ recorded_with: VCR 2.9.3