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
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Nation do
4
+ let(:home_team) { JSONHelper::Nation.get(:home_team) }
5
+ let(:away_team) { JSONHelper::Nation.get(:away_team) }
6
+ let(:referee) { JSONHelper::Nation.get(:referee) }
7
+ let(:team) { JSONHelper::Nation.get(:team) }
8
+ let(:competition) { JSONHelper::Nation.get(:competition) }
9
+ let(:nation) { Infostrada::Nation }
10
+
11
+ describe '#initialize' do
12
+ context 'home team nation' do
13
+ let(:home_team_nation) { nation.new(home_team, 'home_team') }
14
+
15
+ it 'has id' do
16
+ expect(home_team_nation.id).to eq(2235)
17
+ end
18
+
19
+ it 'has name' do
20
+ expect(home_team_nation.name).to eq('Brazil')
21
+ end
22
+
23
+ it 'has short name' do
24
+ expect(home_team_nation.short_name).to eq('BRA')
25
+ end
26
+ end
27
+
28
+ context 'away team nation' do
29
+ let(:away_team_nation) { nation.new(away_team, 'away_team') }
30
+
31
+ it 'has id' do
32
+ expect(away_team_nation.id).to eq(2236)
33
+ end
34
+
35
+ it 'has name' do
36
+ expect(away_team_nation.name).to eq('Argentina')
37
+ end
38
+
39
+ it 'has short name' do
40
+ expect(away_team_nation.short_name).to eq('AR')
41
+ end
42
+ end
43
+
44
+ context 'referee nation' do
45
+ let(:referee_nation) { nation.new(referee, 'referee') }
46
+
47
+ it 'has id' do
48
+ expect(referee_nation.id).to eq(0)
49
+ end
50
+
51
+ it 'has name' do
52
+ expect(referee_nation.name).to eq('Portugal')
53
+ end
54
+
55
+ it 'has short name' do
56
+ expect(referee_nation.short_name).to eq('PT')
57
+ end
58
+ end
59
+
60
+ context 'team nation' do
61
+ let(:team_nation) { nation.new(team, 'team') }
62
+
63
+ it 'has id' do
64
+ expect(team_nation.id).to eq(2235)
65
+ end
66
+
67
+ it 'has name' do
68
+ expect(team_nation.name).to eq('Brazil')
69
+ end
70
+
71
+ it 'has short name' do
72
+ expect(team_nation.short_name).to eq('BRA')
73
+ end
74
+ end
75
+
76
+ context 'competition nation' do
77
+ let(:competition_nation) { nation.new(competition, 'competition') }
78
+
79
+ it 'has id' do
80
+ expect(competition_nation.id).to eq(2101)
81
+ end
82
+
83
+ it 'has name' do
84
+ expect(competition_nation.name).to eq('Europe')
85
+ end
86
+
87
+ it 'has short name' do
88
+ expect(competition_nation.short_name).to eq('EUR')
89
+ end
90
+ end
91
+ end
92
+
93
+ describe '.from_json' do
94
+ context 'home team nation' do
95
+ let(:home_team_nation_json) { nation.new(home_team, 'home_team').as_json }
96
+ let(:home_from_json) { nation.from_json(home_team_nation_json, 'home_team') }
97
+
98
+ it 'has id' do
99
+ expect(home_from_json.id).to eq(2235)
100
+ end
101
+
102
+ it 'has name' do
103
+ expect(home_from_json.name).to eq('Brazil')
104
+ end
105
+
106
+ it 'has short name' do
107
+ expect(home_from_json.short_name).to eq('BRA')
108
+ end
109
+ end
110
+
111
+ context 'away team nation' do
112
+ let(:away_team_nation_json) { nation.new(away_team, 'away_team').as_json }
113
+ let(:away_from_json) { nation.from_json(away_team_nation_json, 'away_team') }
114
+
115
+ it 'has id' do
116
+ expect(away_from_json.id).to eq(2236)
117
+ end
118
+
119
+ it 'has name' do
120
+ expect(away_from_json.name).to eq('Argentina')
121
+ end
122
+
123
+ it 'has short name' do
124
+ expect(away_from_json.short_name).to eq('AR')
125
+ end
126
+ end
127
+
128
+ context 'referee nation' do
129
+ let(:referee_nation_json) { nation.new(referee, 'referee').as_json }
130
+ let(:referee_from_json) { nation.from_json(referee_nation_json, 'referee') }
131
+
132
+ it 'has id' do
133
+ expect(referee_from_json.id).to eq(0)
134
+ end
135
+
136
+ it 'has name' do
137
+ expect(referee_from_json.name).to eq('Portugal')
138
+ end
139
+
140
+ it 'has short name' do
141
+ expect(referee_from_json.short_name).to eq('PT')
142
+ end
143
+ end
144
+
145
+ context 'team nation' do
146
+ let(:team_nation_json) { nation.new(team, 'team').as_json }
147
+ let(:team_from_json) { nation.from_json(team_nation_json, 'team') }
148
+
149
+ it 'has id' do
150
+ expect(team_from_json.id).to eq(2235)
151
+ end
152
+
153
+ it 'has name' do
154
+ expect(team_from_json.name).to eq('Brazil')
155
+ end
156
+
157
+ it 'has short name' do
158
+ expect(team_from_json.short_name).to eq('BRA')
159
+ end
160
+ end
161
+
162
+ context 'competition nation' do
163
+ let(:competition_nation_json) { nation.new(competition, 'competition').as_json }
164
+ let(:competition_from_json) { nation.from_json(competition_nation_json, 'competition') }
165
+
166
+ it 'has id' do
167
+ expect(competition_from_json.id).to eq(2101)
168
+ end
169
+
170
+ it 'has name' do
171
+ expect(competition_from_json.name).to eq('Europe')
172
+ end
173
+
174
+ it 'has short name' do
175
+ expect(competition_from_json.short_name).to eq('EUR')
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::PersonInfo do
4
+ let(:default) { JSONHelper::PersonInfo.get(:default) }
5
+ let(:person_id) { 611_005 }
6
+ let(:person_info) { Infostrada::PersonInfo }
7
+
8
+ let(:path) { 'GetPersonInfo' }
9
+ let(:uri) { "#{@base_url}/#{path}?#{@default_params}&&personid=#{person_id}" }
10
+
11
+ # [default] - infostrada returns an array
12
+ before do
13
+ stub_request(:get, uri)
14
+ .to_return(status: 200, body: [default].to_json)
15
+ end
16
+
17
+ describe '.where' do
18
+ it 'returns new person info' do
19
+ result = person_info.where(person_id: person_id)
20
+
21
+ expect(result).not_to be_nil
22
+ expect(result).to be_kind_of(person_info)
23
+ end
24
+ end
25
+
26
+ describe '#initialize' do
27
+ let(:default_person) { person_info.new(person_id, default) }
28
+
29
+ it 'has id' do
30
+ expect(default_person.id).to eq(person_id)
31
+ end
32
+
33
+ it 'has first name' do
34
+ expect(default_person.first_name).to eq(default['c_FirstName'])
35
+ end
36
+
37
+ it 'has last name' do
38
+ expect(default_person.last_name).to eq(default['c_LastName'])
39
+ end
40
+
41
+ it 'has public name' do
42
+ expect(default_person.public_name).to eq(default['c_PublicName'])
43
+ end
44
+
45
+ it 'has nickname' do
46
+ expect(default_person.nickname).to eq(default['c_Nickname'])
47
+ end
48
+
49
+ it 'has birthdate' do
50
+ expect(default_person.birthdate).not_to be_nil
51
+ end
52
+
53
+ it 'has height' do
54
+ expect(default_person.height).to eq(default['n_Height'])
55
+ end
56
+
57
+ it 'has weight' do
58
+ expect(default_person.weight).to eq(default['n_Weight'])
59
+ end
60
+
61
+ it 'has birth city' do
62
+ expect(default_person.birth_city).to eq(default['c_BirthCity'])
63
+ end
64
+
65
+ it 'has birth country' do
66
+ expect(default_person.birth_country).to eq(default['c_BirthCountry'])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Competition do
4
+ let(:default) { JSONHelper::Phase.get(:default).first }
5
+ let(:list) { JSONHelper::Phase.get(:list) }
6
+ let(:phase) { Infostrada::Phase }
7
+ let(:default_phase) { phase.new(default.clone) }
8
+ let(:serialized) { default_phase.as_json }
9
+ let(:edition_id) { 1 }
10
+ let(:uri) do
11
+ "#{@base_url}/GetPhaseList?#{@default_params}&&editionid=#{edition_id}"
12
+ end
13
+
14
+ before do
15
+ stub_request(:get, uri)
16
+ .to_return(status: 200, body: list.to_json)
17
+ end
18
+
19
+ describe '.where' do
20
+ it 'returns a list of phases' do
21
+ phases = phase.where(edition_id: edition_id)
22
+ expect(phases.count).to eq(list.count)
23
+ expect(phases.first).to be_a(phase)
24
+ end
25
+ end
26
+
27
+ describe '#initialize' do
28
+ let(:p) { phase.new(default.clone) }
29
+
30
+ it 'has id' do
31
+ expect(p.id).to eq(default['n_PhaseID'])
32
+ end
33
+
34
+ it 'has name' do
35
+ expect(p.name).to eq(default['c_Phase'])
36
+ end
37
+
38
+ it 'has level' do
39
+ expect(p.level).to eq(default['n_PhaseLevel'])
40
+ end
41
+
42
+ it 'has short_name' do
43
+ expect(p.short_name).to eq(default['c_PhaseShort'])
44
+ end
45
+
46
+ it 'has phase1_id' do
47
+ expect(p.phase1_id).to eq(default['n_Phase1ID'])
48
+ end
49
+
50
+ it 'has phase1_name' do
51
+ expect(p.phase1_name).to eq(default['c_Phase1'])
52
+ end
53
+
54
+ it 'has phase2_id' do
55
+ expect(p.phase2_id).to eq(default['n_Phase2ID'])
56
+ end
57
+
58
+ it 'has phase2_name' do
59
+ expect(p.phase2_name).to eq(default['c_Phase2'])
60
+ end
61
+
62
+ it 'has phase3_id' do
63
+ expect(p.phase3_id).to eq(default['n_Phase3ID'])
64
+ end
65
+
66
+ it 'has phase3_name' do
67
+ expect(p.phase3_name).to eq(default['c_Phase3'])
68
+ end
69
+
70
+ it 'has has_table' do
71
+ expect(p.has_table).to eq(default['b_Table'])
72
+ end
73
+
74
+ it 'has current' do
75
+ expect(p.current).to eq(default['b_Current'])
76
+ end
77
+
78
+ it 'has currents' do
79
+ expect(p.currents).to eq(default['b_Currents'])
80
+ end
81
+
82
+ it 'has start date' do
83
+ date = Date.parse(default['n_DateStart'].to_s)
84
+ expect(p.start_date).to eq(date)
85
+ end
86
+
87
+ it 'has end date' do
88
+ date = Date.parse(default['n_DateEnd'].to_s)
89
+ expect(p.end_date).to eq(date)
90
+ end
91
+ end
92
+
93
+ describe '.from_json' do
94
+ let(:from_json) { phase.from_json(serialized) }
95
+
96
+ it 'has id' do
97
+ expect(from_json.id).to eq(default_phase.id)
98
+ end
99
+
100
+ it 'has name' do
101
+ expect(from_json.name).to eq(default_phase.name)
102
+ end
103
+
104
+ it 'has level' do
105
+ expect(from_json.level).to eq(default_phase.level)
106
+ end
107
+
108
+ it 'has short_name' do
109
+ expect(from_json.short_name).to eq(default_phase.short_name)
110
+ end
111
+
112
+ it 'has phase1_id' do
113
+ expect(from_json.phase1_id).to eq(default_phase.phase1_id)
114
+ end
115
+
116
+ it 'has phase1_name' do
117
+ expect(from_json.phase1_name).to eq(default_phase.phase1_name)
118
+ end
119
+
120
+ it 'has phase2_id' do
121
+ expect(from_json.phase2_id).to eq(default_phase.phase2_id)
122
+ end
123
+
124
+ it 'has phase2_name' do
125
+ expect(from_json.phase2_name).to eq(default_phase.phase2_name)
126
+ end
127
+
128
+ it 'has phase3_id' do
129
+ expect(from_json.phase3_id).to eq(default_phase.phase3_id)
130
+ end
131
+
132
+ it 'has phase3_name' do
133
+ expect(from_json.phase3_name).to eq(default_phase.phase3_name)
134
+ end
135
+
136
+ it 'has has_table' do
137
+ expect(from_json.has_table).to eq(default_phase.has_table)
138
+ end
139
+
140
+ it 'has current' do
141
+ expect(from_json.current).to eq(default_phase.current)
142
+ end
143
+
144
+ it 'has currents' do
145
+ expect(from_json.currents).to eq(default_phase.currents)
146
+ end
147
+
148
+ it 'has start date' do
149
+ expect(from_json.start_date).to eq(default_phase.start_date)
150
+ end
151
+
152
+ it 'has end date' do
153
+ expect(from_json.end_date).to eq(default_phase.end_date)
154
+ end
155
+ end
156
+
157
+ module NullTable
158
+ class Infostrada::Table
159
+ class << self
160
+ attr_accessor :phase_id
161
+
162
+ def where(options = {})
163
+ @phase_id = options.delete(:phase_id)
164
+ true
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ # Only way to get the nulltable table scope
171
+ Mock = Struct.new(:phase_id) do
172
+ include NullTable
173
+ end
174
+
175
+ describe '#table' do
176
+ it 'calls Table where' do
177
+ phase.send(:include, NullTable)
178
+ dphase = phase.new(default.clone)
179
+ expect(dphase.table).to be(true)
180
+ expect(Mock::Infostrada::Table.phase_id).to be(default_phase.id)
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Infostrada::Player do
4
+ let(:default) { JSONHelper::Player.get(:default) }
5
+ let(:goalkeeper) { JSONHelper::Player.get(:goalkeeper) }
6
+ let(:player) { Infostrada::Player }
7
+ let(:p) { player.new(default) }
8
+
9
+ describe '#initialize' do
10
+ it 'has person_id' do
11
+ expect(p.person_id).to eq(default['n_PersonID'])
12
+ end
13
+
14
+ it 'has name' do
15
+ expect(p.name).to eq(default['c_Person'])
16
+ end
17
+
18
+ it 'has short_name' do
19
+ expect(p.short_name).to eq(default['c_PersonShort'])
20
+ end
21
+
22
+ it 'has birthdate' do
23
+ expect(p.birthdate).not_to be_nil
24
+ end
25
+
26
+ it 'has function' do
27
+ expect(p.function).to eq(default['c_Function'])
28
+ end
29
+
30
+ it 'has function_type' do
31
+ expect(p.function_type).to eq(default['n_FunctionType'])
32
+ end
33
+
34
+ it 'has shirt_number' do
35
+ expect(p.shirt_number).to eq(default['n_ShirtNr'])
36
+ end
37
+
38
+ it 'has contract_starts_at' do
39
+ expect(p.contract_starts_at).not_to be_nil
40
+ end
41
+
42
+ it 'has contract_ends_at' do
43
+ expect(p.contract_ends_at).not_to be_nil
44
+ end
45
+
46
+ it 'has nation' do
47
+ expect(p.nation).not_to be_nil
48
+ end
49
+
50
+ it 'calls set_season_stats' do
51
+ called = false
52
+ expect_any_instance_of(player).to receive(:set_season_stats) do
53
+ called = true
54
+ end
55
+ player.new(default.clone)
56
+
57
+ expect(called).to be(true)
58
+ end
59
+ end
60
+
61
+ describe '#set_season_stats' do
62
+ context 'season stats hash' do
63
+ it 'has matches' do
64
+ expect(p.season_stats[:matches]).to eq(default['n_Matches'])
65
+ end
66
+
67
+ it 'has matches_start' do
68
+ expect(p.season_stats[:matches_start]).to eq(default['n_MatchesStart'])
69
+ end
70
+
71
+ it 'has matches_out' do
72
+ expect(p.season_stats[:matches_out]).to eq(default['n_MatchesOut'])
73
+ end
74
+
75
+ it 'has matches_in' do
76
+ expect(p.season_stats[:matches_in]).to eq(default['n_MatchesIn'])
77
+ end
78
+
79
+ it 'has minutes_played' do
80
+ expect(p.season_stats[:minutes_played]).to eq(default['n_MinutesPlayed'])
81
+ end
82
+
83
+ it 'has goals' do
84
+ expect(p.season_stats[:goals]).to eq(default['n_Goals'])
85
+ end
86
+
87
+ it 'has own_goals' do
88
+ expect(p.season_stats[:own_goals]).to eq(default['n_OwnGoals'])
89
+ end
90
+
91
+ it 'has assists' do
92
+ expect(p.season_stats[:assists]).to eq(default['n_Assists'])
93
+ end
94
+
95
+ it 'has cards_yellow' do
96
+ expect(p.season_stats[:cards_yellow]).to eq(default['n_CardsYellow'])
97
+ end
98
+
99
+ it 'has cards_red' do
100
+ expect(p.season_stats[:cards_red]).to eq(default['n_CardsRed'])
101
+ end
102
+
103
+ it 'has cards_red_direct' do
104
+ expect(p.season_stats[:cards_red_direct]).to eq(default['n_CardsRedDirect'])
105
+ end
106
+
107
+ it 'has cards_red_from_yellow' do
108
+ expect(p.season_stats[:cards_red_from_yellow]).to eq(default['n_CardsRed2Yellow'])
109
+ end
110
+ end
111
+ end
112
+ end