football__data 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: 707998b5dd3cbd164065aa5e8a950452584590c4
4
+ data.tar.gz: b7f4a287e8d4a4d886376848ffb5d4d351b73002
5
+ SHA512:
6
+ metadata.gz: ceea9f5e640522bb22a840d6075dcc07b8111a558933ea149ae2083df6d0864a18346a115ab7f67c7904cc2970000af3e57a4423ed8c00f7d742a9f0db9a0f5b
7
+ data.tar.gz: 6e0b033c89154db0525673f69dd2a9d5c5112fd73843e8fc9208b3c94afd31214b1dfb8920c40346f5ef7c79dd65d240051b20d18d757e603662b6225acce71e
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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in football__data.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # FootballData
2
+
3
+ A ruby wrapper of [football-data.org](http://api.football-data.org/index)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'football__data'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install football__data
20
+
21
+ ## Usage
22
+
23
+ ### API Usage
24
+
25
+ First you need to configure the api
26
+
27
+ ```ruby
28
+ FootballData.configure do |config|
29
+ # get api key at 'http://api.football-data.org/register'
30
+ config.api_key = YOUR_API_KEY
31
+
32
+ # default api version is 'alpha' if not setted
33
+ config.api_version = 'alpha'
34
+
35
+ # the default control method is 'full' if not setted
36
+ # see request section on 'http://api.football-data.org/documentation'
37
+ config.response_control = 'minified'
38
+ end
39
+ ```
40
+
41
+ Use `FootballData.fetch(resource, subresource, params)` to fetch the data.
42
+ It returns a json parsed object. Such as:
43
+
44
+ ```ruby
45
+ # GET 'http://api.football-data.org/v1/soccerseasons'
46
+ FootballData.fetch(:soccerseasons)
47
+
48
+ # GET 'http://api.football-data.org/v1/soccerseasons/398/leagueTable'
49
+ FootballData.fetch(:soccerseasons, :leagueTable, id: 398)
50
+
51
+ # GET 'http://api.football-data.org/v1/soccerseasons/398/fixtures?matchday=8'
52
+ FootballData.fetch(:soccerseasons, :fixtures, id: 398, matchday: 8)
53
+
54
+ res = FootballData.fetch(:teams, :players, id: 57)
55
+ pp res['players'].find{|player| player['name'] =~ /Mesut/i}
56
+ # {"id"=>1967,
57
+ # "name"=>"Mesut Özil",
58
+ # "position"=>"Attacking Midfield",
59
+ # "jerseyNumber"=>11,
60
+ # "dateOfBirth"=>"1988-10-15",
61
+ # "nationality"=>"Germany",
62
+ # "contractUntil"=>"2018-06-30",
63
+ # "marketValue"=>"40,000,000 €"}
64
+ ```
65
+
66
+ See api structure on page 'http://api.football-data.org/documentation'
67
+
68
+ ### Executable Usage
69
+
70
+ TODO
71
+
72
+ ## Contributing
73
+
74
+ Feel free to file an issue of make a pr.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "football__data"
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/football ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env ruby
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'football__data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "football__data"
8
+ spec.version = FootballData::VERSION
9
+ spec.authors = ["delta"]
10
+ spec.email = ["delta4d@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = %q{ruby api wrapper of football-data.org}
14
+ spec.description = %q{ruby api wrapper of football-data.org}
15
+ spec.homepage = "https://github.com/delta4d/football-data"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = ["football"]
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "faraday", "~> 0.9"
25
+ end
@@ -0,0 +1,24 @@
1
+ module FootballData
2
+ module Configuration
3
+ DEFAULT_API_KEY = nil
4
+ DEFAULT_API_VERSON = "alpha"
5
+ DEFAULT_RESPONSE_CONTROL = "full"
6
+
7
+ API_ENDPOINT = "http://api.football-data.org"
8
+
9
+ attr_writer :api_version, :api_key, :response_control
10
+
11
+ def configure
12
+ raise "don't you wanna configure it?" unless block_given?
13
+ yield self
14
+ @api_version ||= DEFAULT_API_VERSON
15
+ @response_control ||= DEFAULT_RESPONSE_CONTROL
16
+ end
17
+
18
+ def reset!
19
+ @api_key = DEFAULT_API_KEY
20
+ @api_version = DEFAULT_API_VERSON
21
+ @response_control = DEFAULT_RESPONSE_CONTROL
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module FootballData
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "football__data/version"
2
+ require "football__data/configuration"
3
+
4
+ require "json"
5
+ require "faraday"
6
+
7
+ module FootballData
8
+ extend Configuration
9
+
10
+ class << self
11
+ # main method of FootballData, fetch info of football matches and players
12
+ # see 'http://api.football-data.org/documentation' for details
13
+ #
14
+ # @param resource [Symbol, String] one of :soccerseasons, :teams, :fixtures
15
+ # @param subresource [Symbol, String]
16
+ # :soccerseasons => one of :fixtures, :teams, :leagueTable
17
+ # :teams => one of :fixtures, :players
18
+ # @param params [Hash] the filter parameters, :id is also pass by params
19
+ def fetch(resource, subresource = nil, params = {})
20
+ id, filter = parse_params(params)
21
+ path = "/#{@api_version}/#{resource}"
22
+ path += "/#{id}/#{subresource}" if id
23
+ path += "?#{filter}" if filter
24
+ response = get(path)
25
+ JSON.parse(response.body)
26
+ end
27
+
28
+ private
29
+
30
+ def parse_params(params)
31
+ id = params[:id]
32
+ no_id_params = params.dup
33
+ no_id_params.delete(:id)
34
+ filter = no_id_params.map{ |key, val| "#{key}=#{val}" }.join("&")
35
+ [id, filter]
36
+ end
37
+
38
+ def connection
39
+ @connection ||= Faraday.new(url: API_ENDPOINT,
40
+ headers: {"X-Auth-Token" => @api_key,
41
+ "X-Response-Control" => @response_control})
42
+ end
43
+
44
+ def get(path)
45
+ connection.get(path)
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: football__data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - delta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-06 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ description: ruby api wrapper of football-data.org
56
+ email:
57
+ - delta4d@gmail.com
58
+ executables:
59
+ - football
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/football
71
+ - bin/setup
72
+ - football__data.gemspec
73
+ - lib/football__data.rb
74
+ - lib/football__data/configuration.rb
75
+ - lib/football__data/version.rb
76
+ homepage: https://github.com/delta4d/football-data
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: ruby api wrapper of football-data.org
100
+ test_files: []
101
+ has_rdoc: