football_ruby 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e318cacb2e1d0e12f454581beab87f26d3ef2fe
4
- data.tar.gz: 91713e935c224aae90a1368faaea2d6c8682c36c
3
+ metadata.gz: 5aede82050753e7212b727656ac94ef0d905df7c
4
+ data.tar.gz: 4ea9926f9fd653da526c12eaffc3bc9f3a00e555
5
5
  SHA512:
6
- metadata.gz: 616918fc9b2e19178aa1ae6e62250b603894167c8fd29e8a096b03cee24974069d65a91d657dc77d69da1056b8ebaeee89e1aa08b4180a1a69fe829cf85277f8
7
- data.tar.gz: 73cb0464ef1b5867674c7fa0cfe8836e80d357b257eccf0ee45db8b9379d9ce5600618cdf526491076ae72f829775931c699fe8d0c2e3255f593a8c67874ac75
6
+ metadata.gz: d306d3dfa5008a27631c4f8a6d2683ac25d54ae779fff4688defc0494dc2755ceccf3949c3416a4a8051f136ef1e457347958d8fe95d4172e6abc21df507b536
7
+ data.tar.gz: bc45e56165a30bc5ec2afee39868d0d40ffb731c6ebc0d6f11e641af845a63688618f07c799d9d71b3c1ab58c328c09cf784140d44576d977c92e7a22487d509
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ ![Travis Master](https://travis-ci.org/Saidbek/football_ruby.svg?branch=master)
1
2
  # FootballRuby
2
3
 
3
4
  football-data.org API Container for Ruby
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Said Kaldybaev']
10
10
  spec.email = ['said.kaldybaev@gmail.com']
11
11
 
12
- spec.summary = %q{ruby wrapper for football-data.org API}
13
- spec.description = %q{ruby wrapper for football-data.org API}
12
+ spec.summary = %q{football-data.org API wrapper in ruby}
13
+ spec.description = %q{football-data.org API wrapper in ruby}
14
14
  spec.homepage = 'https://github.com/Saidbek/football_ruby'
15
15
  spec.license = 'MIT'
16
16
 
data/lib/football_ruby.rb CHANGED
@@ -1,3 +1,10 @@
1
+ require 'net/http'
1
2
  require 'football_ruby/base'
2
3
  require 'football_ruby/client'
4
+ require 'football_ruby/configuration'
5
+ require 'football_ruby/errors'
3
6
  require 'football_ruby/version'
7
+
8
+ module FootballRuby
9
+ extend Configuration
10
+ end
@@ -1,32 +1,26 @@
1
- require 'net/http'
2
- require 'football_ruby/errors'
3
-
4
1
  module FootballRuby
5
2
  class Base
6
- API_ENDPOINT = 'http://api.football-data.org'
7
- API_VERSION = 'v1'
8
- API_LIVE = 'http://soccer-cli.appspot.com'
9
-
10
3
  def get(path, params={})
11
- uri = URI("#{API_ENDPOINT}/#{API_VERSION}/#{path}")
12
-
4
+ uri = URI("#{FootballRuby::Configuration::API_ENDPOINT}/#{path}")
13
5
  request = build_request(uri, build_headers(params))
6
+
14
7
  build_response(uri, request)
15
8
  end
16
9
 
17
10
  def get_live_scores
18
- uri = URI("#{API_LIVE}/")
19
-
11
+ uri = URI("#{FootballRuby::Configuration::LIVE_ENDPOINT}/")
20
12
  request = build_request(uri)
13
+
21
14
  build_response(uri, request)
22
15
  end
23
16
 
24
17
  private
25
18
 
26
19
  def build_headers(params)
20
+ raise ApiTokenMissingError, 'Please set up your api token' if FootballRuby.api_token.nil?
21
+
27
22
  {
28
- 'X-Auth-Token' => '31d3d417db12416abbb83e1e3f0a47a9',
29
- 'X-Response-Control' => 'full'
23
+ 'X-Auth-Token': FootballRuby.api_token
30
24
  }.merge(params)
31
25
  end
32
26
 
@@ -35,15 +29,9 @@ module FootballRuby
35
29
  end
36
30
 
37
31
  def build_response(uri, request)
38
- response = Net::HTTP.start(uri.host, uri.port) do |http|
32
+ Net::HTTP.start(uri.host, uri.port) do |http|
39
33
  http.request(request)
40
34
  end
41
-
42
- if response.kind_of? Net::HTTPSuccess
43
- response
44
- else
45
- raise FootballRuby::ResponseError.new(response)
46
- end
47
35
  end
48
36
  end
49
37
  end
@@ -12,7 +12,7 @@ module FootballRuby
12
12
 
13
13
  # List all teams for a certain league.
14
14
  def league_teams(id)
15
- raise 'missing id' if id.nil?
15
+ raise IdMissingError, 'missing id' if id.nil?
16
16
 
17
17
  json_response get("competitions/#{id}/teams")
18
18
  end
@@ -23,7 +23,7 @@ module FootballRuby
23
23
  # match_day=/\d+/
24
24
 
25
25
  def league_table(id, opts={})
26
- raise 'missing id' if id.nil?
26
+ raise IdMissingError, 'missing id' if id.nil?
27
27
 
28
28
  match_day = opts[:match_day]
29
29
 
@@ -40,7 +40,7 @@ module FootballRuby
40
40
  # match_day=/\d+/
41
41
 
42
42
  def league_fixtures(id, opts={})
43
- raise 'missing id' if id.nil?
43
+ raise IdMissingError, 'missing id' if id.nil?
44
44
 
45
45
  time_frame = opts[:time_frame]
46
46
  match_day = opts[:match_day]
@@ -75,7 +75,7 @@ module FootballRuby
75
75
  # head2head=/\d+/
76
76
 
77
77
  def fixture(id, opts={})
78
- raise 'missing id' if id.nil?
78
+ raise IdMissingError, 'missing id' if id.nil?
79
79
 
80
80
  head2head = opts[:head2head]
81
81
 
@@ -93,7 +93,7 @@ module FootballRuby
93
93
  # venue=/home|away/
94
94
 
95
95
  def team_fixtures(id, opts={})
96
- raise 'missing id' if id.nil?
96
+ raise IdMissingError, 'missing id' if id.nil?
97
97
 
98
98
  season = opts[:season]
99
99
  time_frame = opts[:time_frame]
@@ -109,14 +109,14 @@ module FootballRuby
109
109
 
110
110
  # Show one team.
111
111
  def team(id)
112
- raise 'missing id' if id.nil?
112
+ raise IdMissingError, 'missing id' if id.nil?
113
113
 
114
114
  json_response get("teams/#{id}/")
115
115
  end
116
116
 
117
117
  # Show all players for a certain team.
118
118
  def team_players(id)
119
- raise 'missing team id' if id.nil?
119
+ raise IdMissingError, 'missing team id' if id.nil?
120
120
 
121
121
  json_response get("teams/#{id}/players/")
122
122
  end
@@ -0,0 +1,12 @@
1
+ module FootballRuby
2
+ module Configuration
3
+ API_ENDPOINT = 'http://api.football-data.org/v1'
4
+ LIVE_ENDPOINT = 'http://soccer-cli.appspot.com'
5
+
6
+ attr_accessor :api_token
7
+
8
+ def configure
9
+ yield self
10
+ end
11
+ end
12
+ end
@@ -1,11 +1,6 @@
1
1
  module FootballRuby
2
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
3
+ class ResponseError < Error; end
4
+ class ApiTokenMissingError < Error; end
5
+ class IdMissingError < Error; end
11
6
  end
@@ -1,3 +1,3 @@
1
1
  module FootballRuby
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Said Kaldybaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: ruby wrapper for football-data.org API
41
+ description: football-data.org API wrapper in ruby
42
42
  email:
43
43
  - said.kaldybaev@gmail.com
44
44
  executables: []
@@ -58,6 +58,7 @@ files:
58
58
  - lib/football_ruby.rb
59
59
  - lib/football_ruby/base.rb
60
60
  - lib/football_ruby/client.rb
61
+ - lib/football_ruby/configuration.rb
61
62
  - lib/football_ruby/errors.rb
62
63
  - lib/football_ruby/version.rb
63
64
  homepage: https://github.com/Saidbek/football_ruby
@@ -83,5 +84,5 @@ rubyforge_project:
83
84
  rubygems_version: 2.5.1
84
85
  signing_key:
85
86
  specification_version: 4
86
- summary: ruby wrapper for football-data.org API
87
+ summary: football-data.org API wrapper in ruby
87
88
  test_files: []