battlenet-api 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/battlenet/api/client.rb +44 -44
- data/lib/battlenet/api/configuration.rb +2 -0
- data/lib/battlenet/api/version.rb +1 -1
- data/spec/client_spec.rb +7 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3ffc4db9dbc65f708fc5e0dafee49ed147af9147399b0d78ad5c48c881a3b6a
|
4
|
+
data.tar.gz: f904105696582f327eb828e65974ada0e28ef4c91075f059710c2bf7bb82cd24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a21c7d05f4676a8256c1ec9e037d71719db80f646b0d1753a5e6b42ad94b72232b7c61dd0b984091c1f88d2f0b3087ea1b0f2e3c983add0a274886269d581d
|
7
|
+
data.tar.gz: 8445140089e4890358b0cb9a9332da4434f001fc4a5580277697dc0cd2b70376f991af76a8dc70c2381a8141062bdfd8459d367221bf45a4ffdb22c25dbad82b
|
data/lib/battlenet/api/client.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
+
def initialize(options={})
|
11
|
+
options = Battlenet.options.merge(options)
|
10
12
|
|
11
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
39
|
+
def endpoint
|
40
|
+
raise "Invalid Game Endpoint" if @endpoint == nil
|
41
|
+
@endpoint
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def get(path, params = {})
|
45
|
+
make_request :get, path, params
|
46
|
+
end
|
51
47
|
|
52
|
-
|
53
|
-
|
48
|
+
def make_request(verb, path, params = {})
|
49
|
+
options = {}
|
50
|
+
headers = {}
|
54
51
|
|
55
|
-
|
56
|
-
|
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
|
-
|
55
|
+
if @api_key
|
56
|
+
options[:query] ||= {}
|
57
|
+
options[:query].merge!({ :apikey => @api_key })
|
61
58
|
end
|
62
59
|
|
63
|
-
|
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
|
data/spec/client_spec.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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.
|
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:
|
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.
|
232
|
+
rubygems_version: 2.7.3
|
233
233
|
signing_key:
|
234
234
|
specification_version: 4
|
235
235
|
summary: Battlenet Client API
|