battlenet-api 1.1.0 → 1.2.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
- SHA1:
3
- metadata.gz: d94d64ac8a17ab60791a9866ce0a6931da5fa830
4
- data.tar.gz: 276fb263625a13ee0bc8e817de74764ed343f18f
2
+ SHA256:
3
+ metadata.gz: c3ffc4db9dbc65f708fc5e0dafee49ed147af9147399b0d78ad5c48c881a3b6a
4
+ data.tar.gz: f904105696582f327eb828e65974ada0e28ef4c91075f059710c2bf7bb82cd24
5
5
  SHA512:
6
- metadata.gz: e8d39c4264f3b883cd17594bbdba711ce268191c714c97c47e925fb3e55d97077f76494f9eaca6fdad343c0f66396ef19374edf792a4e49a8541703dc5c701de
7
- data.tar.gz: 6d2bb6ea3f5b49229c396daa233d30855fcd0c3aef22e5fd7757331a0eed4844817a2d59e3245170aa25a5aa29403502b6278d17c2acceb3f9ea595aecf3601d
6
+ metadata.gz: 34a21c7d05f4676a8256c1ec9e037d71719db80f646b0d1753a5e6b42ad94b72232b7c61dd0b984091c1f88d2f0b3087ea1b0f2e3c983add0a274886269d581d
7
+ data.tar.gz: 8445140089e4890358b0cb9a9332da4434f001fc4a5580277697dc0cd2b70376f991af76a8dc70c2381a8141062bdfd8459d367221bf45a4ffdb22c25dbad82b
@@ -4,62 +4,62 @@ require 'httparty'
4
4
  require 'addressable/uri'
5
5
 
6
6
  module Battlenet
7
+ class Client
8
+ attr_accessor *Configuration::OPTIONS_KEYS
7
9
 
8
- class Client
9
- include HTTParty
10
+ def initialize(options={})
11
+ options = Battlenet.options.merge(options)
10
12
 
11
- attr_accessor *Configuration::OPTIONS_KEYS
12
-
13
- def initialize(options={})
14
- options = Battlenet.options.merge(options)
15
-
16
- Configuration::OPTIONS_KEYS.each do |key|
17
- send("#{key}=", options[key])
18
- end
19
- self.class.base_uri "https://#{domain}#{endpoint}"
13
+ Configuration::OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
20
15
  end
16
+ end
21
17
 
22
- def domain
23
- domain = case @region
24
- when :us
25
- 'us.api.battle.net'
26
- when :eu
27
- 'eu.api.battle.net'
28
- when :kr
29
- 'kr.api.battle.net'
30
- when :tw
31
- 'tw.api.battle.net'
32
- when :cn
33
- 'api.battlenet.com.cn'
34
- else
35
- raise "Invalid region: #{region.to_s}"
36
- end
37
- end
18
+ def base_uri
19
+ "https://#{domain}#{endpoint}"
20
+ end
38
21
 
39
- def endpoint
40
- raise "Invalid Game Endpoint" if @endpoint == nil
41
- @endpoint
22
+ def domain
23
+ domain = case @region
24
+ when :us
25
+ 'us.api.battle.net'
26
+ when :eu
27
+ 'eu.api.battle.net'
28
+ when :kr
29
+ 'kr.api.battle.net'
30
+ when :tw
31
+ 'tw.api.battle.net'
32
+ when :cn
33
+ 'api.battlenet.com.cn'
34
+ else
35
+ raise "Invalid region: #{region.to_s}"
42
36
  end
37
+ end
43
38
 
44
- def get(path, params = {})
45
- make_request :get, path, params
46
- end
39
+ def endpoint
40
+ raise "Invalid Game Endpoint" if @endpoint == nil
41
+ @endpoint
42
+ end
47
43
 
48
- def make_request(verb, path, params = {})
49
- options = {}
50
- headers = {}
44
+ def get(path, params = {})
45
+ make_request :get, path, params
46
+ end
51
47
 
52
- options[:headers] = headers unless headers.empty?
53
- options[:query] = params unless params.empty?
48
+ def make_request(verb, path, params = {})
49
+ options = {}
50
+ headers = {}
54
51
 
55
- if @api_key
56
- options[:query] ||= {}
57
- options[:query].merge!({ :apikey => @api_key })
58
- end
52
+ options[:headers] = headers unless headers.empty?
53
+ options[:query] = params unless params.empty?
59
54
 
60
- response = self.class.send(verb, Addressable::URI.encode(path), options)
55
+ if @api_key
56
+ options[:query] ||= {}
57
+ options[:query].merge!({ :apikey => @api_key })
61
58
  end
62
59
 
63
- end
60
+ encoded_path = Addressable::URI.encode(path)
64
61
 
62
+ response = HTTParty.send(verb, "#{base_uri}#{encoded_path}" , options)
63
+ end
64
+ end
65
65
  end
@@ -4,12 +4,14 @@ module Battlenet
4
4
  OPTIONS_KEYS = [
5
5
  :api_key,
6
6
  :region,
7
+ :locale,
7
8
  :endpoint
8
9
  ].freeze
9
10
 
10
11
  DEFAULT_API_KEY = nil
11
12
  DEFAULT_ENDPOINT = nil
12
13
  DEFAULT_REGION = :us
14
+ DEFAULT_LOCALE = :en_US
13
15
 
14
16
  attr_accessor *OPTIONS_KEYS
15
17
 
@@ -1,5 +1,5 @@
1
1
  module Battlenet
2
2
  module Api
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -1,13 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Battlenet::Client do
4
+ it 'is expected not to override API url when creating multiple clients' do
5
+ eu_client = Battlenet::Client.new(api_key: 'api_key', region: :eu, endpoint: '/wow')
6
+ expect(eu_client.base_uri).to eq 'https://eu.api.battle.net/wow'
4
7
 
5
- before do
6
- Battlenet.configure do |config|
7
- config.api_key = ENV['BATTLENET_API_KEY']
8
- config.region = :us
9
- end
10
- @client = Battlenet::Client.new
8
+ us_client = Battlenet::Client.new(api_key: 'api_key', region: :us, endpoint: '/wow')
9
+ expect(us_client.base_uri).to eq 'https://us.api.battle.net/wow'
10
+
11
+ expect(eu_client.base_uri).to eq 'https://eu.api.battle.net/wow'
11
12
  end
12
13
 
13
14
  # it "should translate foreign characters for URLS (whispä)" do
@@ -17,5 +18,4 @@ describe Battlenet::Client do
17
18
  # it "should translate spaces accurately for URLS (emerald dream)" do
18
19
  # character = @client.character({:realm => 'emerald dream', :character_name => 'pftpft'})
19
20
  # end
20
-
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battlenet-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - goodcodeguy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  version: '0'
230
230
  requirements: []
231
231
  rubyforge_project:
232
- rubygems_version: 2.6.13
232
+ rubygems_version: 2.7.3
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Battlenet Client API