ugcleague 1.1.1 → 1.2.2
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 +4 -4
- data/.rspec +2 -0
- data/README.md +7 -0
- data/lib/ugcleague/client/players.rb +1 -1
- data/lib/ugcleague/configuration.rb +1 -1
- data/lib/ugcleague/error.rb +0 -2
- data/lib/ugcleague/request.rb +15 -4
- data/lib/ugcleague/version.rb +1 -1
- data/spec/fixtures/player.json +25 -0
- data/spec/fixtures/player_active.json +15 -0
- data/spec/fixtures/player_current.json +15 -0
- data/spec/fixtures/player_exists.json +3 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/ugcleague/client/players_spec.rb +46 -0
- data/spec/ugcleague/client/teams_spec.rb +0 -0
- data/spec/ugcleague/configuration_spec.rb +0 -0
- data/spec/ugcleague/error_spec.rb +0 -0
- data/spec/ugcleague/request_spec.rb +19 -0
- data/spec/ugcleague_spec.rb +63 -0
- data/ugcleague_api.gemspec +6 -0
- metadata +82 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74a0eabdbcc574f7f6a25747678807207ae0e93a
|
4
|
+
data.tar.gz: 38df875c17afc93365c2924edc2393feaa9e83dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64dd37c9f112dc676e6996f636811a98252a59222d341eccf98537ebceb4252d369a9aecb32f8e1ea5a3d393b20c6de58ccbd8772be8e12f00dd79ae3547507
|
7
|
+
data.tar.gz: 2e0a5f21ccc570b31ab0363bb990b87fb17c23000f4401d8dc841e13c9c6a0ecbfdee7866fc8497b84382435b93290f0aaecb3781e04b509d309479e41e17c11
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -26,6 +26,7 @@ require 'ugcleague'
|
|
26
26
|
UGCLeague.configure do |config|
|
27
27
|
config.api_key = "API Key" # Obtain from a UGC admin.
|
28
28
|
config.user_agent = "User agent" # User agent to be sent with the request.
|
29
|
+
config.debug = false # Whether to print debug messages.
|
29
30
|
end
|
30
31
|
```
|
31
32
|
|
@@ -38,6 +39,12 @@ UGCLeague.api_key = "API Key"
|
|
38
39
|
# Set the user agent.
|
39
40
|
UGCLeague.user_agent = "User agent"
|
40
41
|
|
42
|
+
# Set debug.
|
43
|
+
UGCLeague.debug = true
|
44
|
+
|
45
|
+
# Checks if the player has a profile on UGC.
|
46
|
+
UGCLeague.player_has_profile(76561198063808035)
|
47
|
+
|
41
48
|
# Get a player's team history.
|
42
49
|
UGCLeague.player_history(76561198063808035)
|
43
50
|
|
data/lib/ugcleague/error.rb
CHANGED
data/lib/ugcleague/request.rb
CHANGED
@@ -13,10 +13,6 @@ module UGCLeague
|
|
13
13
|
attr_accessor :api_key
|
14
14
|
|
15
15
|
def self.parse(body)
|
16
|
-
case body
|
17
|
-
when "Access denied."; raise Error::Unauthorized.new "Invalid API key"
|
18
|
-
end
|
19
|
-
|
20
16
|
begin
|
21
17
|
JSON.load body
|
22
18
|
rescue JSON::ParserError
|
@@ -27,9 +23,23 @@ module UGCLeague
|
|
27
23
|
def get(options={})
|
28
24
|
options[:key] = @api_key unless !@api_key
|
29
25
|
query_string = Rack::Utils.build_query(options)
|
26
|
+
|
27
|
+
debug_message("GET request for \"http://www.ugcleague.com/api/api.php?#{query_string}\" sent (using useragent \"#{@user_agent}\")")
|
30
28
|
validate self.class.get("http://www.ugcleague.com/api/api.php?#{query_string}")
|
31
29
|
end
|
32
30
|
|
31
|
+
def validate(response)
|
32
|
+
case response.body
|
33
|
+
when "Access denied."; raise Error::Unauthorized.new "Invalid API key"
|
34
|
+
end
|
35
|
+
|
36
|
+
response.parsed_response
|
37
|
+
end
|
38
|
+
|
39
|
+
def debug_message(message)
|
40
|
+
puts "DEBUG: #{message}" if @debug
|
41
|
+
end
|
42
|
+
|
33
43
|
private
|
34
44
|
|
35
45
|
def error_message(response)
|
@@ -41,3 +51,4 @@ module UGCLeague
|
|
41
51
|
|
42
52
|
end
|
43
53
|
end
|
54
|
+
|
data/lib/ugcleague/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"ugc_page": "http://www.ugcleague.com/players_page.cfm?player_id=76561198063808035",
|
3
|
+
"team": [
|
4
|
+
{
|
5
|
+
"name": "Diruo Division",
|
6
|
+
"tag": "_esportsTM",
|
7
|
+
"format": "9v9",
|
8
|
+
"division": "AUS/NZ Platinum",
|
9
|
+
"status": "DR",
|
10
|
+
"last_updated": "2014-07-21 00:00:57",
|
11
|
+
"joined": "2013-08-20 04:51:12",
|
12
|
+
"active": "true"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"name": "Take Five!",
|
16
|
+
"tag": "Take Five, !",
|
17
|
+
"format": "4v4",
|
18
|
+
"division": "Silver N.Amer",
|
19
|
+
"status": "I",
|
20
|
+
"last_updated": "2014-08-20 02:57:59",
|
21
|
+
"joined": "2013-12-23 15:12:38",
|
22
|
+
"active": "false"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"ugc_page": "http://www.ugcleague.com/players_page.cfm?player_id=76561198063808035",
|
3
|
+
"team": [
|
4
|
+
{
|
5
|
+
"name": "Diruo Division",
|
6
|
+
"tag": "_esportsTM",
|
7
|
+
"format": "9v9",
|
8
|
+
"division": "AUS/NZ Platinum",
|
9
|
+
"status": "A",
|
10
|
+
"last_updated": "2014-07-21 00:00:57",
|
11
|
+
"joined": "2013-08-20 04:51:12",
|
12
|
+
"active": "true"
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"ugc_page": "http://www.ugcleague.com/players_page.cfm?player_id=76561198063808035",
|
3
|
+
"team": [
|
4
|
+
{
|
5
|
+
"name": "Diruo Division",
|
6
|
+
"tag": "_esportsTM",
|
7
|
+
"format": "9v9",
|
8
|
+
"division": "AUS/NZ Platinum",
|
9
|
+
"status": "HP",
|
10
|
+
"last_updated": "2014-07-21 00:00:57",
|
11
|
+
"joined": "2013-08-20 04:51:12",
|
12
|
+
"active": "true"
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
def load_fixture(fixture)
|
5
|
+
File.new(File.dirname(__FILE__) + "/fixtures/#{fixture}.json")
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.expand_path("../../lib/ugcleague", __FILE__)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
end
|
12
|
+
|
13
|
+
def stub_get(url, fixture)
|
14
|
+
stub_request(:get, "http://www.ugcleague.com#{url}")
|
15
|
+
.with(:headers => {:Accept => 'application/json'})
|
16
|
+
.to_return(:body => load_fixture(fixture))
|
17
|
+
end
|
18
|
+
|
19
|
+
def a_get(url)
|
20
|
+
a_request(:get, "http://www.ugcleague.com#{url}")
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UGCLeague::Client do
|
4
|
+
|
5
|
+
describe "#player_has_profile" do
|
6
|
+
before do
|
7
|
+
stub_get("/api/api.php?exists=123", "player_exists")
|
8
|
+
@player = UGCLeague.player_has_profile(123)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the correct resource" do
|
12
|
+
expect(a_get("/api/api.php?exists=123")).to have_been_made
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return a hash" do
|
16
|
+
expect(@player).to be_a Hash
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#player_history" do
|
21
|
+
before do
|
22
|
+
stub_get("/api/api.php?player=123", "player")
|
23
|
+
@player = UGCLeague.player_history(123)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the correct resource" do
|
27
|
+
expect(a_get("/api/api.php?player=123")).to have_been_made
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return a hash" do
|
31
|
+
expect(@player).to be_a Hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#player_current" do
|
36
|
+
before do
|
37
|
+
stub_get("/api/api.php?active=123", "player_active")
|
38
|
+
@player = UGCLeague.player_current(123)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the correct resource" do
|
42
|
+
expect(a_get("/api/api.php?active=123")).to have_been_made
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UGCLeague::Request do
|
4
|
+
|
5
|
+
it { should respond_to :get }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@request = UGCLeague::Request.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#parse" do
|
12
|
+
it "should return JSON" do
|
13
|
+
body = "{\"exists\": true}"
|
14
|
+
expect(UGCLeague::Request.parse(body)).to be_a Hash
|
15
|
+
expect { UGCLeague::Request.parse("Not JSON") }.to raise_error(UGCLeague::Error::Parsing)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UGCLeague do
|
4
|
+
after { UGCLeague.reset }
|
5
|
+
|
6
|
+
describe "#client" do
|
7
|
+
|
8
|
+
it "should be a UGCLeague::Client" do
|
9
|
+
expect(UGCLeague.client).to be_a UGCLeague::Client
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not override other clients" do
|
13
|
+
client_1 = UGCLeague.client(api_key: '001', user_agent: 'Client 1')
|
14
|
+
client_2 = UGCLeague.client(api_key: '002', user_agent: 'Client 2')
|
15
|
+
|
16
|
+
expect(client_1.api_key).to eq('001')
|
17
|
+
expect(client_2.api_key).to eq('002')
|
18
|
+
|
19
|
+
expect(client_1.user_agent).to eq('Client 1')
|
20
|
+
expect(client_2.user_agent).to eq('Client 2')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#api_key=" do
|
26
|
+
it "should set the api key" do
|
27
|
+
UGCLeague.api_key = '123'
|
28
|
+
expect(UGCLeague.api_key).to eq('123')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#user_agent=" do
|
33
|
+
it "should set the user agent" do
|
34
|
+
UGCLeague.user_agent = 'Test'
|
35
|
+
expect(UGCLeague.user_agent).to eq('Test')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#user_agent" do
|
40
|
+
it "should return the default user agent" do
|
41
|
+
expect(UGCLeague.user_agent).to eq(UGCLeague::Configuration::DEFAULT_USER_AGENT)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#debug=" do
|
46
|
+
it "should set the debug option" do
|
47
|
+
UGCLeague.debug = true
|
48
|
+
expect(UGCLeague.debug).to eq(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#configure" do
|
53
|
+
UGCLeague::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
54
|
+
it "should set #{key}" do
|
55
|
+
UGCLeague.configure do |config|
|
56
|
+
config.send("#{key}=", key)
|
57
|
+
expect(UGCLeague.send(key)).to eq(key)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/ugcleague_api.gemspec
CHANGED
@@ -12,7 +12,13 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.homepage = "https://github.com/Ranndom/UGCLeague"
|
13
13
|
|
14
14
|
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec)/})
|
15
16
|
gem.require_paths = ["lib"]
|
16
17
|
|
17
18
|
gem.add_runtime_dependency 'httparty'
|
19
|
+
gem.add_runtime_dependency "rack"
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'webmock'
|
18
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ugcleague
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ranndom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
27
83
|
description: Ruby client for UGC League API
|
28
84
|
email:
|
29
85
|
- Ranndom@rnndm.xyz
|
@@ -31,6 +87,7 @@ executables: []
|
|
31
87
|
extensions: []
|
32
88
|
extra_rdoc_files: []
|
33
89
|
files:
|
90
|
+
- ".rspec"
|
34
91
|
- Gemfile
|
35
92
|
- README.md
|
36
93
|
- Rakefile
|
@@ -42,6 +99,17 @@ files:
|
|
42
99
|
- lib/ugcleague/error.rb
|
43
100
|
- lib/ugcleague/request.rb
|
44
101
|
- lib/ugcleague/version.rb
|
102
|
+
- spec/fixtures/player.json
|
103
|
+
- spec/fixtures/player_active.json
|
104
|
+
- spec/fixtures/player_current.json
|
105
|
+
- spec/fixtures/player_exists.json
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/ugcleague/client/players_spec.rb
|
108
|
+
- spec/ugcleague/client/teams_spec.rb
|
109
|
+
- spec/ugcleague/configuration_spec.rb
|
110
|
+
- spec/ugcleague/error_spec.rb
|
111
|
+
- spec/ugcleague/request_spec.rb
|
112
|
+
- spec/ugcleague_spec.rb
|
45
113
|
- ugcleague_api.gemspec
|
46
114
|
homepage: https://github.com/Ranndom/UGCLeague
|
47
115
|
licenses: []
|
@@ -66,4 +134,15 @@ rubygems_version: 2.4.5.1
|
|
66
134
|
signing_key:
|
67
135
|
specification_version: 4
|
68
136
|
summary: Ruby client for UGC League API
|
69
|
-
test_files:
|
137
|
+
test_files:
|
138
|
+
- spec/fixtures/player.json
|
139
|
+
- spec/fixtures/player_active.json
|
140
|
+
- spec/fixtures/player_current.json
|
141
|
+
- spec/fixtures/player_exists.json
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/ugcleague/client/players_spec.rb
|
144
|
+
- spec/ugcleague/client/teams_spec.rb
|
145
|
+
- spec/ugcleague/configuration_spec.rb
|
146
|
+
- spec/ugcleague/error_spec.rb
|
147
|
+
- spec/ugcleague/request_spec.rb
|
148
|
+
- spec/ugcleague_spec.rb
|