football_cli 0.0.6 → 1.0.0

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: 1df441d44406edc4be111c1116102489aed819c1
4
- data.tar.gz: de99649c3dcadb29610f06dd83db866fda0e56da
3
+ metadata.gz: 60746f91d740220139bb1a16b12689bb35f00ed9
4
+ data.tar.gz: 983ccaa2ff3c5cd5b831e47d79d13082ac4f85b3
5
5
  SHA512:
6
- metadata.gz: 036089059d5fc065ad442940e669846fa9c7cadce35b88e396803a48ed490911bd2cae729445f3c4d98ae30fa962f47fe877ee7605a74ad333ba054668b2db43
7
- data.tar.gz: 9fc52868aa7c04995e55b05015f60bbe7af84312f0ced1de427345d2fc3a31b571620210a9c3c1f82f88a7d302c9d1d1a2ecaa992c7930517a4383440882a4d2
6
+ metadata.gz: a71c97c95680115d4f951a482aeca9085ed03b6f8a449cb499f2e94501945d8eb5cda26060476da8b2aa6d59a075242e7641112aabd422695febec6650c7e5cd
7
+ data.tar.gz: ddd3331f6cef62daa3e1835dc1df1f8f8ffc9cc9a594d6d60ff91c6d87d3ab0bc303ce5c6de8318108c6f771638e55ce3e166c9fa186d2f4c8e019830ff971a3
data/.gitignore CHANGED
@@ -1 +1 @@
1
- tmp
1
+ tmp
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0@football_cli
1
+ 2.3.0@football_cli
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,14 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- football_cli (0.0.6)
4
+ football_cli (1.0.0)
5
5
  football_ruby
6
6
  rainbow
7
+ terminal-table
7
8
  thor
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
13
+ addressable (2.5.1)
14
+ public_suffix (~> 2.0, >= 2.0.2)
12
15
  aruba (0.14.2)
13
16
  childprocess (~> 0.5.6)
14
17
  contracts (~> 0.9)
@@ -20,6 +23,8 @@ GEM
20
23
  childprocess (0.5.9)
21
24
  ffi (~> 1.0, >= 1.0.11)
22
25
  contracts (0.16.0)
26
+ crack (0.4.3)
27
+ safe_yaml (~> 1.0.0)
23
28
  cucumber (2.4.0)
24
29
  builder (>= 2.1.2)
25
30
  cucumber-core (~> 1.5.0)
@@ -35,8 +40,10 @@ GEM
35
40
  ffi (1.9.18)
36
41
  football_ruby (0.1.2)
37
42
  gherkin (4.1.3)
43
+ hashdiff (0.3.4)
38
44
  multi_json (1.12.1)
39
45
  multi_test (0.1.2)
46
+ public_suffix (2.0.5)
40
47
  rainbow (2.2.2)
41
48
  rake
42
49
  rake (12.0.0)
@@ -44,10 +51,15 @@ GEM
44
51
  diff-lcs (>= 1.2.0, < 2.0)
45
52
  rspec-support (~> 3.6.0)
46
53
  rspec-support (3.6.0)
54
+ safe_yaml (1.0.4)
47
55
  terminal-table (1.8.0)
48
56
  unicode-display_width (~> 1.1, >= 1.1.1)
49
57
  thor (0.19.4)
50
58
  unicode-display_width (1.2.1)
59
+ webmock (3.0.1)
60
+ addressable (>= 2.3.6)
61
+ crack (>= 0.3.2)
62
+ hashdiff
51
63
 
52
64
  PLATFORMS
53
65
  ruby
@@ -56,7 +68,7 @@ DEPENDENCIES
56
68
  aruba
57
69
  football_cli!
58
70
  rake
59
- terminal-table
71
+ webmock
60
72
 
61
73
  BUNDLED WITH
62
74
  1.14.6
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="http://i.imgur.com/FLITgqs.jpg">
3
3
  </p>
4
4
 
5
- # Fottball CLI
5
+ # Football CLI
6
6
 
7
7
  A command line interface for all the football data feeds in Ruby
8
8
 
data/bin/football_cli CHANGED
@@ -1,4 +1,10 @@
1
- #!/usr/bin/env ruby
2
- require 'football_cli'
1
+ #!/usr/bin/env ruby -U
2
+
3
+ Signal.trap('INT') { abort }
4
+
5
+ lib = File.expand_path('../../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ require 'football_cli/runner'
9
+ FootballCli::Runner.new(ARGV.dup).execute!
3
10
 
4
- FootballCli::CLI.start( ARGV )
data/football_cli.gemspec CHANGED
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
22
22
  spec.executables << 'football_cli'
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'thor'
26
- spec.add_dependency 'football_ruby'
27
- spec.add_dependency 'rainbow'
25
+ spec.add_runtime_dependency 'thor'
26
+ spec.add_runtime_dependency 'football_ruby'
27
+ spec.add_runtime_dependency 'rainbow'
28
+ spec.add_runtime_dependency 'terminal-table'
28
29
 
29
30
  spec.add_development_dependency 'rake'
30
31
  spec.add_development_dependency 'aruba'
31
- spec.add_development_dependency 'terminal-table'
32
+ spec.add_development_dependency 'webmock'
32
33
  end
@@ -1,24 +1,22 @@
1
- require 'thor'
2
- require_relative 'handler'
3
-
4
1
  module FootballCli
5
2
  class CLI < Thor
6
- desc 'show', 'sample description'
7
-
8
- option :league
9
- option :match_day, type: :numeric
10
- option :format
11
- option :file
3
+ desc 'config SUBCOMMAND ...ARGS', 'Write options in the configuration file'
4
+ subcommand 'config', Config
12
5
 
13
- option :team
14
- class_option :players, type: :boolean
15
- class_option :fixtures, type: :boolean
6
+ desc 'show', 'Display all the football data feeds'
7
+ option :league, aliases: '-l', banner: 'PD', desc: 'Current standing of league'
8
+ option :match_day, type: :numeric, aliases: '-d', banner: 5, desc: 'Current standing of league for a given day'
9
+ option :format, aliases: '-t', banner: 'json', desc: 'Output format type, default: table'
10
+ option :file, aliases: '-f', banner: 'players.json', desc: 'File name to save the output'
11
+ option :team, aliases: '-t', banner: 'FCB', desc: 'Team details, players or fixtures'
12
+ class_option :players, type: :boolean, aliases: '-p'
13
+ class_option :fixtures, type: :boolean, aliases: '-f'
16
14
 
17
15
  def show
18
16
  handler.run
19
17
  end
20
18
 
21
- desc 'live', 'display live scores'
19
+ desc 'live', 'Display live scores'
22
20
  def live
23
21
  handler.live_scores
24
22
  end
@@ -0,0 +1,9 @@
1
+ module FootballCli
2
+ class Config < Thor
3
+ desc 'api_token KEY', 'Set the global configuration for api_token'
4
+ method_options update: :boolean
5
+ def api_token(api_token)
6
+ Configuration.write(api_token, :api_token, options)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require 'yaml'
2
+
3
+ module FootballCli
4
+ module Configuration
5
+ CONFIG_FILE = '.football_cli.yml'
6
+ CONFIG_CONTENTS = {
7
+ api_token: '',
8
+ }
9
+
10
+ def self.write(value, key, options)
11
+ create_config_file unless File.exist? config_file
12
+ update_value(value, key) && return if options['update'] && !send(key).empty?
13
+
14
+ if send(key).empty?
15
+ puts "Updating config file with #{key}: #{value}"
16
+ update_value(value, key)
17
+ else
18
+ puts "Do you want to overwrite #{key} provide --update option"
19
+ end
20
+ end
21
+
22
+ def self.update_value(value, key)
23
+ content = config_data
24
+ content.send(:[]=, key, value)
25
+
26
+ File.open(config_file, 'w') do |f|
27
+ f.write(content.to_yaml)
28
+ end
29
+ end
30
+
31
+ def self.create_config_file
32
+ File.open(config_file, 'w+') { |f| f.write(CONFIG_CONTENTS.to_yaml) }
33
+ end
34
+
35
+ def self.api_token
36
+ config_data[:api_token] if config_data
37
+ end
38
+
39
+ def self.config_file
40
+ File.join(ENV['HOME'], CONFIG_FILE)
41
+ end
42
+
43
+ def self.config_data
44
+ YAML::load_file(config_file) if File.exist? config_file
45
+ end
46
+ end
47
+ end
@@ -20,6 +20,8 @@ module FootballCli
20
20
  end
21
21
 
22
22
  def run
23
+ check_for_api_token
24
+
23
25
  if league
24
26
  league_table
25
27
  elsif team
@@ -58,7 +60,7 @@ module FootballCli
58
60
  team_response = client.team(team_id)
59
61
 
60
62
  output(
61
- title: "#{team_response[:name]} players. Total #{response[:count]}",
63
+ title: "#{team_response[:name]} fixtures. Total #{response[:count]}",
62
64
  response: response[:fixtures],
63
65
  columns: %i(matchday homeTeamName goalsHomeTeam goalsAwayTeam awayTeamName status date)
64
66
  )
@@ -104,7 +106,13 @@ module FootballCli
104
106
  end
105
107
 
106
108
  def client
109
+ FootballRuby.api_token = Configuration.api_token
110
+
107
111
  @client ||= FootballRuby::Client.new
108
112
  end
113
+
114
+ def check_for_api_token
115
+ raise Thor::Error ,"ERROR: You must config the api_token\nSOLUTION: Set up with `config api_token TOKEN`" if Configuration.api_token.to_s.empty?
116
+ end
109
117
  end
110
118
  end
@@ -0,0 +1,47 @@
1
+ require 'football_cli'
2
+
3
+ # to use Webmock we need the Runner class
4
+ # https://github.com/cucumber/aruba#testing-ruby-cli-programs-without-spawning-a-new-ruby-process
5
+ module FootballCli
6
+ class Runner
7
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
8
+ @argv = argv
9
+ @stdin = stdin
10
+ @stdout = stdout
11
+ @stderr = stderr
12
+ @kernel = kernel
13
+ end
14
+
15
+ def execute!
16
+ exit_code = run_cli
17
+ @kernel.exit(exit_code)
18
+ end
19
+
20
+ private
21
+
22
+ def run_cli
23
+ exit_code = begin
24
+ $stderr = @stderr
25
+ $stdin = @stdin
26
+ $stdout = @stdout
27
+
28
+ FootballCli::CLI.start(@argv)
29
+
30
+ 0
31
+ rescue StandardError => e
32
+ b = e.backtrace
33
+ @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
34
+ @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
35
+ 1
36
+ rescue SystemExit => e
37
+ e.status
38
+ ensure
39
+ $stderr = STDERR
40
+ $stdin = STDIN
41
+ $stdout = STDOUT
42
+ end
43
+
44
+ @kernel.exit(exit_code)
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module FootballCli
2
- VERSION = '0.0.6'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/football_cli.rb CHANGED
@@ -1,2 +1,6 @@
1
- require 'football_cli/version'
1
+ require 'thor'
2
+ require 'football_cli/configuration'
3
+ require 'football_cli/config'
2
4
  require 'football_cli/cli'
5
+ require 'football_cli/handler'
6
+ require 'football_cli/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Said Kaldybaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-20 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: thor
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: terminal-table
98
+ name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -114,6 +128,8 @@ files:
114
128
  - football_cli.gemspec
115
129
  - lib/football_cli.rb
116
130
  - lib/football_cli/cli.rb
131
+ - lib/football_cli/config.rb
132
+ - lib/football_cli/configuration.rb
117
133
  - lib/football_cli/format/base.rb
118
134
  - lib/football_cli/format/csv.rb
119
135
  - lib/football_cli/format/format_factory.rb
@@ -121,6 +137,7 @@ files:
121
137
  - lib/football_cli/format/table.rb
122
138
  - lib/football_cli/handler.rb
123
139
  - lib/football_cli/mapper.rb
140
+ - lib/football_cli/runner.rb
124
141
  - lib/football_cli/version.rb
125
142
  homepage: https://github.com/Saidbek/football_cli
126
143
  licenses: