football_ruby 0.1.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: 58e13b4b1816884b0095e547573fda6dabee8349
4
+ data.tar.gz: de06b0e1f9db579deb931cad5c3a5eef3235a927
5
+ SHA512:
6
+ metadata.gz: c2b1ce27ed035925fb08009923a3b46e66df10f4d27c99f8fc6ead5166cb6676b5136d31e56729ac29e492af6ed001a3a66e27e4c49bb5350f198c566354c815
7
+ data.tar.gz: 8260529c9fb47d248142ff1f1aff03b19b09e47ec1e6f3870aa0c7e5a01113e6394e99b1c245940b11b9cade3d94a7fc40376bf963354ebd8f76e5bab876996e
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,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in football_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Said Kaldybaev
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,32 @@
1
+ # FootballRuby
2
+
3
+ football-data.org API Container for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'football_ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install football_ruby
20
+
21
+ ## Usage
22
+
23
+ More about filters, structure and API: [football-data.org](http://api.football-data.org/documentation)
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Saidbek/football_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
28
+
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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 "football_ruby"
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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'football_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'football_ruby'
8
+ spec.version = FootballRuby::VERSION
9
+ spec.authors = ['Said Kaldybaev']
10
+ spec.email = ['said.kaldybaev@gmail.com']
11
+
12
+ spec.summary = %q{ruby wrapper for football-data.org API}
13
+ spec.description = %q{ruby wrapper for football-data.org API}
14
+ spec.homepage = 'https://github.com/Saidbek/football_ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'webmock'
28
+ end
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'football_ruby/errors'
3
+
4
+ module FootballRuby
5
+ class Base
6
+ API_ENDPOINT = 'http://api.football-data.org'
7
+ API_VERSION = 'v1'
8
+ API_LIVE = 'http://soccer-cli.appspot.com'
9
+
10
+ def get(path, params={})
11
+ uri = URI("#{API_ENDPOINT}/#{API_VERSION}/#{path}")
12
+
13
+ request = build_request(uri, build_headers(params))
14
+ build_response(uri, request)
15
+ end
16
+
17
+ def get_live_scores
18
+ uri = URI("#{API_LIVE}/")
19
+
20
+ request = build_request(uri)
21
+ build_response(uri, request)
22
+ end
23
+
24
+ private
25
+
26
+ def build_headers(params)
27
+ {
28
+ 'X-Auth-Token' => '31d3d417db12416abbb83e1e3f0a47a9',
29
+ 'X-Response-Control' => 'full'
30
+ }.merge(params)
31
+ end
32
+
33
+ def build_request(uri, headers={})
34
+ Net::HTTP::Get.new(uri, headers)
35
+ end
36
+
37
+ def build_response(uri, request)
38
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
39
+ http.request(request)
40
+ end
41
+
42
+ if response.kind_of? Net::HTTPSuccess
43
+ response
44
+ else
45
+ raise FootballRuby::ResponseError.new(response)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,135 @@
1
+ require 'json'
2
+
3
+ module FootballRuby
4
+ class Client < Base
5
+
6
+ # List all available leagues.
7
+ def leagues(opts={})
8
+ season = opts.fetch(:season) { Time.now.year }
9
+
10
+ json_response get("competitions/?season=#{season}")
11
+ end
12
+
13
+ # List all teams for a certain league.
14
+ def league_teams(id)
15
+ raise 'missing id' if id.nil?
16
+
17
+ json_response get("competitions/#{id}/teams")
18
+ end
19
+
20
+ # Show League Table / current standing.
21
+ # Filters:
22
+ #
23
+ # match_day=/\d+/
24
+
25
+ def league_table(id, opts={})
26
+ raise 'missing id' if id.nil?
27
+
28
+ match_day = opts[:match_day]
29
+
30
+ uri = "competitions/#{id}/leagueTable/"
31
+ url = match_day.nil? ? uri : "#{uri}?matchday=#{match_day}"
32
+
33
+ json_response get(url)
34
+ end
35
+
36
+ # List all fixtures for a certain league.
37
+ # Filters:
38
+ #
39
+ # time_frame=/p|n[1-9]{1,2}/
40
+ # match_day=/\d+/
41
+
42
+ def league_fixtures(id, opts={})
43
+ raise 'missing id' if id.nil?
44
+
45
+ time_frame = opts[:time_frame]
46
+ match_day = opts[:match_day]
47
+
48
+ uri = "competitions/#{id}/fixtures/"
49
+ url = time_frame.nil? ? uri : "#{uri}?timeFrame=#{time_frame}"
50
+ url = match_day.nil? ? url : "#{url}?matchday=#{match_day}"
51
+
52
+ json_response get(url)
53
+ end
54
+
55
+ # List fixtures across a set of leagues.
56
+ # Filters:
57
+ #
58
+ # time_frame=/p|n[1-9]{1,2}/
59
+ # league=leagueCode
60
+
61
+ def fixtures(opts={})
62
+ time_frame = opts[:time_frame]
63
+ league = opts[:league]
64
+
65
+ uri = "fixtures/"
66
+ url = time_frame.nil? ? uri : "#{uri}?timeFrame=#{time_frame}"
67
+ url = league.nil? ? url : "#{url}?league=#{league}"
68
+
69
+ json_response get(url)
70
+ end
71
+
72
+ # Show one fixture.
73
+ # Filters:
74
+ #
75
+ # head2head=/\d+/
76
+
77
+ def fixture(id, opts={})
78
+ raise 'missing id' if id.nil?
79
+
80
+ head2head = opts[:head2head]
81
+
82
+ uri = "fixtures/#{id}/"
83
+ url = head2head.nil? ? uri : "#{uri}?head2head=#{head2head}"
84
+
85
+ json_response get(url)
86
+ end
87
+
88
+ # Show all fixtures for a certain team.
89
+ # Filters:
90
+ #
91
+ # season=/\d\d\d\d/
92
+ # time_frame=/p|n[1-9]{1,2}/
93
+ # venue=/home|away/
94
+
95
+ def team_fixtures(id, opts={})
96
+ raise 'missing id' if id.nil?
97
+
98
+ season = opts[:season]
99
+ time_frame = opts[:time_frame]
100
+ venue = opts[:venue]
101
+
102
+ uri = "teams/#{id}/fixtures/"
103
+ url = season.nil? ? uri : "#{uri}?season=#{season}"
104
+ url = time_frame.nil? ? url : "#{url}?timeFrame=#{time_frame}"
105
+ url = venue.nil? ? url : "#{url}?venue=#{venue}"
106
+
107
+ json_response get(url)
108
+ end
109
+
110
+ # Show one team.
111
+ def team(id)
112
+ raise 'missing id' if id.nil?
113
+
114
+ json_response get("teams/#{id}/")
115
+ end
116
+
117
+ # Show all players for a certain team.
118
+ def team_players(id)
119
+ raise 'missing team id' if id.nil?
120
+
121
+ json_response get("teams/#{id}/players/")
122
+ end
123
+
124
+ # Show live scores
125
+ def live_scores
126
+ json_response get_live_scores
127
+ end
128
+
129
+ private
130
+
131
+ def json_response(request)
132
+ JSON.parse(request.body, symbolize_names: true)
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,11 @@
1
+ module FootballRuby
2
+ class Error < StandardError; end
3
+
4
+ class ResponseError < Error
5
+ attr_reader :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module FootballRuby
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'football_ruby/base'
2
+ require 'football_ruby/client'
3
+ require 'football_ruby/version'
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: football_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Said Kaldybaev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-13 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: '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
+ description: ruby wrapper for football-data.org API
70
+ email:
71
+ - said.kaldybaev@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - football_ruby.gemspec
86
+ - lib/football_ruby.rb
87
+ - lib/football_ruby/base.rb
88
+ - lib/football_ruby/client.rb
89
+ - lib/football_ruby/errors.rb
90
+ - lib/football_ruby/version.rb
91
+ homepage: https://github.com/Saidbek/football_ruby
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: ruby wrapper for football-data.org API
115
+ test_files: []