ugcleague 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/ugcleague/api.rb +14 -0
- data/lib/ugcleague/client/players.rb +13 -0
- data/lib/ugcleague/client.rb +9 -0
- data/lib/ugcleague/configuration.rb +30 -0
- data/lib/ugcleague/error.rb +11 -0
- data/lib/ugcleague/request.rb +51 -0
- data/lib/ugcleague/version.rb +3 -0
- data/lib/ugcleague.rb +24 -0
- data/ugcleague_api.gemspec +18 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2186fb5e3d34ef40101b0855c86da380c7ee4ce
|
4
|
+
data.tar.gz: 6e831cf17c5e237b88bdd133028a7cd3f7ccb29d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2e6407178c24277aae13d11f9b2f6bb0b9098e80a8a8138d594a62c91aa3e0f91545defa771266a1519099a7365e01b4adc12864b64ee5e51788ff3b1779bf7
|
7
|
+
data.tar.gz: e11d3a0db720174c2cd65b921ffdae69561c239fe2c511571801179c6dadb1aaf74dc03478968047765da8df746b390c3a76d440ce26fe8e9129e40e22472cfd
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# UGC League
|
2
|
+
|
3
|
+
UGCLeague is a Ruby client for the UGC League API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it from RubyGems:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install ugcleague
|
11
|
+
```
|
12
|
+
|
13
|
+
Or add it to a Gemfile:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem 'ugcleague'
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Configuration:
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'ugcleague'
|
25
|
+
|
26
|
+
UGC.configure do |config|
|
27
|
+
config.api_key = "API Key" # Obtain from a UGC admin.
|
28
|
+
config.user_agent = "User agent" # User agent to be sent with the request.
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Examples:
|
33
|
+
|
34
|
+
```
|
35
|
+
# Set the API key.
|
36
|
+
UGC.api_key = "API Key"
|
37
|
+
|
38
|
+
# Set the user agent.
|
39
|
+
UGC.user_agent = "User agent"
|
40
|
+
|
41
|
+
# Get a player's team history.
|
42
|
+
UGC.player_history(76561198063808035)
|
43
|
+
|
44
|
+
# Get a player's current team.
|
45
|
+
UGC.player_current(76561198063808035)
|
46
|
+
```
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module UGC
|
2
|
+
class API < Request
|
3
|
+
|
4
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
options = UGC.options.merge(options)
|
8
|
+
(Configuration::VALID_OPTIONS_KEYS).each do |key|
|
9
|
+
send("#{key}=", options[key]) if options[key]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UGC
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
VALID_OPTIONS_KEYS = [:api_key, :user_agent].freeze
|
5
|
+
|
6
|
+
DEFAULT_USER_AGENT = "UGC League Ruby Gem #{UGC::VERSION}".freeze
|
7
|
+
|
8
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
9
|
+
|
10
|
+
def self.extended(base)
|
11
|
+
base.reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
20
|
+
option.merge!(key => send(key))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset
|
25
|
+
self.api_key = ENV['UGC_LEAGUE_API_KEY']
|
26
|
+
self.user_agent = DEFAULT_USER_AGENT
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'rack'
|
4
|
+
|
5
|
+
module UGC
|
6
|
+
class Request
|
7
|
+
|
8
|
+
include HTTParty
|
9
|
+
format :json
|
10
|
+
headers 'Accept' => 'application/json'
|
11
|
+
parser Proc.new { |body, _| parse(body) }
|
12
|
+
|
13
|
+
attr_accessor :api_key
|
14
|
+
|
15
|
+
def self.parse(body)
|
16
|
+
case body
|
17
|
+
when "Access denied."; raise Error::Unauthorized.new "Invalid API key"
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
JSON.load body
|
22
|
+
rescue JSON::ParserError
|
23
|
+
raise Error::Parsing.new "The response is not valid JSON"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(options={})
|
28
|
+
options[:key] = @api_key unless !@api_key
|
29
|
+
query_string = Rack::Utils.build_query(options)
|
30
|
+
validate self.class.get("http://www.ugcleague.com/api/api.php?#{query_string}")
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate(response)
|
36
|
+
case response.body
|
37
|
+
when "Access denied."; raise Error::Unauthorized.new error_message(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
response.parsed_response
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_message(response)
|
44
|
+
parsed_response = response.parsed_response
|
45
|
+
|
46
|
+
"Server responded with code #{response.code}. " \
|
47
|
+
"Request URI: #{response.request.base_uri}#{response.request.path}"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/ugcleague.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ugcleague/version'
|
2
|
+
require 'ugcleague/configuration'
|
3
|
+
require 'ugcleague/error'
|
4
|
+
require 'ugcleague/request'
|
5
|
+
require 'ugcleague/api'
|
6
|
+
require 'ugcleague/client'
|
7
|
+
|
8
|
+
module UGC
|
9
|
+
extend Configuration
|
10
|
+
|
11
|
+
def self.client(options={})
|
12
|
+
UGC::Client.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.method_missing(method, *args, &block)
|
16
|
+
return super unless client.respond_to?(method)
|
17
|
+
client.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.respond_to?(method)
|
21
|
+
return client.respond_to?(method) || super
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'ugcleague/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "ugcleague"
|
7
|
+
gem.version = UGC::VERSION
|
8
|
+
gem.authors = ["Ranndom"]
|
9
|
+
gem.email = ["Ranndom@rnndm.xyz"]
|
10
|
+
gem.description = %q{Ruby client for UGC League API}
|
11
|
+
gem.summary = %q{Ruby client for UGC League API}
|
12
|
+
gem.homepage = "https://github.com/Ranndom/UGCLeague"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'httparty'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ugcleague
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ranndom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Ruby client for UGC League API
|
28
|
+
email:
|
29
|
+
- Ranndom@rnndm.xyz
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/ugcleague.rb
|
38
|
+
- lib/ugcleague/api.rb
|
39
|
+
- lib/ugcleague/client.rb
|
40
|
+
- lib/ugcleague/client/players.rb
|
41
|
+
- lib/ugcleague/configuration.rb
|
42
|
+
- lib/ugcleague/error.rb
|
43
|
+
- lib/ugcleague/request.rb
|
44
|
+
- lib/ugcleague/version.rb
|
45
|
+
- ugcleague_api.gemspec
|
46
|
+
homepage: https://github.com/Ranndom/UGCLeague
|
47
|
+
licenses: []
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.4.5.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Ruby client for UGC League API
|
69
|
+
test_files: []
|