gosu_api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/generators/gosu_api/install/install_generator.rb +15 -0
- data/lib/generators/gosu_api/install/templates/gosu_api.rb +3 -0
- data/lib/gosu_api.rb +4 -0
- data/lib/gosu_api/configuration.rb +9 -0
- data/lib/gosu_api/exceptions/forbidden_error.rb +9 -0
- data/lib/gosu_api/gosu_api.rb +25 -0
- data/lib/gosu_api/matchticker.rb +60 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e06c4c771e58085ebd79e58c8b79f593ff498831
|
4
|
+
data.tar.gz: d348830bbb3aaf3b88aed512baaa4349de2402e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36853f50840082c79ab1e07a24f34e46f1a25d62733a611c4fe8909277ce763b217143b0aca524c228ba72b9602429d5467c25e96b111e7f9cd0b4a387c5b102
|
7
|
+
data.tar.gz: c6f1024687908ccf369f278cd077a4d1e417256fcf3a791ca5e45871b6fbda892f8cd142d0539926a4bc918b8205539d3187409034110d876dd0020cd87bb2cf
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GosuApi
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
copy_file 'gosu_api.rb', 'config/initializers/gosu_api.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/gosu_api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module GosuApi
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(self.configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
ENDPOINT = 'http://www.gosugamers.net/api/'
|
16
|
+
GAMES = {
|
17
|
+
:counterstrike => 'counterstrike',
|
18
|
+
:dota2 => 'dota2',
|
19
|
+
:hearthstone => 'hearthstone',
|
20
|
+
:heroesofthestorm => 'heroesofthestorm',
|
21
|
+
:lol => 'lol',
|
22
|
+
:overwatch => 'overwatch',
|
23
|
+
:sc2 => 'starcraft2'
|
24
|
+
}
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module GosuApi
|
6
|
+
class Matchticker
|
7
|
+
|
8
|
+
##
|
9
|
+
# Fetch a list of matches
|
10
|
+
#
|
11
|
+
# ==== Attributes
|
12
|
+
#
|
13
|
+
# * +game+ - The game you want to pull matches for
|
14
|
+
# * +max_results+ - The max amount of results you want to pull
|
15
|
+
# * +offset+ - The offset from where you want to start pulling data
|
16
|
+
# * +date_from+ - From which date you'd like to start pulling data
|
17
|
+
# * +date_to+ - Until which date you'd like to start pulling data
|
18
|
+
#
|
19
|
+
def get_matches(game = nil, max_results = 25, offset = 0, date_from = nil, date_to = nil)
|
20
|
+
method = 'matches'
|
21
|
+
parameters = {}
|
22
|
+
|
23
|
+
raise ArgumentError.new("Max results is out of range. This parameter should not exceed 25 results.") if max_results < 1 || max_results > 25
|
24
|
+
raise ArgumentError.new("Offset is out of range.") if offset < 0
|
25
|
+
|
26
|
+
if game
|
27
|
+
raise ArgumentError.new("This game is not a part of the Gosu Matchticker API.") unless GosuApi::GAMES.has_key?(game.to_sym)
|
28
|
+
parameters['game'] = GosuApi::GAMES[game.to_sym]
|
29
|
+
end
|
30
|
+
|
31
|
+
if date_from
|
32
|
+
raise ArgumentError.new("The date_from provided should be in the DD-MM-YYYY format.") unless date_from.is_a?(DateTime)
|
33
|
+
parameters['dateFrom'] = date_from.strftime("%d-%m-%Y")
|
34
|
+
end
|
35
|
+
|
36
|
+
if date_to
|
37
|
+
raise ArgumentError.new("The date_to provided should be in the DD-MM-YYYY format.") unless date_to.is_a?(DateTime)
|
38
|
+
parameters['dateTo'] = date_to.strftime("%d-%m-%Y")
|
39
|
+
end
|
40
|
+
|
41
|
+
parameters['maxResults'] = max_results
|
42
|
+
parameters['offset'] = offset
|
43
|
+
|
44
|
+
api_result = send_request(method, parameters)
|
45
|
+
api_result["matches"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def send_request(method, parameters = {})
|
49
|
+
parameters["apiKey"] = GosuApi.configuration.api_key
|
50
|
+
result = RestClient.get "#{GosuApi::ENDPOINT}#{method}?#{URI.encode_www_form(parameters)}"
|
51
|
+
case result.code
|
52
|
+
when 200
|
53
|
+
return JSON.parse result
|
54
|
+
when 403
|
55
|
+
raise GosuApi::Exception::ForbiddenError.new(result.to_str)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gosu_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Dorresteijn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: GosuAPI is a gem created to communicate with the GosuGamers.net Matchticker.
|
42
|
+
email: stefan@refreshseo.nl
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/generators/gosu_api/install/install_generator.rb
|
48
|
+
- lib/generators/gosu_api/install/templates/gosu_api.rb
|
49
|
+
- lib/gosu_api.rb
|
50
|
+
- lib/gosu_api/configuration.rb
|
51
|
+
- lib/gosu_api/exceptions/forbidden_error.rb
|
52
|
+
- lib/gosu_api/gosu_api.rb
|
53
|
+
- lib/gosu_api/matchticker.rb
|
54
|
+
homepage: https://github.com/StefanDorresteijn/GosuAPI
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Gem for communicating with the GosuGamers.net API
|
78
|
+
test_files: []
|