foot_stats 0.0.1

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 (40) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +72 -0
  6. data/Rakefile +1 -0
  7. data/foot_stats.gemspec +26 -0
  8. data/lib/foot_stats/championship.rb +66 -0
  9. data/lib/foot_stats/championship_classification.rb +55 -0
  10. data/lib/foot_stats/error_response.rb +13 -0
  11. data/lib/foot_stats/match.rb +77 -0
  12. data/lib/foot_stats/narration.rb +69 -0
  13. data/lib/foot_stats/request.rb +58 -0
  14. data/lib/foot_stats/resource.rb +27 -0
  15. data/lib/foot_stats/response.rb +61 -0
  16. data/lib/foot_stats/setup.rb +27 -0
  17. data/lib/foot_stats/team.rb +37 -0
  18. data/lib/foot_stats/version.rb +3 -0
  19. data/lib/foot_stats.rb +14 -0
  20. data/spec/cassettes/championship.yml +62 -0
  21. data/spec/cassettes/championship_classification.yml +76 -0
  22. data/spec/cassettes/championship_classification_error_response.yml +63 -0
  23. data/spec/cassettes/championship_match.yml +82 -0
  24. data/spec/cassettes/championship_match_error_response.yml +63 -0
  25. data/spec/cassettes/championship_teams.yml +68 -0
  26. data/spec/cassettes/championship_teams_error_response.yml +63 -0
  27. data/spec/cassettes/error_response.yml +62 -0
  28. data/spec/cassettes/match_narration.yml +83 -0
  29. data/spec/cassettes/match_narration_error_response.yml +63 -0
  30. data/spec/cassettes/match_null_narration.yml +73 -0
  31. data/spec/foot_stats/championship_classification_spec.rb +53 -0
  32. data/spec/foot_stats/championship_spec.rb +77 -0
  33. data/spec/foot_stats/match_spec.rb +67 -0
  34. data/spec/foot_stats/narration_spec.rb +69 -0
  35. data/spec/foot_stats/request_spec.rb +43 -0
  36. data/spec/foot_stats/response_spec.rb +72 -0
  37. data/spec/foot_stats/setup_spec.rb +6 -0
  38. data/spec/foot_stats/team_spec.rb +38 -0
  39. data/spec/spec_helper.rb +15 -0
  40. metadata +184 -0
@@ -0,0 +1,73 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://footstats.com.br/modyo.asmx/Narracao
6
+ body:
7
+ encoding: US-ASCII
8
+ string: Usuario=&Senha=&Partida=19
9
+ headers:
10
+ accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ accept-encoding:
13
+ - gzip, deflate
14
+ content-length:
15
+ - '26'
16
+ content-type:
17
+ - application/x-www-form-urlencoded
18
+ user-agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: !binary |-
24
+ T0s=
25
+ headers:
26
+ !binary "ZGF0ZQ==":
27
+ - !binary |-
28
+ VGh1LCAwMyBKYW4gMjAxMyAwMzozMDo0MCBHTVQ=
29
+ !binary "c2VydmVy":
30
+ - !binary |-
31
+ TWljcm9zb2Z0LUlJUy82LjA=
32
+ !binary "eC1wb3dlcmVkLWJ5":
33
+ - !binary |-
34
+ QVNQLk5FVA==
35
+ !binary "eC1hc3BuZXQtdmVyc2lvbg==":
36
+ - !binary |-
37
+ Mi4wLjUwNzI3
38
+ !binary "Y2FjaGUtY29udHJvbA==":
39
+ - !binary |-
40
+ bm8tY2FjaGU=
41
+ !binary "cHJhZ21h":
42
+ - !binary |-
43
+ bm8tY2FjaGU=
44
+ !binary "ZXhwaXJlcw==":
45
+ - !binary |-
46
+ LTE=
47
+ !binary "Y29udGVudC10eXBl":
48
+ - !binary |-
49
+ dGV4dC94bWw7IGNoYXJzZXQ9dXRmLTg=
50
+ !binary "Y29udGVudC1sZW5ndGg=":
51
+ - !binary |-
52
+ MTM4
53
+ body:
54
+ encoding: ASCII-8BIT
55
+ string: >
56
+ <string xmlns="http://tempuri.org/">
57
+ {"Campeonato":{
58
+ "@Id":"172",
59
+ "@Nome":"Camp. Mineiro 2012",
60
+ "@Temporada":"2012",
61
+ "Partida":{
62
+ "@Id":"34829",
63
+ "@Rodada":"1",
64
+ "@Placar":" - ",
65
+ "@TemDisputaPenaltis":"Nao"
66
+ },
67
+ "Narracoes":null
68
+ }}
69
+ </string>
70
+ http_version: !binary |-
71
+ MS4x
72
+ recorded_at: Thu, 03 Jan 2013 03:30:43 GMT
73
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe ChampionshipClassification do
6
+ describe '.all' do
7
+ context "normal response" do
8
+ use_vcr_cassette 'championship_classification'
9
+
10
+ subject { ChampionshipClassification.all(championship: 198).first }
11
+
12
+ its(:team_source_id) { should eq 1487 }
13
+ its(:group) { should eq '' }
14
+ its(:position) { should eq '1' }
15
+ its(:points) { should eq '30' }
16
+ its(:games) { should eq '10' }
17
+ its(:victories) { should eq '10' }
18
+ its(:draws) { should eq '0' }
19
+ its(:loss) { should eq '0' }
20
+ its(:goals_for) { should eq '23' }
21
+ its(:goals_against) { should eq '9' }
22
+ its(:goals_balance) { should eq '14' }
23
+ its(:home_victories) { should eq '5' }
24
+ its(:outside_victories) { should eq '5' }
25
+ its(:home_draws) { should eq '0' }
26
+ its(:outside_draws) { should eq '0' }
27
+ its(:home_defeats) { should eq '0' }
28
+ its(:outside_defeats) { should eq '0' }
29
+ its(:max_point) { should eq '33' }
30
+ its(:use) { should eq '' }
31
+ end
32
+
33
+ context "error response" do
34
+ use_vcr_cassette 'championship_classification_error_response'
35
+ subject { ChampionshipClassification.all(championship: 198) }
36
+
37
+ its(:message) { should eq 'Usuário ou senha Inválidos' }
38
+ end
39
+ end
40
+
41
+ describe ".resource_name" do
42
+ subject { ChampionshipClassification }
43
+
44
+ its(:resource_name) { should eq 'ListaClassificacao' }
45
+ end
46
+
47
+ describe ".resource_key" do
48
+ subject { ChampionshipClassification }
49
+
50
+ its(:resource_key) { should eq 'Campeonato' }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe Championship do
6
+ describe '.all' do
7
+ context "normal response" do
8
+ use_vcr_cassette 'championship'
9
+ subject { Championship.all.first }
10
+
11
+ its(:source_id) { should be 172 }
12
+ its(:name) { should eq 'Camp. Paulista 2012' }
13
+ its(:has_classification) { should be true }
14
+ its(:current_round) { should be 1 }
15
+ its(:total_rounds) { should be 18 }
16
+ end
17
+
18
+ context "error response" do
19
+ use_vcr_cassette 'error_response'
20
+ subject { Championship.all }
21
+
22
+ its(:message) { should eq 'Usuário ou senha Inválidos' }
23
+ end
24
+ end
25
+
26
+ describe "#source_id" do
27
+ subject { Championship.new(source_id: 71) }
28
+
29
+ its(:source_id) { should be 71 }
30
+ end
31
+
32
+ describe "#name" do
33
+ subject { Championship.new(name: 'Campeonato Carioca') }
34
+
35
+ its(:name) { should eq 'Campeonato Carioca' }
36
+ end
37
+
38
+ describe "#has_classification" do
39
+ subject { Championship.new(has_classification: false) }
40
+
41
+ its(:has_classification) { should be false }
42
+ end
43
+
44
+ describe "#current_round" do
45
+ subject { Championship.new(current_round: 20) }
46
+
47
+ its(:current_round) { should be 20 }
48
+ end
49
+
50
+ describe "#total_rounds" do
51
+ subject { Championship.new(total_rounds: 40) }
52
+
53
+ its(:total_rounds) { should be 40 }
54
+ end
55
+
56
+ describe "#classification" do
57
+ it 'should call all from championship passing the id' do
58
+ ChampionshipClassification.should_receive(:all).with(championship: 12)
59
+ Championship.new(source_id: 12).classification
60
+ end
61
+ end
62
+
63
+ describe "#teams" do
64
+ it 'should call all from championship passing the id' do
65
+ Team.should_receive(:all).with(championship: 12)
66
+ Championship.new(source_id: 12).teams
67
+ end
68
+ end
69
+
70
+ describe "#matches" do
71
+ it 'should call all from championship passing the id' do
72
+ Match.should_receive(:all).with(championship: 12)
73
+ Championship.new(source_id: 12).matches
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe Match do
6
+ describe ".all" do
7
+ context "normal response" do
8
+ use_vcr_cassette 'championship_match'
9
+
10
+ subject { Match.all(championship: 198).first }
11
+
12
+ its(:source_id) { should eq 34829 }
13
+ its(:date) { should eq '1/29/2012 4:00:00 PM' }
14
+ its(:status) { should eq 'Partida não iniciada' }
15
+ its(:referee) { should eq '0' }
16
+ its(:stadium) { should eq 'Ronaldo Junqueira' }
17
+ its(:city) { should eq 'Poços de Caldas' }
18
+ its(:state) { should eq 'MG' }
19
+ its(:country) { should eq 'Brasil' }
20
+ its(:has_statistic) { should eq 'Não' }
21
+ its(:has_narration) { should eq 'Não' }
22
+ its(:round) { should eq '1' }
23
+ its(:phase) { should eq 'Primeira Fase' }
24
+ its(:cup) { should eq '9' }
25
+ its(:group) { should eq '3' }
26
+ its(:game_number) { should eq '100' }
27
+ its(:live) { should eq 'Não' }
28
+
29
+ its(:home_team) { should eq 1077 }
30
+ its(:home_team_name) { should eq 'Caldense' }
31
+ its(:home_score) { should eq ' ' }
32
+ its(:home_penalties_score) { should eq '' }
33
+
34
+ its(:visitor_team) { should eq 1242 }
35
+ its(:visitor_team_name) { should eq 'Tupi' }
36
+ its(:visitor_score) { should eq ' ' }
37
+ its(:visitor_penalties_score) { should eq '' }
38
+ end
39
+
40
+ context "error response" do
41
+ use_vcr_cassette 'championship_match_error_response'
42
+ subject { Match.all(championship: 198) }
43
+
44
+ its(:message) { should eq 'Usuário ou senha Inválidos' }
45
+ end
46
+ end
47
+
48
+ describe ".resource_name" do
49
+ subject { Match }
50
+
51
+ its(:resource_name) { should eq 'ListaPartidas' }
52
+ end
53
+
54
+ describe ".resource_key" do
55
+ subject { Match }
56
+
57
+ its(:resource_key) { should eq 'Partidas' }
58
+ end
59
+
60
+ describe "#narrations" do
61
+ it 'should call all from championship passing the id' do
62
+ Narration.should_receive(:all).with(match: 12)
63
+ Match.new(source_id: 12).narrations
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe Narration do
6
+ describe ".all" do
7
+ context "null narration" do
8
+ use_vcr_cassette 'match_null_narration'
9
+ let(:empty_narrations) { Narration.all(match: 19).first }
10
+ subject { empty_narrations }
11
+
12
+ its(:championship_id) { should eq 172 }
13
+ its(:name) { should eq 'Camp. Mineiro 2012' }
14
+ its(:season) { should eq '2012' }
15
+ its(:match_id) { should eq 34829 }
16
+ its(:score) { should eq ' - ' }
17
+ its(:has_penalty) { should eq 'Nao' }
18
+
19
+ its(:details) { should eq [] }
20
+ end
21
+
22
+ context "with narrations" do
23
+ use_vcr_cassette 'match_narration'
24
+ let(:narrations) { Narration.all(match: 19).first }
25
+ subject { narrations }
26
+
27
+ its(:championship_id) { should eq 172 }
28
+ its(:name) { should eq 'Camp. Mineiro 2012' }
29
+ its(:season) { should eq '2012' }
30
+ its(:match_id) { should eq 34829 }
31
+ its(:score) { should eq ' - ' }
32
+ its(:has_penalty) { should eq 'Nao' }
33
+
34
+ context "narrations" do
35
+ subject { narrations.details.first }
36
+
37
+ its(:source_id) { should eq 109 }
38
+ its(:team_source_id) { should eq 18 }
39
+ its(:team_name) { should eq 'Santos' }
40
+ its(:player_source_id) { should eq 11 }
41
+ its(:player_name) { should eq 'Neymar' }
42
+ its(:period) { should eq '1' }
43
+ its(:moment) { should eq '23' }
44
+ its(:description) { should eq 'Impedimento' }
45
+ its(:action) { should eq 'acao' }
46
+ end
47
+ end
48
+
49
+ context "error response" do
50
+ use_vcr_cassette 'match_narration_error_response'
51
+ subject { Narration.all(match: 19) }
52
+
53
+ its(:message) { should eq 'Usuário ou senha Inválidos' }
54
+ end
55
+ end
56
+
57
+ describe ".resource_name" do
58
+ subject { Narration }
59
+
60
+ its(:resource_name) { should eq 'Narracao' }
61
+ end
62
+
63
+ describe ".resource_key" do
64
+ subject { Narration }
65
+
66
+ its(:resource_key) { should eq 'Campeonato' }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module FootStats
4
+ describe Request do
5
+ subject { Request.new(stub(resource_name: 'fake', resource_key: 'fake_key')) }
6
+
7
+ before do
8
+ Request.any_instance.stub(:post).and_return('{}')
9
+ end
10
+
11
+ describe '#resource_name' do
12
+ its(:resource_name) { should eq 'fake' }
13
+ end
14
+
15
+ describe '#resource_key' do
16
+ its(:resource_key) { should eq 'fake_key' }
17
+ end
18
+
19
+ describe '#request_url' do
20
+ it 'should return the base url with resource name' do
21
+ Setup.stub(:base_url).and_return('http://foo.com')
22
+ subject.request_url.should eq 'http://foo.com/fake'
23
+ end
24
+ end
25
+
26
+ describe '#setup_params' do
27
+ before do
28
+ Setup.stub(:username).and_return('username')
29
+ Setup.stub(:password).and_return('password')
30
+ end
31
+
32
+ its(:setup_params) do
33
+ should eq({ Usuario: 'username', Senha: 'password' } )
34
+ end
35
+ end
36
+
37
+ describe '#parse' do
38
+ it 'should create a response object' do
39
+ subject.parse.should be_instance_of(Response)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe Response do
6
+ let(:some_response) do
7
+ %{
8
+ <string xmlns="http://tempuri.org/">
9
+ { "Campeonato": [ { "@Id": "172" } ] }
10
+ </string>
11
+ }
12
+ end
13
+
14
+ let(:successful_response) { Response.new(resource_key: 'Campeonato', body: some_response) }
15
+
16
+ let(:other_response) do
17
+ %{
18
+ <string xmlns="http://tempuri.org/">
19
+ {"Erro": {"@Mensagem": "Usuário ou senha Inválidos"}}
20
+ </string>
21
+ }
22
+ end
23
+
24
+ let(:error_response) { Response.new(resource_key: 'Campeonato', body: other_response) }
25
+
26
+ describe '#error?' do
27
+ context 'when is true' do
28
+ subject { error_response }
29
+
30
+ its(:error?) { should be true }
31
+ end
32
+
33
+ context 'when is false' do
34
+ subject { successful_response }
35
+
36
+ its(:error?) { should be false }
37
+ end
38
+ end
39
+
40
+ describe '#error' do
41
+ context 'when is true' do
42
+ subject { error_response }
43
+
44
+ its(:error) { should eq(ErrorResponse.new('Usuário ou senha Inválidos')) }
45
+ end
46
+
47
+ context 'when is false' do
48
+ subject { successful_response }
49
+
50
+ its(:error) { should be nil }
51
+ end
52
+ end
53
+
54
+ describe '#[]' do
55
+ subject { successful_response[0] }
56
+
57
+ it { should eq({ '@Id' => '172' }) }
58
+ end
59
+
60
+ describe '#collect' do
61
+ subject { successful_response.collect { |b| b['@Id'] } }
62
+
63
+ it { should eq ['172'] }
64
+ end
65
+
66
+ describe '#map' do
67
+ subject { successful_response.map { |b| b['@Id'] } }
68
+
69
+ it { should eq ['172'] }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ module FootStats
4
+ describe Setup do
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module FootStats
5
+ describe Team do
6
+ describe '.all' do
7
+ context "normal response" do
8
+ use_vcr_cassette 'championship_teams'
9
+
10
+ subject { Team.all(championship: 198).first }
11
+
12
+ its(:source_id) { should eq 1487 }
13
+ its(:full_name) { should eq 'América (Teófilo Otoni)' }
14
+ its(:city) { should eq 'Teófilo Otoni' }
15
+ its(:country) { should eq 'Brasil'}
16
+ end
17
+
18
+ context "error response" do
19
+ use_vcr_cassette 'championship_teams_error_response'
20
+ subject { Team.all(championship: 198) }
21
+
22
+ its(:message) { should eq 'Usuário ou senha Inválidos' }
23
+ end
24
+ end
25
+
26
+ describe ".resource_name" do
27
+ subject { Team }
28
+
29
+ its(:resource_name) { should eq 'ListaEquipesCampeonato' }
30
+ end
31
+
32
+ describe ".resource_key" do
33
+ subject { Team }
34
+
35
+ its(:resource_key) { should eq 'Equipe' }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require 'foot_stats'
2
+ require 'vcr'
3
+
4
+ VCR.configure do |config|
5
+ config.cassette_library_dir = 'spec/cassettes'
6
+ config.hook_into(:fakeweb)
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.extend VCR::RSpec::Macros
11
+ end
12
+
13
+ FootStats::Setup.setup do |config|
14
+ config.base_url = 'http://footstats.com.br/modyo.asmx'
15
+ end