blizzard_api 0.3.8 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18b8829ee15345cbac3a2874955718a288bc75893fd8c7d282f30e3a176fd926
4
- data.tar.gz: eeba67d5fd5fbd5a14e380ffc78ae35bc28f88668ca73601572a6441f95eaee1
3
+ metadata.gz: 242a293ba7b8ca3247dc92e4d4499049f4e81fc5ee425035148ad45d45717076
4
+ data.tar.gz: 0b4035e8c611f321a516182ec8f95ec88da575a408b43624ffa8ce4d7e1c7a37
5
5
  SHA512:
6
- metadata.gz: 45e0f9eb2c89426546dc2d29a8462ee1a471e2463c9d1ac0cbd4b4e5a8066894bfed65b720fcaa176954f2548dcdd0624ae7e022ff03ac9f86acd78929e65b47
7
- data.tar.gz: f14afd42c690d863732156f588a87ae1977fcb68221e41b7289324aaa18ab21bcce84306469f2d37a9fab418db2e40b5a9eca6a32c2be8d7fadb42fcc5bf6a1b
6
+ metadata.gz: f8ffab41d1106b9ae14cab5ca48bd369cd301ad7c833d878d841f96ab5c30fdb6944ed1e52b757e52cb519361e3c1317c798202d8e6333c215013d2b35304a57
7
+ data.tar.gz: 3a06b3833836360e72578224e53cc1b1cccb8c70bc310958b0ffe3f02a0cbbbf6ad6e545ad6413a5f7b067edf0f70f783b252b97bcfbf71a19eaec1a66ebbaa9
@@ -1,6 +1,29 @@
1
1
  Please view this file on the master branch, otherwise it may be outdated
2
2
 
3
+ **Version 0.4.1**
4
+
5
+ Added new retail and classic endpoints described here: https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-api-patch-notes-20200609/8902
6
+
7
+ **Version 0.4.0**
8
+
9
+ Added support to searchable endpoints
10
+
11
+ https://develop.battle.net/documentation/world-of-warcraft/guides/search
12
+
13
+ **Version 0.3.11**
14
+
15
+ Fixed D3 item URL.
16
+
17
+ **Version 0.3.10**
18
+
19
+ Really fixed D3 profile URLs this time.
20
+
21
+ **Version 0.3.9**
22
+
23
+ Fix D3 profile URLs.
24
+
3
25
  **Version 0.3.8**
26
+
4
27
  Added new profession endpoints.
5
28
 
6
29
  https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-api-patch-notes-20200414/5680
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blizzard_api (0.3.7)
4
+ blizzard_api (0.4.0)
5
5
  redis (~> 4.1, >= 4.1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.0)
11
+ dotenv (2.7.5)
11
12
  jaro_winkler (1.5.3)
12
13
  minitest (5.11.3)
13
14
  parallel (1.17.0)
@@ -15,7 +16,7 @@ GEM
15
16
  ast (~> 2.4.0)
16
17
  rainbow (3.0.0)
17
18
  rake (13.0.1)
18
- redis (4.1.3)
19
+ redis (4.1.4)
19
20
  rubocop (0.74.0)
20
21
  jaro_winkler (~> 1.5.1)
21
22
  parallel (~> 1.10)
@@ -25,15 +26,18 @@ GEM
25
26
  unicode-display_width (>= 1.4.0, < 1.7)
26
27
  ruby-progressbar (1.10.1)
27
28
  unicode-display_width (1.6.0)
29
+ yard (0.9.25)
28
30
 
29
31
  PLATFORMS
30
32
  ruby
31
33
 
32
34
  DEPENDENCIES
33
35
  blizzard_api!
36
+ dotenv
34
37
  minitest (~> 5.0)
35
38
  rake (~> 13.0)
36
39
  rubocop (~> 0.61)
40
+ yard
37
41
 
38
42
  BUNDLED WITH
39
- 2.1.2
43
+ 2.1.4
data/README.md CHANGED
@@ -73,6 +73,46 @@ Most **data** endpoints will have always 3 methods available `index`, `get` and
73
73
  * `get` is used to get all information about a entry of the index returned data. It receives an id or slug as the first parameter, that depends on the endpoint.
74
74
  * `complete` is a complete information of all items listed in index. **This may perform various calls to the blizzard api** only use if you really need all information.
75
75
 
76
+ ### 3.1 Searchable endpoints
77
+
78
+ Some endpoints support search filters. To perform a search you can use the following formats:
79
+
80
+
81
+ To use the **or** operator you may pass an array of values as argument to `where` or `where_not` methods.
82
+ ```ruby
83
+ realm = BlizzardApi::Wow.realm
84
+ realm_data = realm.search(1, 100) do |options|
85
+ options.where 'name.en_US', %w[Azralon Nemesis]
86
+ end
87
+ ```
88
+
89
+ To use the **and** operator you may call `where` or `where_not` multiple times methods.
90
+ ```ruby
91
+ realm = BlizzardApi::Wow.realm
92
+ realm_data = realm.search(1, 100) do |options|
93
+ options.where 'name.en_US', 'Azralon'
94
+ options.where 'id', 3209
95
+ end
96
+ ```
97
+
98
+ To use the **range** operator you may pass a hash to `where` or `where_not`.
99
+ ```ruby
100
+ realm = BlizzardApi::Wow.realm
101
+ realm_data = realm.search(1, 100) do |options|
102
+ options.where 'id', min: 3209, max: 4000, mode: :exclusive
103
+ end
104
+ ```
105
+ *Note*: If you don't pass the `mode` key as `:exclusive` it will be `:inclusive` by default.
106
+
107
+ To **sort** fields you may call the `order_by` method multiple times:
108
+ ```ruby
109
+ realm = BlizzardApi::Wow.realm
110
+ realm_data = realm.search(1, 100) do |options|
111
+ options.where 'id', min: 3209, max: 4000, mode: :exclusive
112
+ options.order_by 'id', :desc
113
+ end
114
+ ```
115
+
76
116
  ## 4. Available endpoints
77
117
 
78
118
  **Hint**: All methods support an additional optional hash parameter that allows you to override the following configurations for a single call:
@@ -34,7 +34,9 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.add_runtime_dependency 'redis', '~> 4.1', '>= 4.1.0'
36
36
 
37
+ spec.add_development_dependency 'dotenv'
37
38
  spec.add_development_dependency 'minitest', '~> 5.0'
38
39
  spec.add_development_dependency 'rake', '~> 13.0'
39
40
  spec.add_development_dependency 'rubocop', '~> 0.61'
41
+ spec.add_development_dependency 'yard'
40
42
  end
@@ -13,13 +13,12 @@ module BlizzardApi
13
13
  ##
14
14
  # Return information about an item
15
15
  #
16
- # @param item_slug [String] Item slug
17
- # @param item_id [Integer] Item id
16
+ # @param item_slug_and_id [String] Item slug
18
17
  # @!macro request_options
19
18
  #
20
19
  # @!macro response
21
- def get(item_slug, item_id, options = {})
22
- api_request "#{base_url(:community)}/data/item/#{item_slug}-#{item_id}", { ttl: CACHE_TRIMESTER }.merge(options)
20
+ def get(item_slug_and_id, options = {})
21
+ api_request "#{base_url(:community)}/data/item/#{item_slug_and_id}", { ttl: CACHE_TRIMESTER }.merge(options)
23
22
  end
24
23
  end
25
24
  end
@@ -22,7 +22,7 @@ module BlizzardApi
22
22
  # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
23
23
  def index(battletag, oauth_token, options = {})
24
24
  opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
25
- api_request "#{base_url(:community)}/data/profile/#{parse_battle_tag(battletag)}", opts
25
+ api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/", opts
26
26
  end
27
27
 
28
28
  ##
@@ -38,7 +38,7 @@ module BlizzardApi
38
38
  # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
39
39
  def hero(battletag, oauth_token, hero_id, options = {})
40
40
  opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
41
- api_request "#{base_url(:community)}/data/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}", opts
41
+ api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}", opts
42
42
  end
43
43
 
44
44
  ##
@@ -54,7 +54,7 @@ module BlizzardApi
54
54
  # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
55
55
  def hero_items(battletag, oauth_token, hero_id, options = {})
56
56
  opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
57
- api_request "#{base_url(:community)}/data/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/items", opts
57
+ api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/items", opts
58
58
  end
59
59
 
60
60
  ##
@@ -70,7 +70,7 @@ module BlizzardApi
70
70
  # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
71
71
  def hero_follower_items(battletag, oauth_token, hero_id, options = {})
72
72
  opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
73
- api_request "#{base_url(:community)}/data/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/follower-items", opts
73
+ api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/follower-items", opts
74
74
  end
75
75
 
76
76
  private
@@ -50,7 +50,8 @@ module BlizzardApi
50
50
  community: 'https://%s.api.blizzard.com/%s',
51
51
  profile: 'https://%s.api.blizzard.com/profile/%s',
52
52
  media: 'https://%s.api.blizzard.com/data/%s/media',
53
- user_profile: 'https://%s.api.blizzard.com/profile/user/%s'
53
+ user_profile: 'https://%s.api.blizzard.com/profile/user/%s',
54
+ search: 'https://%s.api.blizzard.com/data/%s/search'
54
55
  }.freeze
55
56
 
56
57
  ##
@@ -87,7 +88,7 @@ module BlizzardApi
87
88
  def endpoint_namespace(options)
88
89
  case options[:namespace]
89
90
  when :dynamic
90
- "dynamic-#{region}"
91
+ options.include?(:classic) ? "dynamic-classic-#{region}" : "dynamic-#{region}"
91
92
  when :static
92
93
  options.include?(:classic) ? "static-classic-#{region}" : "static-#{region}"
93
94
  when :profile
@@ -2,5 +2,5 @@
2
2
 
3
3
  module BlizzardApi
4
4
  # Gem version
5
- VERSION = '0.3.8'
5
+ VERSION = '0.4.1'
6
6
  end
@@ -5,6 +5,8 @@ module BlizzardApi
5
5
  module Wow
6
6
  require_relative 'wow/request'
7
7
  require_relative 'wow/game_data/generic_data_endpoint'
8
+ require_relative 'wow/search/search_composer'
9
+ require_relative 'wow/search/search_request'
8
10
 
9
11
  # WoW data api
10
12
  require_relative 'wow/game_data/achievement'
@@ -10,6 +10,8 @@ module BlizzardApi
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.connected_realm
12
12
  class ConnectedRealm < Wow::GenericDataEndpoint
13
+ include BlizzardApi::Wow::Searchable
14
+
13
15
  protected
14
16
 
15
17
  def endpoint_setup
@@ -48,9 +48,9 @@ module BlizzardApi
48
48
 
49
49
  protected
50
50
 
51
- def endpoint_uri(variant = nil)
51
+ def endpoint_uri(variant = nil, scope = :game_data)
52
52
  endpoint = variant ? "#{@endpoint}-#{variant}" : @endpoint
53
- "#{base_url(:game_data)}/#{endpoint}"
53
+ "#{base_url(scope)}/#{endpoint}"
54
54
  end
55
55
 
56
56
  def endpoint_setup
@@ -10,6 +10,52 @@ module BlizzardApi
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.pet
12
12
  class Pet < Wow::GenericDataEndpoint
13
+ ##
14
+ # Fetch media for one of the pets listed by the {#index} using its *id*
15
+ #
16
+ # @param id [Integer] Pet id
17
+ #
18
+ # @!macro request_options
19
+ #
20
+ # @!macro response
21
+ def media(id, options = {})
22
+ api_request "#{base_url(:media)}/pet/#{id}", default_options.merge(options)
23
+ end
24
+
25
+ ##
26
+ # Fetch all pet abilities
27
+ #
28
+ # @!macro request_options
29
+ #
30
+ # @!macro response
31
+ def abilities(options = {})
32
+ api_request "#{endpoint_uri('ability')}/index", default_options.merge(options)
33
+ end
34
+
35
+ ##
36
+ # Fetch a pet ability
37
+ #
38
+ # @param id [Integer] Pet id
39
+ #
40
+ # @!macro request_options
41
+ #
42
+ # @!macro response
43
+ def ability(id, options = {})
44
+ api_request "#{endpoint_uri('ability')}/#{id}", default_options.merge(options)
45
+ end
46
+
47
+ ##
48
+ # Fetch media for one of the pet abilities listed by the {#abilities} using its *id*
49
+ #
50
+ # @param id [Integer] Pet ability id
51
+ #
52
+ # @!macro request_options
53
+ #
54
+ # @!macro response
55
+ def ability_media(id, options = {})
56
+ api_request "#{base_url(:media)}/pet-ability/#{id}", default_options.merge(options)
57
+ end
58
+
13
59
  protected
14
60
 
15
61
  def endpoint_setup
@@ -10,6 +10,8 @@ module BlizzardApi
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.realm
12
12
  class Realm < Wow::GenericDataEndpoint
13
+ include BlizzardApi::Wow::Searchable
14
+
13
15
  protected
14
16
 
15
17
  def endpoint_setup
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Composer for search endpoint arguments
7
+ class SearchComposer
8
+ attr_accessor :fields, :order, :page, :page_size
9
+
10
+ def initialize(page, page_size)
11
+ self.page = page
12
+ self.page_size = page_size
13
+ self.fields = []
14
+ self.order = []
15
+ end
16
+
17
+ ##
18
+ # Add a search field
19
+ #
20
+ # The second argument takes a simple value, an array of values or a hash for range searches.
21
+ #
22
+ # @param field [String] Field name
23
+ # @param value [String|Integer|Hash|Array<Integer|String>]
24
+ # @option value [Integer] :min Range start
25
+ # @option value [Integer] :max Range end
26
+ # @option value [Integer] :mode Range mode (:inclusive|:exclusive)
27
+ #
28
+ # @return {SearchComposer}
29
+ def where(field, value)
30
+ fields.push "#{field}=#{resolve_value(value)}"
31
+ self
32
+ end
33
+
34
+ ##
35
+ # Add a search field
36
+ #
37
+ # The second argument takes a simple value, an array of values or a hash for range searches.
38
+ #
39
+ # @param field [String] Field name
40
+ # @param value [String|Integer|Hash|Array<Integer|String>]
41
+ # @option value [Integer] :min Range start
42
+ # @option value [Integer] :max Range end
43
+ # @option value [Integer] :mode Range mode (:inclusive|:exclusive)
44
+ #
45
+ # @return {SearchComposer}
46
+ def where_not(field, value)
47
+ fields.push "#{field}!=#{resolve_value(value)}"
48
+ self
49
+ end
50
+
51
+ ##
52
+ # Add a sort field
53
+ #
54
+ # @param field [String] Field name
55
+ # @param mode [Symbol] :asc or :desc
56
+ #
57
+ # @return {SearchComposer}
58
+ def order_by(field, mode = :asc)
59
+ raise ArgumentError, 'Invalid order mode.' unless %i[asc desc].include? mode
60
+
61
+ order.push "#{field}:#{mode}"
62
+ self
63
+ end
64
+
65
+ ##
66
+ # Returns a valid queryString based on the options
67
+ #
68
+ # @return {String}
69
+ def to_search_query
70
+ query_string = "_page=#{page}&_pageSize=#{page_size}"
71
+ query_string += '&' + fields.join('&') unless fields.size.zero?
72
+ query_string += "&orderby=#{order.join(',')}" unless order.size.zero?
73
+ query_string
74
+ end
75
+
76
+ protected
77
+
78
+ def resolve_value(value)
79
+ return value.join '||' if value.is_a? Array
80
+
81
+ return value.to_s unless value.is_a? Hash
82
+
83
+ resolve_hash value
84
+ end
85
+
86
+ def resolve_hash(value)
87
+ min = value.key?(:min) ? value[:min] : ''
88
+ max = value.key?(:max) ? value[:max] : ''
89
+ mode = value.key?(:mode) ? value[:mode] : :inclusive
90
+
91
+ return "[#{min},#{max}]" if mode.eql? :inclusive
92
+
93
+ "(#{min},#{max})"
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Added search support to an endpoint
7
+ module Searchable
8
+ ##
9
+ # Fetch data base on search criteria
10
+ #
11
+ # @param page [Integer] Page o return
12
+ # @param page_size [Integer] Amount of items per page
13
+ #
14
+ # @!macro request_options
15
+ # @!macro response
16
+ def search(page = 1, page_size = 100, options = {})
17
+ search_options = SearchComposer.new(page, page_size)
18
+ yield search_options if block_given?
19
+
20
+ api_request "#{endpoint_uri(nil, :search)}?#{search_options.to_search_query}", default_options.merge(options)
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,35 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blizzard_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Schiavo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.1.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '4.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
27
30
  - - ">="
28
31
  - !ruby/object:Gem::Version
29
32
  version: 4.1.0
30
- - - "~>"
33
+ - !ruby/object:Gem::Dependency
34
+ name: dotenv
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
31
38
  - !ruby/object:Gem::Version
32
- version: '4.1'
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: minitest
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +86,20 @@ dependencies:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0.61'
89
+ - !ruby/object:Gem::Dependency
90
+ name: yard
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
75
103
  description: This is a simple interface to obtain data from Blizzard API
76
104
  email:
77
105
  - francis.schiavo@francisschiavo.com
@@ -157,6 +185,8 @@ files:
157
185
  - lib/blizzard_api/wow/profile/guild.rb
158
186
  - lib/blizzard_api/wow/profile/profile.rb
159
187
  - lib/blizzard_api/wow/request.rb
188
+ - lib/blizzard_api/wow/search/search_composer.rb
189
+ - lib/blizzard_api/wow/search/search_request.rb
160
190
  homepage: https://gitlab.com/francisschiavo/blizzard_api
161
191
  licenses:
162
192
  - MIT
@@ -179,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
209
  - !ruby/object:Gem::Version
180
210
  version: '0'
181
211
  requirements: []
182
- rubygems_version: 3.0.6
212
+ rubygems_version: 3.1.2
183
213
  signing_key:
184
214
  specification_version: 4
185
215
  summary: Unofficial Ruby client for Blizzard Entertainment API