overwatch_league 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa49ef54153776b3eb7ff02c1141999242842db7
4
+ data.tar.gz: dca207c46b26d78c6eb03eed06efebc9520b241d
5
+ SHA512:
6
+ metadata.gz: cca08bac209d2edf669f696670567713a8cb52c42bd6a1a90afce778d674b23b6b96768b432cc052b1651b5ea5c875ebdade36b523a52c36ed7052bbd64b7633
7
+ data.tar.gz: c4a582e5b3c6e0c2ecd1d043e70278b72122318ce2696f77ffb235413fe121675cac8b589714527a762a12d320ed3afd7536322816ff9528cd62070e7ada9780
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=2bec143035c2451c97f1c1761c9be318546d69de3706a797410f57b5deaf3186
4
+ language: ruby
5
+ rvm:
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.11.2
8
+ notifications:
9
+ - false
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+ scripts:
15
+ - bundle exec rspec spec
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2018-04-02
10
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in overwatch_league.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 James Gayfer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ [![Gem Version](https://badge.fury.io/rb/overwatch_league.svg)](https://badge.fury.io/rb/overwatch_league)
2
+ [![Build Status](https://travis-ci.org/jgayfer/overwatch_league.svg?branch=master)](https://travis-ci.org/jgayfer/overwatch_league)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/398b860d65874c9ea715/test_coverage)](https://codeclimate.com/github/jgayfer/overwatch_league/test_coverage)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/398b860d65874c9ea715/maintainability)](https://codeclimate.com/github/jgayfer/overwatch_league/maintainability)
5
+
6
+ # Overwatch League
7
+
8
+ A Ruby wrapper around the Overwatch League API
9
+
10
+ ## Installation
11
+ $ gem install overwatch_league
12
+
13
+ ## Basic Example
14
+
15
+ ```
16
+ require 'overwatch_league'
17
+
18
+ owl = OverwatchLeague.new
19
+ teams = owl.teams
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ There is no official documentation for the API. However, [this Reddit post](https://www.reddit.com/r/Competitiveoverwatch/comments/7p0e8d/owl_api_analysis/) documents the API reasonably well.
25
+
26
+ The following methods are supported as part of the basic client.
27
+
28
+ > `teams`
29
+
30
+ > `team(team_id)`
31
+
32
+ > `ranking`
33
+
34
+ > `standings`
35
+
36
+ > `matches`
37
+
38
+ > `match(match_id)`
39
+
40
+ > `schedule`
41
+
42
+ > `streams`
43
+
44
+ > `vods`
45
+
46
+ > `maps`
47
+
48
+ > `news`
49
+
50
+ > `videos`
51
+
52
+ Rather than just returning a JSON `Hash`, each method returns an `OpenStruct` representation of the JSON where the keys have been converted to snake case. This is done for convenience, as it allows for `object.key.another_key` instead of `object['key']['another_key']` when parsing the response.
53
+
54
+ ## Development & Contributions
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jgayfer/overwatch_league.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "overwatch_league"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ require_relative "overwatch_league/version"
2
+ require_relative "overwatch_league/url"
3
+ require_relative "overwatch_league/request"
4
+ require_relative "overwatch_league/api"
5
+ require_relative "overwatch_league/response_error"
6
+ require_relative "overwatch_league/client"
7
+ require_relative "overwatch_league/build_response"
8
+
9
+ module OverwatchLeague
10
+ class << self
11
+ def new
12
+ Client.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,65 @@
1
+ require_relative 'request'
2
+ require_relative 'response_error'
3
+ require_relative 'build_response'
4
+
5
+ module OverwatchLeague
6
+ module API
7
+ BASE_URL = 'https://api.overwatchleague.com'
8
+ HTTP_OK = 200
9
+
10
+ def teams
11
+ handle_response(Request.get(URL.new("#{BASE_URL}/teams")))
12
+ end
13
+
14
+ def team(team_id)
15
+ handle_response(Request.get(URL.new("#{BASE_URL}/teams/#{team_id}")))
16
+ end
17
+
18
+ def ranking
19
+ handle_response(Request.get(URL.new("#{BASE_URL}/ranking")))
20
+ end
21
+
22
+ def standings
23
+ handle_response(Request.get(URL.new("#{BASE_URL}/standings")))
24
+ end
25
+
26
+ def matches
27
+ handle_response(Request.get(URL.new("#{BASE_URL}/matches")))
28
+ end
29
+
30
+ def match(match_id)
31
+ handle_response(Request.get(URL.new("#{BASE_URL}/matches/#{match_id}")))
32
+ end
33
+
34
+ def schedule
35
+ handle_response(Request.get(URL.new("#{BASE_URL}/schedule")))
36
+ end
37
+
38
+ def streams
39
+ handle_response(Request.get(URL.new("#{BASE_URL}/streams")))
40
+ end
41
+
42
+ def vods
43
+ handle_response(Request.get(URL.new("#{BASE_URL}/vods")))
44
+ end
45
+
46
+ def maps
47
+ handle_response(Request.get(URL.new("#{BASE_URL}/maps")))
48
+ end
49
+
50
+ def news
51
+ handle_response(Request.get(URL.new("#{BASE_URL}/news")))
52
+ end
53
+
54
+ def videos
55
+ handle_response(Request.get(URL.new("#{BASE_URL}/playlist/owl-app-playlist")))
56
+ end
57
+
58
+ private
59
+
60
+ def handle_response(response)
61
+ raise ResponseError.new(response) unless response.code == HTTP_OK
62
+ BuildResponse.(response)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,35 @@
1
+ module OverwatchLeague
2
+ module BuildResponse
3
+ class << self
4
+ def call(response)
5
+ snake_case_json_string = convert_hash_keys(JSON.parse(response.body.to_s)).to_json
6
+ JSON.parse(snake_case_json_string, object_class: OpenStruct)
7
+ end
8
+
9
+ private
10
+
11
+ def convert_hash_keys(value)
12
+ case value
13
+ when Array
14
+ value.map { |v| convert_hash_keys(v) }
15
+ when Hash
16
+ Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] }]
17
+ else
18
+ value
19
+ end
20
+ end
21
+
22
+ def underscore_key(k)
23
+ to_snake_case(k.to_s)
24
+ end
25
+
26
+ def to_snake_case(string)
27
+ string.gsub(/::/, '/').
28
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
29
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
30
+ tr("-", "_").
31
+ downcase
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module OverwatchLeague
2
+ class Client
3
+ include OverwatchLeague::API
4
+
5
+ def initialize; end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'http'
2
+
3
+ module OverwatchLeague
4
+ module Request
5
+ class << self
6
+ def get(url)
7
+ HTTP.get(url.to_str)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module OverwatchLeague
2
+ class ResponseError < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ super("#{response.code}: #{response.body}")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'net/http'
2
+
3
+ module OverwatchLeague
4
+ class URL
5
+ def initialize(path, params: {})
6
+ @path = path
7
+ @params = params
8
+ end
9
+
10
+ def to_str
11
+ String.new.tap do |url|
12
+ url << @path
13
+ url << '?' + URI.encode_www_form(@params) unless @params.empty?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module OverwatchLeague
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'overwatch_league/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "overwatch_league"
8
+ spec.version = OverwatchLeague::VERSION
9
+ spec.authors = ["James Gayfer"]
10
+ spec.email = ["gayfer.james@gmail.com"]
11
+
12
+ spec.summary = 'Ruby wrapper for the Overwatch League API'
13
+ spec.description = 'Ruby wrapper for the Overwatch League API'
14
+ spec.homepage = 'http://www.github.com/jgayfer/overwatch_league'
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "webmock", "~> 3.3"
34
+ spec.add_development_dependency "simplecov"
35
+ spec.add_development_dependency "simplecov-console"
36
+ spec.add_dependency "http", "~> 3.0"
37
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overwatch_league
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Gayfer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-02 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-console
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: http
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Ruby wrapper for the Overwatch League API
112
+ email:
113
+ - gayfer.james@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/overwatch_league.rb
129
+ - lib/overwatch_league/api.rb
130
+ - lib/overwatch_league/build_response.rb
131
+ - lib/overwatch_league/client.rb
132
+ - lib/overwatch_league/request.rb
133
+ - lib/overwatch_league/response_error.rb
134
+ - lib/overwatch_league/url.rb
135
+ - lib/overwatch_league/version.rb
136
+ - overwatch_league.gemspec
137
+ homepage: http://www.github.com/jgayfer/overwatch_league
138
+ licenses:
139
+ - MIT
140
+ metadata:
141
+ allowed_push_host: https://rubygems.org
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.5.2.1
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Ruby wrapper for the Overwatch League API
162
+ test_files: []