infostrada 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +5 -13
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +2 -0
  4. data/.travis.yml +6 -0
  5. data/README.md +2 -0
  6. data/infostrada.gemspec +4 -1
  7. data/lib/infostrada.rb +6 -12
  8. data/lib/infostrada/call_refresh.rb +2 -1
  9. data/lib/infostrada/competition.rb +2 -1
  10. data/lib/infostrada/core_ext/hash.rb +14 -0
  11. data/lib/infostrada/core_ext/string.rb +19 -2
  12. data/lib/infostrada/match.rb +2 -2
  13. data/lib/infostrada/match_event.rb +1 -1
  14. data/lib/infostrada/mock.rb +76 -0
  15. data/lib/infostrada/nation.rb +2 -2
  16. data/lib/infostrada/person_info.rb +12 -12
  17. data/lib/infostrada/phase.rb +11 -13
  18. data/lib/infostrada/player.rb +11 -11
  19. data/lib/infostrada/squad.rb +3 -6
  20. data/lib/infostrada/team.rb +4 -4
  21. data/lib/infostrada/team_info.rb +1 -1
  22. data/lib/infostrada/team_request.rb +2 -5
  23. data/lib/infostrada/version.rb +1 -1
  24. data/spec/base_request_spec.rb +19 -0
  25. data/spec/competition_spec.rb +67 -0
  26. data/spec/edition_request_spec.rb +20 -0
  27. data/spec/edition_spec.rb +111 -0
  28. data/spec/endpoint_spec.rb +62 -0
  29. data/spec/formatter_spec.rb +12 -0
  30. data/spec/helpers/json_helper.rb +41 -0
  31. data/spec/json/competition.json +55 -0
  32. data/spec/json/edition.json +61 -0
  33. data/spec/json/edition_request.json +242 -0
  34. data/spec/json/endpoint.json +46 -0
  35. data/spec/json/match.json +945 -0
  36. data/spec/json/match_event.json +187 -0
  37. data/spec/json/match_event_list.json +411 -0
  38. data/spec/json/nation.json +302 -0
  39. data/spec/json/person_info.json +52 -0
  40. data/spec/json/phase.json +158 -0
  41. data/spec/json/player.json +93 -0
  42. data/spec/json/referee.json +184 -0
  43. data/spec/json/sample_responses/all_editions.json +243 -0
  44. data/spec/json/sample_responses/competition_edition_league_21594_serie_a.json +4 -0
  45. data/spec/json/sample_responses/competition_match_days_league_21594_serie_a.json +473 -0
  46. data/spec/json/sample_responses/competition_match_list_league_21594_serie_a.json +25465 -0
  47. data/spec/json/sample_responses/competition_phases_cup_21204_capital_one_cup.json +138 -0
  48. data/spec/json/sample_responses/competition_phases_league_21594_serie_a.json +24 -0
  49. data/spec/json/sample_responses/competition_table_phase_114165_serie_a_2015.json +585 -0
  50. data/spec/json/sample_responses/competition_teams_league_21594.json +165 -0
  51. data/spec/json/sample_responses/get_api_call_refresh_module.json +65 -0
  52. data/spec/json/sample_responses/match_events_1788734_real_atletico_final_champions.json +7960 -0
  53. data/spec/json/sample_responses/match_info_1788734_real_atletico_final_champions.json +96 -0
  54. data/spec/json/sample_responses/match_info_upcoming_1968820_serie_a.json +96 -0
  55. data/spec/json/sample_responses/person_info_611005_bale.json +55 -0
  56. data/spec/json/sample_responses/squad_100163_on_edition_21590.json +1355 -0
  57. data/spec/json/sample_responses/team_info_100163.json +28 -0
  58. data/spec/json/sample_responses/template_dummy_response.json +4 -0
  59. data/spec/json/squad.json +514 -0
  60. data/spec/json/team.json +10 -0
  61. data/spec/json/team_info.json +25 -0
  62. data/spec/json/team_request.json +68 -0
  63. data/spec/match_event_list_spec.rb +21 -0
  64. data/spec/match_event_spec.rb +159 -0
  65. data/spec/match_spec.rb +430 -0
  66. data/spec/nation_spec.rb +179 -0
  67. data/spec/person_info_spec.rb +69 -0
  68. data/spec/phase_spec.rb +183 -0
  69. data/spec/player_spec.rb +112 -0
  70. data/spec/referee_spec.rb +71 -0
  71. data/spec/spec_helper.rb +117 -0
  72. data/spec/squad_spec.rb +25 -0
  73. data/spec/team_info_spec.rb +77 -0
  74. data/spec/team_request_spec.rb +24 -0
  75. data/spec/team_spec.rb +76 -0
  76. metadata +213 -43
@@ -11,7 +11,7 @@ module Infostrada
11
11
  def self.fetch(team_id)
12
12
  info_hash = get!(URL, query: { teamid: team_id.to_i })
13
13
 
14
- info_hash.first ? self.new(info_hash.first.merge({ 'teamid' => team_id.to_i })) : nil
14
+ info_hash.first ? new(info_hash.first.merge({ 'teamid' => team_id.to_i })) : nil
15
15
  end
16
16
 
17
17
  def initialize(hash)
@@ -9,12 +9,9 @@ module Infostrada
9
9
  def self.get_edition(edition_id)
10
10
  list = get!(URLS[:list], query: { editionid: edition_id.to_i })
11
11
 
12
- teams = []
13
- list.each do |team_hash|
14
- teams << Team.new(team_hash.merge('edition_id' => edition_id.to_i), '')
12
+ list.map do |team_hash|
13
+ Team.new(team_hash.merge('edition_id' => edition_id.to_i), '')
15
14
  end
16
-
17
- teams
18
15
  end
19
16
  end
20
17
  end
@@ -1,3 +1,3 @@
1
1
  module Infostrada
2
- VERSION = '0.1.26'
2
+ VERSION = '0.1.27'
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::BaseRequest do
4
+ let(:path) { 'GetEditionList' }
5
+ let(:auth_uri) { "#{@base_url}/#{path}?#{@default_params}" }
6
+ let(:base_request) { Infostrada::BaseRequest }
7
+
8
+ before do
9
+ stub_request(:get, auth_uri)
10
+ .to_return(status: 200, body: [])
11
+ end
12
+
13
+ describe '.get!' do
14
+ it 'http basic authenticates' do
15
+ result = base_request.get!("/#{path}")
16
+ expect(result.body).to eq([])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Competition do
4
+ let(:default) { JSONHelper::Competition.get(:default) }
5
+
6
+ let(:without_nation) do
7
+ JSONHelper::Competition.get(:without_nation)
8
+ end
9
+
10
+ let(:serialized) do
11
+ Infostrada::Competition.new(default.clone).as_json
12
+ end
13
+
14
+ describe '#initialize' do
15
+ it 'has id' do
16
+ result = Infostrada::Competition.new(default.clone)
17
+ expect(result.id).to be(default['n_CompetitionID'])
18
+ end
19
+
20
+ it 'has name' do
21
+ result = Infostrada::Competition.new(default.clone)
22
+ expect(result.name).to be(default['c_Competition'])
23
+ end
24
+
25
+ it 'has nation' do
26
+ result = Infostrada::Competition.new(default.clone)
27
+ expect(result.nation).to_not be(nil)
28
+ end
29
+
30
+ context 'missing nation' do
31
+ it 'doesn\'t fail' do
32
+ result = Infostrada::Competition.new(without_nation.clone)
33
+
34
+ expect(result).not_to be(nil)
35
+ expect(result.id).to be(without_nation['n_CompetitionID'])
36
+ expect(result.name).to be(without_nation['c_Competition'])
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '.from_json' do
42
+ it 'has id' do
43
+ result = Infostrada::Competition.from_json(serialized)
44
+ expect(result.id).to be(serialized['id'])
45
+ end
46
+
47
+ it 'has name' do
48
+ result = Infostrada::Competition.from_json(serialized)
49
+ expect(result.name).to be(serialized['name'])
50
+ end
51
+
52
+ it 'has nation' do
53
+ result = Infostrada::Competition.from_json(serialized)
54
+ expect(result.nation).to_not be(nil)
55
+ end
56
+
57
+ context 'missing nation' do
58
+ it 'doesn\'t fail' do
59
+ result = Infostrada::Competition.from_json(serialized)
60
+
61
+ expect(result).not_to be(nil)
62
+ expect(result.id).to be(serialized['id'])
63
+ expect(result.name).to be(serialized['name'])
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::EditionRequest do
4
+ let(:default) { JSONHelper::EditionRequest.get(:default) }
5
+ let(:path) { 'GetEditionList' }
6
+ let(:uri) { "#{@base_url}/#{path}?#{@default_params}" }
7
+
8
+ before do
9
+ stub_request(:get, uri)
10
+ .to_return(status: 200, body: default.to_json)
11
+ end
12
+
13
+ describe '.get_list' do
14
+ it 'returns array of editions' do
15
+ result = Infostrada::EditionRequest.get_list
16
+ expect(result).not_to be(nil)
17
+ expect(result.count).to equal(default.count)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Edition do
4
+ let(:default) { JSONHelper::Edition.get(:default) }
5
+ let(:without_start_date) { JSONHelper::Edition.get(:without_start_date) }
6
+ let(:without_end_date) { JSONHelper::Edition.get(:without_end_date) }
7
+
8
+ describe '#initialize' do
9
+ context 'with complete edition' do
10
+ let(:default_edition) { Infostrada::Edition.new(default.clone) }
11
+
12
+ it 'has id' do
13
+ expect(default_edition.id).to be(default['n_EditionID'])
14
+ end
15
+
16
+ it 'has season' do
17
+ expect(default_edition.season).to be(default['c_Season'])
18
+ end
19
+
20
+ it 'has start_date' do
21
+ expect(default_edition.start_date).not_to be_nil
22
+ end
23
+
24
+ it 'has end_date' do
25
+ expect(default_edition.end_date).not_to be_nil
26
+ end
27
+
28
+ it 'has competition' do
29
+ expect(default_edition.competition).not_to be_nil
30
+ end
31
+ end
32
+
33
+ context 'wihtout start_date' do
34
+ let(:no_start_edition) { Infostrada::Edition.new(without_start_date.clone) }
35
+
36
+ it 'doesn\'t fail' do
37
+ expect(no_start_edition).not_to be_nil
38
+ end
39
+
40
+ it 'not_has end_date' do
41
+ expect(no_start_edition.start_date).to be_nil
42
+ end
43
+ end
44
+
45
+ context 'wihtout end_date' do
46
+ let(:no_end_edition) { Infostrada::Edition.new(without_end_date.clone) }
47
+
48
+ it 'doesn\'t fail' do
49
+ expect(no_end_edition).not_to be_nil
50
+ end
51
+
52
+ it 'doesn\' have end_date' do
53
+ expect(no_end_edition.end_date).to be_nil
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '.from_json' do
59
+ let(:json_default) { Infostrada::Edition.new(default.clone).as_json }
60
+ let(:json_without_end_date) { Infostrada::Edition.new(without_end_date.clone).as_json }
61
+ let(:json_without_start_date) { Infostrada::Edition.new(without_start_date.clone).as_json }
62
+
63
+ context 'with complete edition' do
64
+ let(:from_json_edition) { Infostrada::Edition.from_json(json_default.clone) }
65
+
66
+ it 'has id' do
67
+ expect(from_json_edition.id).to be(json_default['id'])
68
+ end
69
+
70
+ it 'has season' do
71
+ expect(from_json_edition.season).to be(json_default['season'])
72
+ end
73
+
74
+ it 'has start_date' do
75
+ expect(from_json_edition.start_date).not_to be_nil
76
+ end
77
+
78
+ it 'has end_date' do
79
+ expect(from_json_edition.end_date).not_to be_nil
80
+ end
81
+
82
+ it 'has competition' do
83
+ expect(from_json_edition.competition).not_to be_nil
84
+ end
85
+ end
86
+
87
+ context 'wihtout start_date' do
88
+ let(:from_json_no_start_edition) { Infostrada::Edition.from_json(json_without_start_date.clone) }
89
+
90
+ it 'doesn\'t fail' do
91
+ expect(from_json_no_start_edition).not_to be_nil
92
+ end
93
+
94
+ it 'not_has end_date' do
95
+ expect(from_json_no_start_edition.start_date).to be_nil
96
+ end
97
+ end
98
+
99
+ context 'wihtout end_date' do
100
+ let(:from_json_no_end_edition) { Infostrada::Edition.from_json(json_without_end_date.clone) }
101
+
102
+ it 'doesn\'t fail' do
103
+ expect(from_json_no_end_edition).not_to be_nil
104
+ end
105
+
106
+ it 'not_has end_date' do
107
+ expect(from_json_no_end_edition.end_date).to be_nil
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Endpoint do
4
+ let(:endpoints) { JSONHelper::Endpoint.get(:endpoints) }
5
+ let(:live_table) { JSONHelper::Endpoint.get(:live_table) }
6
+ let(:match_info) { JSONHelper::Endpoint.get(:match_info) }
7
+ let(:action_list) { JSONHelper::Endpoint.get(:action_list) }
8
+ let(:endpoint) { Infostrada::Endpoint }
9
+
10
+ def all_from_endpoints
11
+ endpoints.map { |e| endpoint.new(e) }
12
+ end
13
+
14
+ describe '#initialize' do
15
+ it 'has method' do
16
+ result = all_from_endpoints
17
+
18
+ result.each_with_index do |endpoint, i|
19
+ expect(endpoint.method).not_to be_nil
20
+ expect(endpoint.method).to equal(endpoints[i]['c_Method'])
21
+ end
22
+ end
23
+
24
+ it 'has last_modified' do
25
+ result = all_from_endpoints
26
+
27
+ result.each do |endpoint|
28
+ expect(endpoint.last_modified).not_to be_nil
29
+ end
30
+ end
31
+
32
+ it 'has query string' do
33
+ result = all_from_endpoints
34
+
35
+ result.each_with_index do |endpoint, i|
36
+ expect(endpoint.query_string).not_to be_nil
37
+ expect(endpoint.query_string).to equal(endpoints[i]['c_QueryString'])
38
+ end
39
+ end
40
+
41
+ context 'with live table' do
42
+ it 'has phase id' do
43
+ res = endpoint.new(live_table)
44
+ expect(res.phase_id.to_i).to equal(109223)
45
+ end
46
+ end
47
+
48
+ context 'with match info' do
49
+ it 'has match id' do
50
+ res = endpoint.new(match_info)
51
+ expect(res.match_id.to_i).to equal(1877488)
52
+ end
53
+ end
54
+
55
+ context 'with action list' do
56
+ it 'has match id' do
57
+ res = endpoint.new(match_info)
58
+ expect(res.match_id.to_i).to equal(1877488)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Formatter do
4
+ let(:formatter) { Infostrada::Formatter }
5
+
6
+ describe '.format_date' do
7
+ it 'parses date' do
8
+ date = '/Date(1428426230563+0200)/'
9
+ expect(formatter.format_date(date).to_i).to eq(Time.parse('2015-04-07 19:03:50 UTC').to_i)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ # Automatically loads json files with an associated class for loading fixture
2
+ module JSONHelper
3
+ class << self
4
+ # Uhuhuh! What a cache!
5
+ def cache
6
+ @cache ||= {}
7
+ end
8
+
9
+ def cache_or_load(path)
10
+ cache[path] ||= begin
11
+ file = File.read(path)
12
+ JSON.parse(file).symbolize_keys
13
+ end
14
+ end
15
+
16
+ def load_file(name)
17
+ path = File.expand_path("../../json/#{name}", __FILE__)
18
+ cache_or_load(path)
19
+ end
20
+ end
21
+
22
+ # TODO: Better way to deal with this.
23
+ # Declaring a class for each one was too much.
24
+ # With this, it works, but is too meta, I think.
25
+ class Generic
26
+ def self.get(name)
27
+ new.get(name)
28
+ end
29
+
30
+ def get(name)
31
+ file_name = "#{File.basename(self.class.name.info_underscore)}.json"
32
+ fixtures = ::JSONHelper.load_file(file_name)
33
+ fixtures[name.to_sym].clone
34
+ end
35
+ end
36
+
37
+ Dir[File.expand_path('../../json/*.json', __FILE__)].each do |file_name|
38
+ klass_name = "#{File.basename(file_name, '.json').info_camelize}"
39
+ JSONHelper.const_set(klass_name, Class.new(Generic))
40
+ end
41
+ end
@@ -0,0 +1,55 @@
1
+ {
2
+ "default": {
3
+ "n_CompetitionID": 290,
4
+ "c_Competition": "Community Shield",
5
+ "n_CompetitionSet": 2,
6
+ "n_CompetitionNatioGeoID": 2208,
7
+ "c_CompetitionNatio": "England",
8
+ "c_CompetitionNatioShort": "ENG",
9
+ "n_CompetitionLevel": 0,
10
+ "n_EditionID": 21053,
11
+ "c_Season": "2014/2015",
12
+ "d_EditionStartDate": "/Date(1407621600000+0200)/",
13
+ "d_EditionEndDate": "/Date(1407621600000+0200)/",
14
+ "n_PhaseID": null
15
+ },
16
+ "without_nation": {
17
+ "n_CompetitionID": 290,
18
+ "c_Competition": "Community Shield",
19
+ "n_CompetitionSet": 2,
20
+ "n_CompetitionLevel": 0,
21
+ "n_EditionID": 21053,
22
+ "c_Season": "2014/2015",
23
+ "d_EditionStartDate": "/Date(1407621600000+0200)/",
24
+ "d_EditionEndDate": "/Date(1407621600000+0200)/",
25
+ "n_PhaseID": null
26
+ },
27
+ "another": {
28
+ "n_CompetitionID": 199,
29
+ "c_Competition": "S\u00e9rie A",
30
+ "n_CompetitionSet": 1,
31
+ "n_CompetitionNatioGeoID": 2235,
32
+ "c_CompetitionNatio": "Brazil",
33
+ "c_CompetitionNatioShort": "BRA",
34
+ "n_CompetitionLevel": 1,
35
+ "n_EditionID": 21594,
36
+ "c_Season": "2015",
37
+ "d_EditionStartDate": "/Date(1431122400000+0200)/",
38
+ "d_EditionEndDate": "/Date(1449356400000+0100)/",
39
+ "n_PhaseID": null
40
+ },
41
+ "league": {
42
+ "n_CompetitionID": 199,
43
+ "c_Competition": "S\u00e9rie A",
44
+ "n_CompetitionSet": 1,
45
+ "n_CompetitionNatioGeoID": 2235,
46
+ "c_CompetitionNatio": "Brazil",
47
+ "c_CompetitionNatioShort": "BRA",
48
+ "n_CompetitionLevel": 1,
49
+ "n_EditionID": 21594,
50
+ "c_Season": "2015",
51
+ "d_EditionStartDate": "/Date(1431122400000+0200)/",
52
+ "d_EditionEndDate": "/Date(1449356400000+0100)/",
53
+ "n_PhaseID": null
54
+ }
55
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "default": {
3
+ "n_CompetitionID": 255,
4
+ "c_Competition": "Supercopa de Espana",
5
+ "n_CompetitionSet": 2,
6
+ "n_CompetitionNatioGeoID": 2203,
7
+ "c_CompetitionNatio": "Spain",
8
+ "c_CompetitionNatioShort": "ESP",
9
+ "n_CompetitionLevel": 0,
10
+ "n_EditionID": 21056,
11
+ "c_Season": "2014/2015",
12
+ "d_EditionStartDate": "/Date(1408399200000+0200)/",
13
+ "d_EditionEndDate": "/Date(1408658400000+0200)/",
14
+ "n_PhaseID": null
15
+ },
16
+
17
+ "without_competition": {
18
+ "n_CompetitionID": 67,
19
+ "c_Competition": "Liga BBVA",
20
+ "n_CompetitionSet": 1,
21
+ "n_CompetitionNatioGeoID": 2203,
22
+ "c_CompetitionNatio": "Spain",
23
+ "c_CompetitionNatioShort": "ESP",
24
+ "n_CompetitionLevel": 1,
25
+ "n_EditionID": 21411,
26
+ "c_Season": "2014/2015",
27
+ "d_EditionStartDate": "/Date(1408744800000+0200)/",
28
+ "d_EditionEndDate": "/Date(1432418400000+0200)/",
29
+ "n_PhaseID": null
30
+ },
31
+
32
+ "without_start_date": {
33
+ "n_CompetitionID": 255,
34
+ "c_Competition": "Supercopa de Espana",
35
+ "n_CompetitionSet": 2,
36
+ "n_CompetitionNatioGeoID": 2203,
37
+ "c_CompetitionNatio": "Spain",
38
+ "c_CompetitionNatioShort": "ESP",
39
+ "n_CompetitionLevel": 0,
40
+ "n_EditionID": 21056,
41
+ "c_Season": "2014/2015",
42
+ "d_EditionStartDate": null,
43
+ "d_EditionEndDate": "/Date(1408658400000+0200)/",
44
+ "n_PhaseID": null
45
+ },
46
+
47
+ "without_end_date": {
48
+ "n_CompetitionID": 255,
49
+ "c_Competition": "Supercopa de Espana",
50
+ "n_CompetitionSet": 2,
51
+ "n_CompetitionNatioGeoID": 2203,
52
+ "c_CompetitionNatio": "Spain",
53
+ "c_CompetitionNatioShort": "ESP",
54
+ "n_CompetitionLevel": 0,
55
+ "n_EditionID": 21056,
56
+ "c_Season": "2014/2015",
57
+ "d_EditionStartDate": "/Date(1408399200000+0200)/",
58
+ "d_EditionEndDate": null,
59
+ "n_PhaseID": null
60
+ }
61
+ }