rts 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba96568f7ee8fa1f0c87b28b269719dbb13f18beb45dbc0f7b69e81dc56e24de
4
+ data.tar.gz: 31f73188d7b671a50985342ff643de0fc17885a61fd5e173560590e824530f64
5
+ SHA512:
6
+ metadata.gz: abd797ffe191d7c57559232c7271832710c73780ff0e2615401aa37c5b050dad28c6c822388b4b15f03692351ac84222156d2a0ed7833bc155afa1703e9ac119
7
+ data.tar.gz: 874527101251c8243ccf8867f2781f7fd3e1df194877cd723940398eaab0979129e7fea69a5c9b542c55e18e85bc8fc79858231be4ff5cdd62a02d5bfd2e0fcd
data/lib/rts.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rts/version'
4
+ require 'rts/api/static_sport_event_information'
5
+ require 'rts/api/live_sport_event_information'
6
+ require 'rts/request'
7
+ require 'rts/client'
8
+ require 'rts/error'
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Api
4
+ module LiveSportEventInformation
5
+ # LIVE MATCHES
6
+ # Currently available matches.
7
+ # GET/{sport}/live/matches{?league_id,tournament_id,series_id}
8
+ def live_matches(sport:, league_id: nil, tournament_id: nil, series_id: nil)
9
+ get("#{sport}/live/matches?league_id=#{league_id}&tournament_id=#{tournament_id}&series_id=#{series_id}")
10
+ end
11
+
12
+ # MATCH STATE
13
+ # Current live match state. Resource always shows last sequence state,
14
+ # if you don't set it. It provides complete match state for sequence,
15
+ # so you can reconstruct your data, when you miss a lot of sequences.
16
+ # GET/{sport}/live/matches/{id}/state{?sequence,expand}
17
+ def live_match_state(sport:, id:, sequence: nil, expand: nil)
18
+ get("#{sport}/live/matches/#{id}/state?sequence=#{sequence}&expand=#{expand}")
19
+ end
20
+
21
+ # MATCH FEED
22
+ # Current live match feed. Resource always shows last sequence delta against previous one,
23
+ # if you don't request specific one. Delta sequence represents changed markets and match info.
24
+ # GET/{sport}/live/matches/{id}/feed{?sequence}
25
+ def live_match_feed(sport:, id:, sequence: nil)
26
+ get("#{sport}/live/matches/#{id}/feed?sequence=#{sequence}")
27
+ end
28
+
29
+ # MATCH STATISTICS
30
+ # Current live match statistics. Resource always shows last sequence state,
31
+ # if you don't set it. It provides complete match state for sequence,
32
+ # so you can reconstruct your data, when you miss a lot of sequences.
33
+ # GET/{sport}/live/matches/{id}/statistics/state{?sequence,expand}
34
+
35
+ def live_match_statistics_state(sport:, id:, sequence: nil, expand: nil)
36
+ get("#{sport}/live/matches/#{id}/statistics/state?sequence=#{sequence}?expand=#{expand}")
37
+ end
38
+
39
+ # MATCH STATISTICS FEED
40
+ # Current live match statistics feed. Resource always shows last sequence delta against previous one,
41
+ # if you don't request specific one. Delta sequence represents changed markets and match info.
42
+ # GET/{sport}/live/matches/{id}/statistics/feed{?sequence}
43
+ def live_match_statistics_feed(sport:, id:, sequence: nil)
44
+ get("#{sport}/live/matches/#{id}/statistics/feed?sequence=#{sequence}")
45
+ end
46
+
47
+ # STATISTICS STATES
48
+ # List all statistics states.
49
+ # GET/{sport}/statistics/states
50
+ def statistics_states(sport:)
51
+ get("#{sport}/statistics/states")
52
+ end
53
+
54
+ # LIVE SERIES
55
+ # Currently available live series.
56
+ # GET/{sport}/live/series{?league_id,tournament_id}
57
+ def live_series(sport:, league_id: nil, tournament_id: nil)
58
+ get("#{sport}/live/series?league_id=#{league_id}&tournament_id=#{tournament_id}")
59
+ end
60
+
61
+ # SERIES STATE
62
+ # Current live series state. Resource always shows last sequence state, if you don't set it.
63
+ # GET/{sport}/live/series/{id}/state{?sequence,expand}
64
+ def live_series_state(sport:, id:, sequence: nil, expand: nil)
65
+ get("#{sport}/live/series/#{id}/state?sequence=#{sequence}&expand=#{expand}")
66
+ end
67
+ # SERIES FEED
68
+ # Current live series feed. Resource always shows last sequence delta against previous one,
69
+ # if you don't request specific one. Delta sequence represents changed markets.
70
+ # GET/{sport}/live/series/{id}/feed{?sequence}
71
+
72
+ def live_series_feed(sport:, id:, sequence: nil)
73
+ get("#{sport}/live/series/#{id}/feed?sequence=#{sequence}")
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Api
4
+ module StaticSportEventInformation
5
+ # Currently available sports.
6
+ # GET /sports
7
+ def sports
8
+ get('sports')
9
+ end
10
+
11
+ # Currently available leagues.
12
+ # GET /{sport}/leagues
13
+ def leagues(sport:)
14
+ get("#{sport}/leagues")
15
+ end
16
+
17
+ # List Available teams
18
+ # GET /{sport}/teams
19
+ def teams(sport:)
20
+ get("#{sport}/teams")
21
+ end
22
+
23
+ # PLAYERS
24
+ # GET /{sport}/players{?team_id} List Available players
25
+ # team_id: number (optional), Example: 1, Filter players by team id
26
+ # sport: string (required), Example: lol
27
+ def players(sport:, team_id: nil)
28
+ get("#{sport}/players?team_id=#{team_id}")
29
+ end
30
+
31
+ # TOURNAMENTS
32
+ # Currently available tournaments.
33
+ # GET/{sport}/tournaments{?date_from,date_to}
34
+ # Example URI
35
+ # GET /lol/tournaments?date_from=2016-01-16 00:00:00Z
36
+ # &date_to=2016-01-1600:00:00Z
37
+ # URI ParametersHide
38
+ # date_from
39
+ # date (optional) Example: 2016-01-16 00:00:00Z
40
+ # date_to
41
+ # date (optional) Example: 2016-01-16 00:00:00Z
42
+ # sport
43
+ # string (required) Example: lol
44
+ def tournaments(sport:, date_from: nil, date_to: nil)
45
+ get("#{sport}/tournaments?date_from=#{date_from}&date_to=#{date_to}")
46
+ end
47
+
48
+ # TOURNAMENT TIERS
49
+ # List all possible tournament tiers.
50
+ # GET/{sport}/tournament/tiers
51
+ # Tournament tiers by tier id
52
+ # GET/{sport}/tournament/tiers/{id}
53
+ def tournament_tiers(sport:, id: nil)
54
+ get("#{sport}/tournament/tiers/#{id}")
55
+ end
56
+
57
+ # Series
58
+ # GET/{sport}/series{?tournament_id}
59
+ def series(sport:, tournament_id: nil)
60
+ get("#{sport}/series?tournament_id=#{tournament_id}")
61
+ end
62
+
63
+ # Series types
64
+ # List All Series types
65
+ # GET/{sport}/series/types
66
+ def series_type(sport:)
67
+ get("#{sport}/series/types")
68
+ end
69
+
70
+ # SERIES STATES
71
+ # List all possible series states.
72
+ # GET/{sport}/series/states
73
+ def series_states(sport:, id: nil)
74
+ get("#{sport}/series/states/#{id}")
75
+ end
76
+
77
+ # MATCHES
78
+ # Matches for series. Shows only closed and resolved matches.
79
+ # List All Matches in Series
80
+ # GET/{sport}/matches{?tournament_id,series_id,league_id}
81
+ def matches(sport:, tournament_id: nil, series_id: nil, league_id: nil)
82
+ get("#{sport}/matches?tournament_id=#{tournament_id}&series_id=#{series_id}&league_id=#{league_id}")
83
+ end
84
+
85
+ # MATCH POSITIONS
86
+ # Possible match positions e.g. for LOL it can be Top,Mid,Jungles...
87
+ # GET/{sport}/match/positions
88
+ def match_positions(sport:)
89
+ get("#{sport}/match/positions")
90
+ end
91
+
92
+ # MATCH STATES
93
+ # List all possible match states.
94
+ # GET/{sport}/match/states
95
+ def match_states(sport:)
96
+ get("#{sport}/match/states")
97
+ end
98
+
99
+ # Markets
100
+ # List all markets. Selection array is sorted by order of selections.
101
+ def markets(sport:)
102
+ get("#{sport}/markets")
103
+ end
104
+
105
+ # SELECTIONS
106
+ # List all selections types
107
+ # GET/{sport}/market/selections
108
+ def market_selections(sport:)
109
+ get("#{sport}/market/selections")
110
+ end
111
+
112
+ # CLOSE TIMES
113
+ # List all market close times. It is in match time.
114
+ # GET/{sport}/market/close_times
115
+
116
+ def market_close_times(sport:)
117
+ get("#{sport}/market/close_times")
118
+ end
119
+
120
+ # RESOLVE TIMES
121
+ # List all market resolve times. It is in match time.
122
+ # GET/{sport}/market/resolve_times
123
+
124
+ def market_resolve_times(sport:)
125
+ get("#{sport}/market/resolve_times")
126
+ end
127
+
128
+ # MARKET STATES
129
+ # List all market states.
130
+ # GET /{sport}/market/states
131
+
132
+ def market_states(sport:)
133
+ get("#{sport}/market/states")
134
+ end
135
+ end
136
+ end
data/lib/rts/client.rb ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module RTS
6
+ class Client < Request
7
+ attr_accessor :api_key, :client_certificate, :client_key, :client_certificate_path, :client_key_path
8
+ BASE_URL = 'https://api-json.sandbox.rtsmunity.com:6220'
9
+ include ::Api::StaticSportEventInformation
10
+ include ::Api::LiveSportEventInformation
11
+
12
+ def initialize(api_key:, client_certificate: nil, client_key: nil,
13
+ client_certificate_path: nil, client_key_path: nil)
14
+ @api_key = api_key
15
+ configure_client_certificate(client_certificate, client_certificate_path)
16
+ configure_client_key(client_key, client_key_path)
17
+ validate_openssl_configuration
18
+ end
19
+
20
+ def request_url(path)
21
+ "#{BASE_URL}/#{path}"
22
+ end
23
+
24
+ def headers
25
+ { "X-Api-Key": api_key }
26
+ end
27
+
28
+ private
29
+
30
+ def configure_client_certificate(client_certificate, client_certificate_path)
31
+ @client_certificate = (client_certificate || File.read(client_certificate_path))
32
+ end
33
+
34
+ def configure_client_key(client_key, client_key_path)
35
+ @client_key = (client_key || File.read(client_key_path))
36
+ end
37
+
38
+ def validate_openssl_configuration
39
+ ::OpenSSL::X509::Certificate.new(client_certificate) &&
40
+ ::OpenSSL::PKey::RSA.new(client_key)
41
+ end
42
+
43
+ def ssl_client_key
44
+ ::OpenSSL::PKey::RSA.new(client_key)
45
+ end
46
+
47
+ def ssl_client_certificate
48
+ OpenSSL::X509::Certificate.new(client_certificate)
49
+ end
50
+ end
51
+ end
52
+
53
+ # 'https://api-json.sandbox.rtsmunity.com:6220/csgo/matches',
data/lib/rts/error.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RTS
4
+ class Error < ::StandardError
5
+ class << self
6
+ def errors
7
+ @errors ||= {
8
+ 400 => RTS::Error::BadRequest,
9
+ 404 => RTS::Error::NotFound
10
+ }
11
+ end
12
+
13
+ def on_complete(response)
14
+ klass = errors[response.http_code&.to_i] || RTS::Error::Unknown
15
+ request = response.response&.request.inspect
16
+ raise klass.new({ code: response.http_code, body: response.http_body,
17
+ request: request })
18
+ end
19
+ end
20
+
21
+ # Raised when Rts returns a 4xx HTTP status code
22
+ ClientError = Class.new(self)
23
+
24
+ # Raised when Rts returns the HTTP status code 400
25
+ BadRequest = Class.new(ClientError)
26
+
27
+ # Raised when Rts returns the HTTP status code 404
28
+ NotFound = Class.new(ClientError)
29
+
30
+ # Raised when Rts returns unknown status code
31
+ Unknown = Class.new(self)
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ module RTS
6
+ class Request
7
+ def get(url)
8
+ data = RestClient::Request.execute(
9
+ method: :get,
10
+ url: request_url(url),
11
+ headers: headers,
12
+ ssl_client_cert: ssl_client_certificate,
13
+ ssl_client_key: ssl_client_key
14
+ )
15
+
16
+ JSON.parse(data)
17
+ rescue RestClient::Exception => e
18
+ RTS::Error.on_complete(e)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RTS
4
+ VERSION = '0.1.0'
5
+ end
data/rts.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rts/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rts'
9
+ spec.version = RTS::VERSION
10
+ spec.authors = ['Rahul']
11
+ spec.email = ['rahulismishra@gmail.com']
12
+ spec.summary = 'Rest Client for rts esports JSON API'
13
+ spec.description = 'Rest Client for RTS esports JSON API'
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.17', '>= 1.17.3'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.8'
29
+ spec.add_development_dependency 'vcr', '~> 4.0'
30
+ spec.add_development_dependency 'webmock', '~> 3.4'
31
+
32
+ spec.add_runtime_dependency 'openssl', '~> 2.1', '>= 2.1.0'
33
+ spec.add_runtime_dependency 'rest-client', '~> 2.1', '>= 2.1.0'
34
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rahul
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.17.3
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.17'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.17.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.8'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.8'
75
+ - !ruby/object:Gem::Dependency
76
+ name: vcr
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '4.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.4'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.4'
103
+ - !ruby/object:Gem::Dependency
104
+ name: openssl
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.1.0
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '2.1'
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.1.0
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.1'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rest-client
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.1.0
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '2.1'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 2.1.0
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '2.1'
143
+ description: Rest Client for RTS esports JSON API
144
+ email:
145
+ - rahulismishra@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - lib/rts.rb
151
+ - lib/rts/api/live_sport_event_information.rb
152
+ - lib/rts/api/static_sport_event_information.rb
153
+ - lib/rts/client.rb
154
+ - lib/rts/error.rb
155
+ - lib/rts/request.rb
156
+ - lib/rts/version.rb
157
+ - rts.gemspec
158
+ homepage:
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.7.9
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Rest Client for rts esports JSON API
182
+ test_files: []