blizzard_api 0.3.11 → 0.4.0

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: 0d749ca8885288890aa3fd989b55d761520775a0187bc395802152d09a27b57d
4
- data.tar.gz: b9da4c8d1aa1c505737a258780e80db4c41a0ea789fef38b7d673cdd5ad3a29b
3
+ metadata.gz: ba9df0ce8e6bc1398057fa55eae73f4081d370f13d204f0d6f2eccb313f3bed2
4
+ data.tar.gz: 5f3d190b6d324c45b456ccd856b6271b6e2447816930b7e451aa7fa325c85d98
5
5
  SHA512:
6
- metadata.gz: 2320bad31262928a97d77ddf5092ad86a80278ac88572be33a9f252aa639d99973a8c3554b786f3c95fc9a05be0aba099412038eaee56bda11a9e6414221ff40
7
- data.tar.gz: 7a9df7fb947da25b9e5ae4e19c6384acfe3f5111f6d4ca2615f4ab87ee80cdfde25bb7cbebde597e2c5bebe4b303a661605e6ff51ef68860c24c07895883c844
6
+ metadata.gz: aa67738363d505b469eeb89c5fcc140fe2bbd8834c3be1afd588ba1a7ae9ac79347409bfdecad97a7a24ea1c427b70a5b4f3812b8d838d11c5b41bb34916bc09
7
+ data.tar.gz: 6489a58fc1132f50ccd977f0ad4dff408997c9fff80be0d38b7e5d43602287c99490af2604b6bed7a913baa22ad701189fe9eb366a58b39b1266b57a275df73d
@@ -1,5 +1,11 @@
1
1
  Please view this file on the master branch, otherwise it may be outdated
2
2
 
3
+ **Version 0.4.0**
4
+
5
+ Added support to searchable endpoints
6
+
7
+ https://develop.battle.net/documentation/world-of-warcraft/guides/search
8
+
3
9
  **Version 0.3.11**
4
10
 
5
11
  Fixed D3 item URL.
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blizzard_api (0.3.11)
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,7 +13,7 @@ module BlizzardApi
13
13
  ##
14
14
  # Return information about an item
15
15
  #
16
- # @param item_slug [String] Item slug
16
+ # @param item_slug_and_id [String] Item slug
17
17
  # @!macro request_options
18
18
  #
19
19
  # @!macro response
@@ -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
  ##
@@ -2,5 +2,5 @@
2
2
 
3
3
  module BlizzardApi
4
4
  # Gem version
5
- VERSION = '0.3.11'
5
+ VERSION = '0.4.0'
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,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.11
4
+ version: 0.4.0
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-08 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