Module: BnetApi
- Extended by:
- BnetApi
- Includes:
- HTTParty
- Included in:
- BnetApi
- Defined in:
- lib/bnet_api.rb,
lib/bnet_api/d3.rb,
lib/bnet_api/sc2.rb,
lib/bnet_api/wow.rb,
lib/bnet_api/oauth.rb,
lib/bnet_api/version.rb,
lib/bnet_api/wow_data.rb
Overview
The base module namespace for the BnetApi library.
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.0.2'
Instance Method Summary collapse
-
#config ⇒ Object
Sets up the configuration of the API.
-
#configure {|config| ... } ⇒ Object
Yields the API configuration object.
-
#make_request(request, *optional_fields) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API and returns the retrieved data in a hash.
-
#make_request_oauth(request, access_token) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API using OAuth instead of API key authentication and returns the retrieved data in a hash.
-
#make_request_with_params(request, params) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API with some additional URL parameters and returns the retrieved data in a hash.
Instance Method Details
#config ⇒ Object
Sets up the configuration of the API.
22 23 24 |
# File 'lib/bnet_api.rb', line 22 def config @config ||= OpenStruct.new(region: :eu, locale: :en_GB) end |
#configure {|config| ... } ⇒ Object
Yields the API configuration object.
17 18 19 |
# File 'lib/bnet_api.rb', line 17 def configure yield config end |
#make_request(request, *optional_fields) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API and returns the retrieved data in a hash.
31 32 33 |
# File 'lib/bnet_api.rb', line 31 def make_request(request, *optional_fields) self.get("https://#{@config.region}.api.battle.net/#{request}#{build_url_params(optional_fields)}") end |
#make_request_oauth(request, access_token) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API using OAuth instead of API key authentication and returns the retrieved data in a hash.
57 58 59 |
# File 'lib/bnet_api.rb', line 57 def make_request_oauth(request, access_token) self.get("https://#{@config.region}.api.battle.net/#{request}?locale=#{@config.locale}&access_token=#{access_token}") end |
#make_request_with_params(request, params) ⇒ Hash
Sends a HTTPS GET request to the Battle.net API with some additional URL parameters and returns the retrieved data in a hash.
41 42 43 44 45 46 47 48 49 |
# File 'lib/bnet_api.rb', line 41 def make_request_with_params(request, params) url = "https://#{@config.region}.api.battle.net/#{request}?" params.each do |k, v| url += "#{k}=#{v}&" end url += "locale=#{@config.locale}&apikey=#{@config.api_key}" self.get(url) end |