infostrada 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.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +51 -0
- data/README.md +42 -0
- data/bin/strada +45 -0
- data/infostrada.gemspec +29 -0
- data/lib/infostrada/base_request.rb +36 -0
- data/lib/infostrada/commands.rb +77 -0
- data/lib/infostrada/competition.rb +24 -0
- data/lib/infostrada/core_ext/string.rb +9 -0
- data/lib/infostrada/edition.rb +27 -0
- data/lib/infostrada/edition_request.rb +18 -0
- data/lib/infostrada/errors.rb +7 -0
- data/lib/infostrada/formatter.rb +21 -0
- data/lib/infostrada/nation.rb +17 -0
- data/lib/infostrada/person_info.rb +28 -0
- data/lib/infostrada/player.rb +54 -0
- data/lib/infostrada/squad.rb +19 -0
- data/lib/infostrada/team.rb +34 -0
- data/lib/infostrada/team_info.rb +29 -0
- data/lib/infostrada/team_request.rb +18 -0
- data/lib/infostrada/version.rb +3 -0
- data/lib/infostrada.rb +63 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8a8b5ee87337a4ef44fa4c6ef2cd039b292b9fb
|
4
|
+
data.tar.gz: 484e915e0c41a3ae3e4193e8aa16667611ae3e23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 536352807582e80903546052089a0ae636f71c0d5f9432fe0e888fb2c31e711b522c2ec5ac908a75267589556f4a737078b797e5415f1c772f766edbe0e8e44c
|
7
|
+
data.tar.gz: 574363bbfdd0bef6030fab3765eb2f97d4b04ae75cb74cd0c8aadddb1cae1f46991e4f1c9014068d9bb73d82d102c5a892221458185f17bd888ae475924ff6a3
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
infostrada (0.0.1)
|
5
|
+
colored
|
6
|
+
httparty (~> 0.12)
|
7
|
+
rb-readline
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (1.1.0)
|
13
|
+
colored (1.2)
|
14
|
+
httparty (0.12.0)
|
15
|
+
json (~> 1.8)
|
16
|
+
multi_xml (>= 0.5.2)
|
17
|
+
json (1.8.1)
|
18
|
+
multi_xml (0.5.5)
|
19
|
+
parser (2.1.4)
|
20
|
+
ast (~> 1.1)
|
21
|
+
slop (~> 3.4, >= 3.4.5)
|
22
|
+
powerpack (0.0.9)
|
23
|
+
rainbow (2.0.0)
|
24
|
+
rake (10.1.1)
|
25
|
+
rb-readline (0.5.1)
|
26
|
+
reek (1.3.6)
|
27
|
+
ruby2ruby (~> 2.0.7)
|
28
|
+
ruby_parser (~> 3.2)
|
29
|
+
sexp_processor
|
30
|
+
rubocop (0.18.1)
|
31
|
+
json (>= 1.7.7, < 2)
|
32
|
+
parser (~> 2.1.3)
|
33
|
+
powerpack (~> 0.0.6)
|
34
|
+
rainbow (>= 1.99.1, < 3.0)
|
35
|
+
ruby2ruby (2.0.7)
|
36
|
+
ruby_parser (~> 3.1)
|
37
|
+
sexp_processor (~> 4.0)
|
38
|
+
ruby_parser (3.3.0)
|
39
|
+
sexp_processor (~> 4.1)
|
40
|
+
sexp_processor (4.4.1)
|
41
|
+
slop (3.4.7)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (~> 1.5)
|
48
|
+
infostrada!
|
49
|
+
rake
|
50
|
+
reek
|
51
|
+
rubocop
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Infostrada API
|
2
|
+
|
3
|
+
This is a wrapper for [infostrada](http://www.infostradasports.com/) football API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```console
|
10
|
+
$ gem 'infostrada-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```console
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```console
|
22
|
+
$ gem install infostrada-api
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
First you have to configure API access with user and password:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Infostrada.configure do |config|
|
31
|
+
config.auth_user = infostrada_user
|
32
|
+
config.auth_password = infostrada_password
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/rikas/infostrada-api/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/bin/strada
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
4
|
+
|
5
|
+
require 'infostrada'
|
6
|
+
require 'infostrada/commands'
|
7
|
+
require 'colored'
|
8
|
+
require 'readline'
|
9
|
+
|
10
|
+
module Infostrada
|
11
|
+
puts "Loading Infostrada API #{Infostrada::VERSION}"
|
12
|
+
|
13
|
+
VALID_COMMANDS = %w(exit show-squad show-teams show-player editions select-edition)
|
14
|
+
|
15
|
+
comp = Proc.new { |s| VALID_COMMANDS.grep( /^#{Regexp.escape(s)}/ ) }
|
16
|
+
|
17
|
+
Readline.completion_append_character = ' '
|
18
|
+
Readline.completion_proc = comp
|
19
|
+
|
20
|
+
# Ignore CTRL+C
|
21
|
+
trap('INT', 'SIG_IGN')
|
22
|
+
|
23
|
+
def self.execute_command(input)
|
24
|
+
command, *parameters = input.split("\s")
|
25
|
+
method = command.gsub('-', '_')
|
26
|
+
|
27
|
+
if VALID_COMMANDS.include?(command)
|
28
|
+
if parameters
|
29
|
+
Commands.send(method, *parameters)
|
30
|
+
else
|
31
|
+
Commands.send(method)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "Invalid command `#{command}'".red
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
loop do
|
39
|
+
line = Readline::readline("#{Commands.selected_edition_string}> ".magenta, true)
|
40
|
+
|
41
|
+
break if line.nil? || line == 'exit'
|
42
|
+
|
43
|
+
execute_command(line)
|
44
|
+
end
|
45
|
+
end
|
data/infostrada.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'infostrada/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'infostrada'
|
8
|
+
spec.version = Infostrada::VERSION
|
9
|
+
spec.authors = ['Ricardo Otero']
|
10
|
+
spec.email = ['oterosantos@gmail.com']
|
11
|
+
spec.summary = 'Infostrada Football API wrapper.'
|
12
|
+
spec.description = 'Infostrada Football API wrapper.'
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'reek'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
|
+
|
26
|
+
spec.add_dependency 'httparty', '~> 0.12'
|
27
|
+
spec.add_dependency 'colored'
|
28
|
+
spec.add_dependency 'rb-readline'
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Infostrada
|
2
|
+
# This is the class that every class making API requests must descend from. It includes HTTParty
|
3
|
+
# to easily support every type of HTTP request. The basic_auth is set up from the
|
4
|
+
# Infostrada.configuration mechanism described in the Infostrada module.
|
5
|
+
class BaseRequest
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
# Uncomment to debug HTTParty calls.
|
9
|
+
# debug_output $stdout
|
10
|
+
|
11
|
+
basic_auth 'APIdemo', 'Sauv@k@vel4'
|
12
|
+
|
13
|
+
# The default format of the requests. Used on HTTP header 'Content-Type'.
|
14
|
+
format :json
|
15
|
+
|
16
|
+
# Base URI of the service. Since the gem is only football related for now we can have the
|
17
|
+
# football path already in the base_uri.
|
18
|
+
base_uri 'demo.api.infostradasports.com/svc/Football.svc/json/'
|
19
|
+
|
20
|
+
# Which default parameters we can send in every request?
|
21
|
+
default_params languageCode: 2
|
22
|
+
|
23
|
+
# Default request timeout in seconds. This can be overriden by module configuration.
|
24
|
+
default_timeout 10
|
25
|
+
|
26
|
+
# Disable the use of rails query string format.
|
27
|
+
#
|
28
|
+
# With rails query string format enabled:
|
29
|
+
# => get '/', :query => {:selected_ids => [1,2,3]}
|
30
|
+
#
|
31
|
+
# Would translate to this:
|
32
|
+
# => /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
33
|
+
#
|
34
|
+
disable_rails_query_string_format
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Infostrada
|
2
|
+
# The class containing the methods used by the command line tool.
|
3
|
+
class Commands
|
4
|
+
class << self
|
5
|
+
attr_accessor :selected_edition
|
6
|
+
|
7
|
+
def selected_edition_string
|
8
|
+
if @selected_edition
|
9
|
+
"#{@selected_edition.competition_name} #{@selected_edition.season}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def editions
|
14
|
+
get_editions.each do |edition|
|
15
|
+
print_id_col(edition.id)
|
16
|
+
print "#{edition.competition_name} #{edition.season}\n".bold
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def select_edition(edition_id)
|
21
|
+
get_editions
|
22
|
+
@selected_edition = @editions.find { |edition| edition.id == edition_id.to_i }
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_teams
|
26
|
+
edition_teams = @selected_edition.teams
|
27
|
+
edition_teams.each do |team|
|
28
|
+
print_id_col(team.id)
|
29
|
+
print "#{team.name}\n".bold
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_squad(team_id)
|
34
|
+
players = Squad.where(edition_id: @selected_edition.id, team_id: team_id)
|
35
|
+
players.each do |player|
|
36
|
+
print_id_col(player.person_id)
|
37
|
+
print "#{player.function[0]} ".bold.red
|
38
|
+
print "#{player.name}\n".bold
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def show_player(person_id)
|
43
|
+
person = PersonInfo.where(person_id: person_id)
|
44
|
+
nickname = person.nickname
|
45
|
+
|
46
|
+
print_person(person, nickname)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def print_person(person, nickname)
|
52
|
+
print "#{person.public_name}".bold.yellow
|
53
|
+
print nickname ? " (#{nickname})\n" : "\n"
|
54
|
+
|
55
|
+
puts "Date of birth: #{person.birthdate}
|
56
|
+
Weight: #{person.weight}
|
57
|
+
Height: #{person.height}
|
58
|
+
Born: #{person.birth_city} / #{person.birth_country}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_id_col(id)
|
62
|
+
id = sprintf('%9s', id)
|
63
|
+
print '[' << "#{id}".yellow << '] '
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_editions
|
67
|
+
@editions ||= Edition.all
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_edition(edition_id)
|
71
|
+
get_editions.each do |edition|
|
72
|
+
return edition if edition.id == edition_id.to_i
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Competition
|
3
|
+
attr_accessor :id, :name, :set, :level, :nation
|
4
|
+
|
5
|
+
def initialize(hash)
|
6
|
+
@id = hash.delete('n_CompetitionID')
|
7
|
+
@name = hash.delete('c_Competition')
|
8
|
+
|
9
|
+
@nation = Nation.new
|
10
|
+
set_nation_attributes(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_nation_attributes(hash)
|
16
|
+
hash.each do |key, value|
|
17
|
+
if key =~ /[cn]_\w+Natio.*/
|
18
|
+
method = "#{key.snake_case.gsub(/[cn]_competition_?/, '')}="
|
19
|
+
@nation.send(method, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Edition
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
attr_accessor :id, :competition, :season, :start_date, :end_date
|
6
|
+
|
7
|
+
def_delegator :@competition, :name, :competition_name
|
8
|
+
def_delegator :@competition, :id, :competition_id
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
editions = EditionRequest.get_list
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(hash)
|
15
|
+
@id = hash.delete('n_EditionID')
|
16
|
+
@season = hash.delete('c_Season')
|
17
|
+
@start_date = Formatter.format_date(hash.delete('d_EditionStartDate'))
|
18
|
+
@end_date = hash.delete('d_EditionEndDate')
|
19
|
+
|
20
|
+
@competition = Competition.new(hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teams
|
24
|
+
Team.all(id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class EditionRequest < Infostrada::BaseRequest
|
3
|
+
URLS = {
|
4
|
+
list: '/GetEditionList'
|
5
|
+
}
|
6
|
+
|
7
|
+
def self.get_list
|
8
|
+
list = get(URLS[:list])
|
9
|
+
|
10
|
+
editions = []
|
11
|
+
list.each do |edition_hash|
|
12
|
+
editions << Edition.new(edition_hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
editions
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Infostrada
|
2
|
+
# This class is used to format types that come from infostrada like dates.
|
3
|
+
class Formatter
|
4
|
+
# Formats the stupid date format from Infostrada.
|
5
|
+
def self.format_date(date)
|
6
|
+
if date && match = date.match(/\/Date\(([0-9]+)([\+\-])([0-9]+)\)\//i)
|
7
|
+
# The date was in miliseconds since Unix epoch
|
8
|
+
stamp = match[1].to_i / 1000
|
9
|
+
|
10
|
+
offset = match[3].scan(/.{2}/)
|
11
|
+
offset = offset[0].to_i * 3600 + offset[1].to_i
|
12
|
+
|
13
|
+
final = stamp.send(match[2], offset)
|
14
|
+
|
15
|
+
Time.at(final).to_date
|
16
|
+
else
|
17
|
+
Time.now.to_date
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Nation
|
3
|
+
attr_accessor :id, :name, :short_name
|
4
|
+
|
5
|
+
def natio_geo_id=(id)
|
6
|
+
self.id = id
|
7
|
+
end
|
8
|
+
|
9
|
+
def natio=(name)
|
10
|
+
self.name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def natio_short=(short_name)
|
14
|
+
self.short_name = short_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class PersonInfo < Infostrada::BaseRequest
|
3
|
+
URL = '/GetPersonInfo'
|
4
|
+
|
5
|
+
attr_accessor :id, :first_name, :last_name, :public_name, :nickname, :height, :birthdate
|
6
|
+
attr_accessor :weight, :birth_city, :birth_country
|
7
|
+
|
8
|
+
def self.where(options)
|
9
|
+
id = options.delete(:person_id)
|
10
|
+
info = get(URL, query: { personid: id }).first
|
11
|
+
self.new(id, info)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(id, info)
|
15
|
+
@id = id
|
16
|
+
|
17
|
+
@first_name = info['c_FirstName']
|
18
|
+
@last_name = info['c_LastName']
|
19
|
+
@public_name = info['c_PublicName']
|
20
|
+
@nickname = info['c_Nickname']
|
21
|
+
@birthdate = Formatter.format_date(info['d_BirthDate'])
|
22
|
+
@height = info['n_Height']
|
23
|
+
@weight = info['n_Weight']
|
24
|
+
@birth_city = info['c_BirthCity']
|
25
|
+
@birth_country = info['c_BirthCountry']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Player
|
3
|
+
attr_accessor :person_id, :name, :short_name, :birthdate, :function, :shirt_number
|
4
|
+
attr_accessor :season_stats, :nation
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
@person_id = hash['n_PersonID']
|
8
|
+
@name = hash['c_Person']
|
9
|
+
@short_name = hash['c_PersonShort']
|
10
|
+
|
11
|
+
@birthdate = Formatter.format_date(hash['d_BirthDate'])
|
12
|
+
|
13
|
+
# Function can be one of the folowing strings:
|
14
|
+
# "Goalkeeper", "Defender", "Midfielder", "Forward" or "Coach"
|
15
|
+
@function = hash['c_Function']
|
16
|
+
@shirt_number = hash['n_ShirtNr']
|
17
|
+
|
18
|
+
# Season statistics
|
19
|
+
set_season_stats(hash)
|
20
|
+
|
21
|
+
@nation = Nation.new
|
22
|
+
set_nation_attributes(hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def set_season_stats(hash)
|
28
|
+
@season_stats = {}
|
29
|
+
|
30
|
+
@season_stats[:matches] = hash['n_Matches']
|
31
|
+
@season_stats[:matches_start] = hash['n_MatchesStart']
|
32
|
+
@season_stats[:matches_out] = hash['n_MatchesOut']
|
33
|
+
@season_stats[:matches_in] = hash['n_MatchesIn']
|
34
|
+
@season_stats[:minutes_played] = hash['n_MinutesPlayed']
|
35
|
+
@season_stats[:goals] = hash['n_Goals']
|
36
|
+
@season_stats[:own_goals] = hash['n_OwnGoals']
|
37
|
+
@season_stats[:assists] = hash['n_Assists']
|
38
|
+
@season_stats[:cards_yellow] = hash['n_CardsYellow']
|
39
|
+
@season_stats[:cards_red] = hash['n_CardsRed']
|
40
|
+
@season_stats[:cards_red_direct] = hash['n_CardsRedDirect']
|
41
|
+
@season_stats[:cards_red_from_yellow] = hash['n_CardsRed2Yellow']
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_nation_attributes(hash)
|
45
|
+
hash.each do |key, value|
|
46
|
+
if key =~ /[cn]_\w+Natio.*/
|
47
|
+
method = "#{key.snake_case.gsub(/[cn]_person_?/, '')}="
|
48
|
+
@nation.send(method, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Squad < Infostrada::BaseRequest
|
3
|
+
URL = '/GetSquad'
|
4
|
+
|
5
|
+
def self.where(options = {})
|
6
|
+
edition_id = options.delete(:edition_id)
|
7
|
+
team_id = options.delete(:team_id)
|
8
|
+
|
9
|
+
list = get(URL, query: { editionid: edition_id, teamid: team_id })
|
10
|
+
|
11
|
+
players = []
|
12
|
+
list.each do |player_hash|
|
13
|
+
players << Player.new(player_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
players
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class Team
|
3
|
+
attr_accessor :id, :name, :short_name, :nation, :edition_id
|
4
|
+
|
5
|
+
def self.all(edition_id)
|
6
|
+
teams = TeamRequest.get_edition(edition_id.to_i)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(hash)
|
10
|
+
@id = hash.delete('n_TeamID')
|
11
|
+
@name = hash.delete('c_Team')
|
12
|
+
@short_name = hash.delete('c_TeamShort')
|
13
|
+
@edition_id = hash.delete('edition_id')
|
14
|
+
|
15
|
+
@nation = Nation.new
|
16
|
+
set_nation_attributes(hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
def details
|
20
|
+
info ||= TeamInfo.fetch(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_nation_attributes(hash)
|
26
|
+
hash.each do |key, value|
|
27
|
+
if key =~ /[cn]_\w+Natio.*/
|
28
|
+
method = "#{key.snake_case.gsub(/[cn]_team_?/, '')}="
|
29
|
+
@nation.send(method, value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class TeamInfo < BaseRequest
|
3
|
+
attr_accessor :official_name, :official_short_name, :public_name, :public_short_name, :nickname
|
4
|
+
attr_accessor :foundation_date, :official_stadium_name, :stadium_name, :stadium_capacity
|
5
|
+
attr_accessor :url, :city
|
6
|
+
|
7
|
+
URL = '/GetTeamInfo'
|
8
|
+
|
9
|
+
def self.fetch(team_id)
|
10
|
+
info_hash = get(URL, query: { teamid: team_id.to_i })
|
11
|
+
|
12
|
+
self.new(info_hash.first)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(hash)
|
16
|
+
@official_name = hash['c_OfficialName']
|
17
|
+
@official_short_name = hash['c_OfficialNameSort']
|
18
|
+
@public_name = hash['c_PublicName']
|
19
|
+
@public_short_name = hash['c_PublicNameSort']
|
20
|
+
@nickname = hash['c_Nickname']
|
21
|
+
@foundation_date = hash['d_FoundationDate']
|
22
|
+
@official_stadium_name = hash['c_StadiumOfficialName']
|
23
|
+
@stadium_name = hash['c_Stadium']
|
24
|
+
@stadium_capacity = hash['n_StadiumCapacity']
|
25
|
+
@url = hash['c_URL']
|
26
|
+
@city = hash['c_City']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Infostrada
|
2
|
+
class TeamRequest < Infostrada::BaseRequest
|
3
|
+
URLS = {
|
4
|
+
list: '/GetTeamList'
|
5
|
+
}
|
6
|
+
|
7
|
+
def self.get_edition(edition_id)
|
8
|
+
list = get(URLS[:list], query: { editionid: edition_id.to_i })
|
9
|
+
|
10
|
+
teams = []
|
11
|
+
list.each do |team_hash|
|
12
|
+
teams << Team.new(team_hash.merge('edition_id' => edition_id.to_i))
|
13
|
+
end
|
14
|
+
|
15
|
+
teams
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/infostrada.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
require 'infostrada/core_ext/string'
|
6
|
+
|
7
|
+
require 'infostrada/base_request'
|
8
|
+
require 'infostrada/competition'
|
9
|
+
|
10
|
+
require 'infostrada/edition'
|
11
|
+
require 'infostrada/edition_request'
|
12
|
+
|
13
|
+
require 'infostrada/errors'
|
14
|
+
|
15
|
+
require 'infostrada/nation'
|
16
|
+
|
17
|
+
require 'infostrada/team'
|
18
|
+
require 'infostrada/team_request'
|
19
|
+
require 'infostrada/team_info'
|
20
|
+
|
21
|
+
require 'infostrada/squad'
|
22
|
+
require 'infostrada/player'
|
23
|
+
require 'infostrada/person_info'
|
24
|
+
|
25
|
+
require 'infostrada/version'
|
26
|
+
|
27
|
+
module Infostrada
|
28
|
+
# The configuration of the API requests. This configuration is also shared by
|
29
|
+
# <Infostrada::BaseRequest> where the HTTParty configuration is done.
|
30
|
+
class Configuration
|
31
|
+
attr_reader :user, :password, :timeout
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
BaseRequest.default_options[:basic_auth] ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def user=(user)
|
38
|
+
BaseRequest.default_options[:basic_auth].merge!(username: user)
|
39
|
+
@user = user
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def password=(password)
|
44
|
+
BaseRequest.default_options[:basic_auth].merge!(password: password)
|
45
|
+
@password = password
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def timeout=(timeout)
|
50
|
+
BaseRequest.default_options[:timeout] = timeout
|
51
|
+
@timeout = timeout
|
52
|
+
self
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.configuration
|
57
|
+
@configuration ||= Configuration.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.configure
|
61
|
+
yield(configuration) if block_given?
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: infostrada
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Otero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: reek
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colored
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rb-readline
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Infostrada Football API wrapper.
|
112
|
+
email:
|
113
|
+
- oterosantos@gmail.com
|
114
|
+
executables:
|
115
|
+
- strada
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- README.md
|
122
|
+
- bin/strada
|
123
|
+
- infostrada.gemspec
|
124
|
+
- lib/infostrada.rb
|
125
|
+
- lib/infostrada/base_request.rb
|
126
|
+
- lib/infostrada/commands.rb
|
127
|
+
- lib/infostrada/competition.rb
|
128
|
+
- lib/infostrada/core_ext/string.rb
|
129
|
+
- lib/infostrada/edition.rb
|
130
|
+
- lib/infostrada/edition_request.rb
|
131
|
+
- lib/infostrada/errors.rb
|
132
|
+
- lib/infostrada/formatter.rb
|
133
|
+
- lib/infostrada/nation.rb
|
134
|
+
- lib/infostrada/person_info.rb
|
135
|
+
- lib/infostrada/player.rb
|
136
|
+
- lib/infostrada/squad.rb
|
137
|
+
- lib/infostrada/team.rb
|
138
|
+
- lib/infostrada/team_info.rb
|
139
|
+
- lib/infostrada/team_request.rb
|
140
|
+
- lib/infostrada/version.rb
|
141
|
+
homepage: ''
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.2.1
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Infostrada Football API wrapper.
|
165
|
+
test_files: []
|