soda_xml_team 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +33 -0
- data/README.md +10 -1
- data/Rakefile +5 -2
- data/bin/soda-league-directory +61 -0
- data/lib/soda_xml_team.rb +9 -8
- data/lib/soda_xml_team/address.rb +34 -34
- data/lib/soda_xml_team/base.rb +4 -2
- data/lib/soda_xml_team/client.rb +45 -16
- data/lib/soda_xml_team/news.rb +18 -16
- data/lib/soda_xml_team/schedule.rb +11 -12
- data/lib/soda_xml_team/standings.rb +31 -25
- data/lib/soda_xml_team/version.rb +3 -1
- data/soda_xml_team.gemspec +14 -14
- data/spec/soda_xml_team_news_spec.rb +10 -8
- data/spec/soda_xml_team_schedule_spec.rb +10 -6
- data/spec/soda_xml_team_spec.rb +37 -29
- data/spec/soda_xml_team_standings_spec.rb +7 -5
- data/spec/spec_helper.rb +9 -9
- data/tasks/rspec.rake +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdd088c94b73418807eb01eb8185d64da675b0f7
|
4
|
+
data.tar.gz: 358dc4c8fe43b05a03361a0f904416169f7c65b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d828d183ac7579722944ddbeed1ec4cc79651f565a26c51a4c9570aa554b9f44ad3a9225ec5bcd4474fc70e14a69450e4a8719b0dd7b20c92ec1846cdf16b72
|
7
|
+
data.tar.gz: fa15a7711f5c0b9393e046782bb46a0056b1315f48b3bc0d4879bff85b02644222bc29d297d32f31612b20d935ae9d2c0b34502baaa0406d3de22ac9afafe538
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-12-07 21:50:37 -0600 using RuboCop version 0.27.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 5
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 80
|
11
|
+
|
12
|
+
# Offense count: 2
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
# Offense count: 4
|
17
|
+
# Configuration parameters: AllowURI, URISchemes.
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 133
|
20
|
+
|
21
|
+
# Offense count: 6
|
22
|
+
# Configuration parameters: CountComments.
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 61
|
25
|
+
|
26
|
+
# Offense count: 2
|
27
|
+
Metrics/PerceivedComplexity:
|
28
|
+
Max: 28
|
29
|
+
|
30
|
+
# Offense count: 1
|
31
|
+
# Configuration parameters: Exclude.
|
32
|
+
Style/FileName:
|
33
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SODA XML Team Gem
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/seatshare/soda_xml_team.png)](https://travis-ci.org/seatshare/soda_xml_team)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/soda_xml_team.svg)](http://badge.fury.io/rb/soda_xml_team) [![Build Status](https://travis-ci.org/seatshare/soda_xml_team.png)](https://travis-ci.org/seatshare/soda_xml_team)
|
4
4
|
|
5
5
|
This [gem](http://rubygems.org/gems/soda_xml_team) serves as an interface to the [SODA (Sports On Demand API) from XML Team](http://www.xmlteam.com/soda/). It uses [HTTParty](http://johnnunemaker.com/httparty/) and [Nokogiri](http://nokogiri.org/) to retrieve and parse the data.
|
6
6
|
|
@@ -108,6 +108,15 @@ standings = SodaXmlTeam::Standings.parse_standings(standings_document)
|
|
108
108
|
puts standings.inspect
|
109
109
|
```
|
110
110
|
|
111
|
+
### League Directory File Parser
|
112
|
+
|
113
|
+
This gem includes an executable for parsing files from the [SODA League Directory](http://private.xmlteam.com/league-directory/), which is useful for handling a particular sports league.
|
114
|
+
|
115
|
+
```bash
|
116
|
+
$ soda-league-directory ~/Downloads/xt.20140505T114154-0400.l.afa.ar.primera-leaguedir.xml
|
117
|
+
[{:import_key=>"o.afa.ar-t.113", :entity_name=>"Argentinos Juniors ", :status=>1, :entity_type=>"l.afa.ar.primera"}, {:import_key=>"o.afa.ar-t.92", :entity_name=>"Arsenal de Sarandi ", :status=>1, :entity_type=>"l.afa.ar.primera"}, ... ]
|
118
|
+
```
|
119
|
+
|
111
120
|
## Contributing
|
112
121
|
|
113
122
|
1. Fork it ( https://github.com/seatshare/soda_xml_team/fork )
|
data/Rakefile
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
# Arguments
|
6
|
+
file = "#{ARGV[0]}" || nil
|
7
|
+
|
8
|
+
if file.nil? || file == ''
|
9
|
+
puts 'Usage: soda-league-directory path-to-file.xml'
|
10
|
+
Kernel.exit(false)
|
11
|
+
end
|
12
|
+
|
13
|
+
unless File.exist? file
|
14
|
+
puts 'File does not exist.'
|
15
|
+
Kernel.exit(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
File.open("#{ARGV[0]}", 'r') do |io|
|
19
|
+
|
20
|
+
document = Nokogiri::XML(io)
|
21
|
+
|
22
|
+
fail 'Invalid XML league directory.' unless document.is_a? Nokogiri::XML::Document
|
23
|
+
|
24
|
+
output = []
|
25
|
+
|
26
|
+
entity_type = ''
|
27
|
+
document.css('sports-content-codes sports-content-code[code-type="league"]').each do |sportscontentcode|
|
28
|
+
entity_type = sportscontentcode['code-key']
|
29
|
+
end
|
30
|
+
|
31
|
+
document.css('team').each do |team|
|
32
|
+
|
33
|
+
row = {}
|
34
|
+
|
35
|
+
team.css('team-metadata').each do |teammeta|
|
36
|
+
row[:team_key] = teammeta['team-key']
|
37
|
+
team.css('name').each do |namemeta|
|
38
|
+
row[:name] = namemeta['full']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
output << row
|
43
|
+
end
|
44
|
+
|
45
|
+
final_output = []
|
46
|
+
# Export a create statement
|
47
|
+
output.each do |team|
|
48
|
+
next if ['', 'TBA'].include? team[:name].strip
|
49
|
+
next if team[:team_key].strip == ''
|
50
|
+
object = {
|
51
|
+
import_key: team[:team_key],
|
52
|
+
entity_name: team[:name],
|
53
|
+
status: 1,
|
54
|
+
entity_type: entity_type
|
55
|
+
}
|
56
|
+
final_output << object
|
57
|
+
end
|
58
|
+
|
59
|
+
puts final_output.to_s
|
60
|
+
|
61
|
+
end
|
data/lib/soda_xml_team.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require 'soda_xml_team/version'
|
2
|
+
require 'soda_xml_team/client'
|
3
|
+
require 'soda_xml_team/base'
|
4
|
+
require 'soda_xml_team/address'
|
5
|
+
require 'soda_xml_team/schedule'
|
6
|
+
require 'soda_xml_team/news'
|
7
|
+
require 'soda_xml_team/standings'
|
8
8
|
|
9
|
+
##
|
10
|
+
# SODA XML Team
|
9
11
|
module SodaXmlTeam
|
10
|
-
|
11
12
|
end
|
@@ -1,53 +1,57 @@
|
|
1
|
+
##
|
2
|
+
# SODA XML Team module
|
1
3
|
module SodaXmlTeam
|
4
|
+
##
|
5
|
+
# Address class
|
2
6
|
class Address < Client
|
3
|
-
|
7
|
+
##
|
8
|
+
# Builds the query address against the API
|
4
9
|
def self.build(method, options = {})
|
5
|
-
|
6
10
|
path = []
|
7
11
|
|
8
|
-
|
9
|
-
raise "Invalid method."
|
10
|
-
end
|
12
|
+
fail 'Invalid method.' unless %w(get_listing get_document).include? method
|
11
13
|
|
12
14
|
# Get a listing of documents
|
13
|
-
if method
|
15
|
+
if method == 'get_listing'
|
14
16
|
endpoint = '/getListings?'
|
15
17
|
|
16
|
-
if options[:league_id].nil? && options[:team_id].nil?
|
17
|
-
raise "Must specify a `league_id` (league-keys) or `team_id` (team-keys)."
|
18
|
-
end
|
18
|
+
fail 'Must specify `league_id` (league-keys) or `team_id` (team-keys).' if options[:league_id].nil? && options[:team_id].nil?
|
19
19
|
|
20
20
|
# League identifier
|
21
|
-
if options[:league_id]
|
22
|
-
path << "league-keys=#{options[:league_id]}"
|
23
|
-
end
|
21
|
+
path << "league-keys=#{options[:league_id]}" if options[:league_id]
|
24
22
|
|
25
23
|
# Team identifier
|
26
|
-
if options[:team_id]
|
27
|
-
path << "team-keys=#{options[:team_id]}"
|
28
|
-
end
|
24
|
+
path << "team-keys=#{options[:team_id]}" if options[:team_id]
|
29
25
|
|
30
26
|
# Document type
|
31
27
|
if options[:type]
|
32
28
|
path << "fixture-keys=#{options[:type]}"
|
33
29
|
else
|
34
|
-
|
30
|
+
fail 'Must specify the `type` (fixture-keys)'
|
35
31
|
end
|
36
32
|
|
37
33
|
# Start date/time
|
38
34
|
if options[:start_datetime].is_a? String
|
39
35
|
options[:start_datetime] = DateTime.parse(options[:start_datetime])
|
40
|
-
path << "earliest-date-time=#{options[:start_datetime].strftime(
|
36
|
+
path << "earliest-date-time=#{options[:start_datetime].strftime(
|
37
|
+
'%Y%m%dT%H%M%S%z'
|
38
|
+
)}"
|
41
39
|
elsif options[:start_datetime].is_a? DateTime
|
42
|
-
path << "earliest-date-time=#{options[:start_datetime].strftime(
|
40
|
+
path << "earliest-date-time=#{options[:start_datetime].strftime(
|
41
|
+
'%Y%m%dT%H%M%S%z'
|
42
|
+
)}"
|
43
43
|
end
|
44
44
|
|
45
45
|
# End date/time
|
46
46
|
if options[:end_datetime].is_a? String
|
47
47
|
options[:end_datetime] = DateTime.parse(options[:end_datetime])
|
48
|
-
path << "latest-date-time=#{options[:end_datetime].strftime(
|
48
|
+
path << "latest-date-time=#{options[:end_datetime].strftime(
|
49
|
+
'%Y%m%dT%H%M%S%z'
|
50
|
+
)}"
|
49
51
|
elsif options[:end_datetime].is_a? DateTime
|
50
|
-
path << "latest-date-time=#{options[:end_datetime].strftime(
|
52
|
+
path << "latest-date-time=#{options[:end_datetime].strftime(
|
53
|
+
'%Y%m%dT%H%M%S%z'
|
54
|
+
)}"
|
51
55
|
end
|
52
56
|
|
53
57
|
# Use a date window
|
@@ -59,23 +63,21 @@ module SodaXmlTeam
|
|
59
63
|
if !options[:limit].nil? && options[:limit] > 0 && options[:limit] <= 50
|
60
64
|
path << "max-result-count=#{options[:limit]}"
|
61
65
|
else
|
62
|
-
path <<
|
66
|
+
path << 'max-result-count=10'
|
63
67
|
end
|
64
68
|
|
65
69
|
# Priority
|
66
|
-
if options[:priority]
|
67
|
-
path << "priorities=#{options[:priority]}"
|
68
|
-
end
|
70
|
+
path << "priorities=#{options[:priority]}" if options[:priority]
|
69
71
|
|
70
72
|
# Which document revisions to return
|
71
|
-
if options[:revisions]
|
72
|
-
path <<
|
73
|
+
if options[:revisions] == 'all'
|
74
|
+
path << 'revision-control=all'
|
73
75
|
else
|
74
|
-
path <<
|
76
|
+
path << 'revision-control=latest-only'
|
75
77
|
end
|
76
78
|
|
77
79
|
# Always return the XML listing
|
78
|
-
path <<
|
80
|
+
path << 'stylesheet=sportsml2rss-1.0-s'
|
79
81
|
|
80
82
|
# Get a specific document
|
81
83
|
else
|
@@ -83,21 +85,19 @@ module SodaXmlTeam
|
|
83
85
|
if options[:document_id]
|
84
86
|
path << "doc-ids=#{options[:document_id]}"
|
85
87
|
else
|
86
|
-
|
88
|
+
fail 'Missing `document_id` (doc-ids)'
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
92
|
# Concatenate it together
|
91
|
-
path = path.join
|
93
|
+
path = path.join '&'
|
92
94
|
|
93
95
|
# Use sandbox hostname or production
|
94
|
-
if options[:sandbox]
|
96
|
+
if options[:sandbox] == true
|
95
97
|
return SodaXmlTeam::API_SANDBOX_URL + endpoint + path
|
96
98
|
else
|
97
99
|
return SodaXmlTeam::API_BASE_URL + endpoint + path
|
98
100
|
end
|
99
|
-
|
100
101
|
end
|
101
|
-
|
102
102
|
end
|
103
|
-
end
|
103
|
+
end
|
data/lib/soda_xml_team/base.rb
CHANGED
data/lib/soda_xml_team/client.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
|
+
##
|
2
|
+
# SODA XML Team module
|
1
3
|
module SodaXmlTeam
|
2
|
-
|
3
4
|
require 'httparty'
|
4
5
|
require 'nokogiri'
|
5
6
|
|
7
|
+
##
|
8
|
+
# Client for interacting with API
|
6
9
|
class Client
|
7
|
-
|
8
10
|
def initialize(username, password)
|
9
|
-
@auth = {:
|
11
|
+
@auth = { username: username, password: password }
|
10
12
|
@dir = File.dirname __FILE__
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
##
|
16
|
+
# Content Finder retrieves an RSS feed of desired data
|
17
|
+
def content_finder(options = {})
|
18
|
+
response = HTTParty.get(
|
19
|
+
SodaXmlTeam::Address.build(
|
20
|
+
'get_listing',
|
21
|
+
options
|
22
|
+
),
|
23
|
+
basic_auth: @auth,
|
24
|
+
ssl_ca_file: "#{@dir}/../ca-certificates.crt",
|
25
|
+
ssl_version: :SSLv3
|
26
|
+
)
|
15
27
|
feed = Nokogiri::XML(response.body)
|
16
28
|
|
17
29
|
documents = []
|
@@ -20,36 +32,53 @@ module SodaXmlTeam
|
|
20
32
|
|
21
33
|
# Parse for document ID
|
22
34
|
link = item.css('link').inner_text
|
23
|
-
document_id = link.gsub
|
35
|
+
document_id = link.gsub(/(.*)?doc-ids=/i, '')
|
24
36
|
|
25
37
|
record[:title] = item.css('title').inner_text
|
26
38
|
record[:link] = link
|
27
39
|
record[:document_id] = document_id
|
28
40
|
record[:date] = DateTime.parse(item.xpath('./dc:date').inner_text)
|
29
41
|
item.xpath('./sportsml:sports-content-codes').each do |sportscontent|
|
30
|
-
sportscontent.xpath('./sportsml:sports-content-code').each do |
|
31
|
-
record[
|
42
|
+
sportscontent.xpath('./sportsml:sports-content-code').each do |c|
|
43
|
+
record[c['code-type'].to_sym] = c['code-key']
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
35
47
|
documents << record
|
36
48
|
end
|
37
49
|
|
38
|
-
|
39
|
-
|
50
|
+
documents
|
40
51
|
end
|
41
52
|
|
53
|
+
##
|
42
54
|
# Deprecated: Please use `content_finder` instead
|
43
|
-
def get_listing(options={})
|
44
|
-
warn
|
45
|
-
response = HTTParty.get(
|
55
|
+
def get_listing(options = {})
|
56
|
+
warn '[DEPRECATION] `get_listing` is deprecated. Please use `content_finder` instead.'
|
57
|
+
response = HTTParty.get(
|
58
|
+
SodaXmlTeam::Address.build(
|
59
|
+
'get_listing',
|
60
|
+
options
|
61
|
+
),
|
62
|
+
basic_auth: @auth,
|
63
|
+
ssl_ca_file: "#{@dir}/../ca-certificates.crt",
|
64
|
+
ssl_version: :SSLv3
|
65
|
+
)
|
46
66
|
Nokogiri::XML(response.body)
|
47
67
|
end
|
48
68
|
|
49
|
-
|
50
|
-
|
69
|
+
##
|
70
|
+
# Get Document retrieves a parsed XML instance of a given document
|
71
|
+
def get_document(options = {})
|
72
|
+
response = HTTParty.get(
|
73
|
+
SodaXmlTeam::Address.build(
|
74
|
+
'get_document',
|
75
|
+
options
|
76
|
+
),
|
77
|
+
basic_auth: @auth,
|
78
|
+
ssl_ca_file: "#{@dir}/../ca-certificates.crt",
|
79
|
+
ssl_version: :SSLv3
|
80
|
+
)
|
51
81
|
Nokogiri::XML(response.body)
|
52
82
|
end
|
53
|
-
|
54
83
|
end
|
55
84
|
end
|
data/lib/soda_xml_team/news.rb
CHANGED
@@ -1,39 +1,41 @@
|
|
1
|
+
##
|
2
|
+
# SODA XML Team module
|
1
3
|
module SodaXmlTeam
|
2
|
-
|
3
4
|
require 'nokogiri'
|
4
5
|
|
6
|
+
##
|
7
|
+
# News class
|
5
8
|
class News
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
##
|
10
|
+
# Parses news documents into hashes
|
11
|
+
# - document: a Nokegiri::XML::Document
|
12
|
+
def self.parse_news(document = {})
|
9
13
|
output = []
|
10
14
|
|
11
|
-
unless document.is_a? Nokogiri::XML::Document
|
12
|
-
raise "Invalid XML news."
|
13
|
-
end
|
15
|
+
fail 'Invalid XML news.' unless document.is_a? Nokogiri::XML::Document
|
14
16
|
|
15
17
|
output = {}
|
16
18
|
|
17
19
|
# Article meta data
|
18
20
|
document.css('sports-content').each do |metadata|
|
19
21
|
output[:title] = metadata.css('sports-title').first.content
|
20
|
-
|
22
|
+
unless metadata.css('byline person').empty?
|
21
23
|
output[:author] = metadata.css('byline person').first.content
|
22
24
|
end
|
23
25
|
output[:author_title] = metadata.css('byline byttl').first.content
|
24
26
|
output[:headline] = metadata.css('article hedline hl1').first.content
|
25
|
-
output[:abstract] = metadata.css('article abstract')
|
27
|
+
output[:abstract] = metadata.css('article abstract')
|
28
|
+
.first.content.gsub(/\n/, '').strip
|
26
29
|
end
|
27
30
|
|
28
31
|
# Article content
|
29
|
-
document.xpath(
|
30
|
-
|
32
|
+
document.xpath(
|
33
|
+
'/xts:sports-content-set/sports-content/article/nitf/body/body.content'
|
34
|
+
).each do |article_body|
|
35
|
+
output[:body] = article_body.css('*').to_s.gsub(/\n/, '').strip
|
31
36
|
end
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
output
|
35
39
|
end
|
36
|
-
|
37
40
|
end
|
38
|
-
|
39
|
-
end
|
41
|
+
end
|
@@ -1,16 +1,18 @@
|
|
1
|
+
##
|
2
|
+
# SODA XML Team module
|
1
3
|
module SodaXmlTeam
|
2
|
-
|
3
4
|
require 'nokogiri'
|
4
5
|
|
6
|
+
##
|
7
|
+
# Schedule class
|
5
8
|
class Schedule
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
##
|
10
|
+
# Parses schedule documents into hashes
|
11
|
+
# - document: a Nokegiri::XML::Document
|
12
|
+
def self.parse_schedule(document = {})
|
9
13
|
output = []
|
10
14
|
|
11
|
-
unless document.is_a? Nokogiri::XML::Document
|
12
|
-
raise "Invalid XML schedule."
|
13
|
-
end
|
15
|
+
fail 'Invalid XML schedule.' unless document.is_a? Nokogiri::XML::Document
|
14
16
|
|
15
17
|
document.css('schedule sports-event').each do |event|
|
16
18
|
|
@@ -37,10 +39,7 @@ module SodaXmlTeam
|
|
37
39
|
output << row
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
output
|
42
43
|
end
|
43
|
-
|
44
44
|
end
|
45
|
-
|
46
|
-
end
|
45
|
+
end
|
@@ -1,23 +1,28 @@
|
|
1
|
+
##
|
2
|
+
# SODA XML Team module
|
1
3
|
module SodaXmlTeam
|
2
|
-
|
3
4
|
require 'nokogiri'
|
4
5
|
|
6
|
+
##
|
7
|
+
# Standings class
|
5
8
|
class Standings
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
##
|
10
|
+
# Parses standings documents into hashes
|
11
|
+
# - document: a Nokegiri::XML::Document
|
12
|
+
def self.parse_standings(document = {})
|
9
13
|
output = []
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
15
|
+
fail 'Invalid XML standings.' unless
|
16
|
+
document.is_a? Nokogiri::XML::Document
|
14
17
|
|
15
18
|
document.css('sports-content standing').each do |division|
|
16
19
|
|
17
20
|
row = {}
|
18
21
|
row[:division] = division['content-label']
|
19
22
|
|
20
|
-
division.css(
|
23
|
+
division.css(
|
24
|
+
'sports-content-codes sports-content-code[code-type="conference"]'
|
25
|
+
).each do |standingmetadata|
|
21
26
|
row[:conference] = standingmetadata['code-name']
|
22
27
|
end
|
23
28
|
|
@@ -27,8 +32,8 @@ module SodaXmlTeam
|
|
27
32
|
|
28
33
|
team_record = {}
|
29
34
|
|
30
|
-
team.css('team-metadata name').each do |
|
31
|
-
team_record[:name] = "#{
|
35
|
+
team.css('team-metadata name').each do |tmn|
|
36
|
+
team_record[:name] = "#{tmn[:first]} #{tmn[:last]}"
|
32
37
|
end
|
33
38
|
|
34
39
|
team.css('team-stats').each do |teamstats|
|
@@ -36,18 +41,22 @@ module SodaXmlTeam
|
|
36
41
|
team_record[:standing_points] = teamstats['standing-points'].to_i
|
37
42
|
end
|
38
43
|
|
39
|
-
team.css('team-stats rank').each do |
|
40
|
-
team_record[:division_rank] =
|
41
|
-
team_record[:conference_rank] =
|
44
|
+
team.css('team-stats rank').each do |tsr|
|
45
|
+
team_record[:division_rank] = tsr[:value].to_i
|
46
|
+
team_record[:conference_rank] = tsr['xts:conference-rank'].to_i
|
42
47
|
end
|
43
48
|
|
44
|
-
team.css('team-stats outcome-totals').each do |
|
45
|
-
next if
|
46
|
-
next if
|
47
|
-
next
|
48
|
-
next
|
49
|
-
|
50
|
-
|
49
|
+
team.css('team-stats outcome-totals').each do |ot|
|
50
|
+
next if ot['competition-scope'] != 'league'
|
51
|
+
next if ot['date-coverage-type'] != 'season-regular'
|
52
|
+
next unless ot['duration-scope'].nil?
|
53
|
+
next unless ot['alignment-scope'].nil?
|
54
|
+
ot.keys.each do |otk|
|
55
|
+
begin
|
56
|
+
team_record[otk] = ot[otk].to_i if Float(ot[otk])
|
57
|
+
rescue
|
58
|
+
team_record[otk] = ot[otk]
|
59
|
+
end
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
@@ -58,10 +67,7 @@ module SodaXmlTeam
|
|
58
67
|
output << row
|
59
68
|
end
|
60
69
|
|
61
|
-
|
62
|
-
|
70
|
+
output
|
63
71
|
end
|
64
|
-
|
65
72
|
end
|
66
|
-
|
67
|
-
end
|
73
|
+
end
|
data/soda_xml_team.gemspec
CHANGED
@@ -4,25 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'soda_xml_team/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'soda_xml_team'
|
8
8
|
spec.version = SodaXmlTeam::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Stephen Yeargin']
|
10
|
+
spec.email = ['stephen@seatsha.re']
|
11
|
+
spec.summary = 'XML Team Sports On Demand API'
|
12
|
+
spec.description = "A basic layer for interacting with XML Team's Sports On Demand API (SODA)"
|
13
|
+
spec.homepage = 'https://github.com/seatshare/soda_xml_team'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
25
|
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
26
|
+
spec.add_dependency 'nokogiri', '>= 1.6.3'
|
27
|
+
spec.add_dependency 'httparty', '>= 0.13'
|
28
28
|
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'SodaXmlTeamNews' do
|
4
4
|
|
5
5
|
subject { SodaXmlTeam::News }
|
6
6
|
|
7
7
|
describe '.parse_news' do
|
8
8
|
|
9
|
-
let(:input)
|
10
|
-
SodaXmlTeam::Client.new(
|
9
|
+
let(:input) do
|
10
|
+
SodaXmlTeam::Client.new(
|
11
|
+
ENV['SODA_USERNAME'], ENV['SODA_PASSWORD']
|
12
|
+
).get_document(
|
11
13
|
sandbox: true,
|
12
14
|
document_id: 'xt.3329967-NAS-2005-OUTLOOK'
|
13
|
-
|
14
|
-
|
15
|
+
)
|
16
|
+
end
|
15
17
|
let(:output) { subject.parse_news(input) }
|
16
18
|
|
17
19
|
it 'has a article that matches' do
|
18
20
|
expect(output[:title]).to eq '2005-06 Nashville Predators Preview'
|
19
21
|
expect(output[:headline]).to eq '2005-06 Nashville Predators Preview'
|
20
|
-
expect(output[:abstract]).to
|
21
|
-
expect(output[:body]).to
|
22
|
+
expect(output[:abstract]).to include 'The Nashville Predators were the'
|
23
|
+
expect(output[:body]).to include '<p>(Sports Network) - The Nashville'
|
22
24
|
end
|
23
25
|
|
24
26
|
end
|
25
|
-
end
|
27
|
+
end
|
@@ -6,12 +6,14 @@ describe SodaXmlTeam do
|
|
6
6
|
|
7
7
|
describe '.parse_schedule' do
|
8
8
|
|
9
|
-
let(:input)
|
10
|
-
SodaXmlTeam::Client.new(
|
9
|
+
let(:input) do
|
10
|
+
SodaXmlTeam::Client.new(
|
11
|
+
ENV['SODA_USERNAME'], ENV['SODA_PASSWORD']
|
12
|
+
).get_document(
|
11
13
|
sandbox: true,
|
12
14
|
document_id: 'xt.10875359-nas-sked'
|
13
|
-
|
14
|
-
|
15
|
+
)
|
16
|
+
end
|
15
17
|
let(:output) { subject.parse_schedule(input) }
|
16
18
|
|
17
19
|
it 'has 82 games in a season' do
|
@@ -27,7 +29,9 @@ describe SodaXmlTeam do
|
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'has expected start date/time' do
|
30
|
-
expect(output[1][:start_date_time]).to eq DateTime.parse(
|
32
|
+
expect(output[1][:start_date_time]).to eq DateTime.parse(
|
33
|
+
'October 8, 2009 7:00 PM CDT'
|
34
|
+
)
|
31
35
|
end
|
32
36
|
|
33
37
|
it 'has expected site' do
|
@@ -40,4 +44,4 @@ describe SodaXmlTeam do
|
|
40
44
|
|
41
45
|
end
|
42
46
|
|
43
|
-
end
|
47
|
+
end
|
data/spec/soda_xml_team_spec.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'SodaXmlTeam' do
|
4
4
|
|
5
|
-
subject
|
5
|
+
subject do
|
6
|
+
SodaXmlTeam::Client.new(
|
7
|
+
ENV['SODA_USERNAME'], ENV['SODA_PASSWORD']
|
8
|
+
)
|
9
|
+
end
|
6
10
|
|
7
11
|
describe '.content_finder' do
|
8
12
|
|
9
|
-
let(:input)
|
13
|
+
let(:input) do
|
10
14
|
{
|
11
15
|
sandbox: true,
|
12
16
|
league_id: 'l.nhl.com',
|
@@ -15,7 +19,7 @@ describe "SodaXmlTeam" do
|
|
15
19
|
start_datetime: DateTime.parse('2010-01-01 00:00:00 CDT'),
|
16
20
|
end_datetime: DateTime.parse('2011-01-01 00:00:00 CDT')
|
17
21
|
}
|
18
|
-
|
22
|
+
end
|
19
23
|
let(:output) { subject.content_finder(input) }
|
20
24
|
|
21
25
|
it 'has seven items' do
|
@@ -23,19 +27,21 @@ describe "SodaXmlTeam" do
|
|
23
27
|
end
|
24
28
|
|
25
29
|
it 'has attributes that match' do
|
26
|
-
expect(output[0][:title]).to eq
|
27
|
-
expect(output[0][:link]).to eq
|
28
|
-
expect(output[0][:document_id]).to eq
|
29
|
-
expect(output[0][:date]).to eq DateTime.parse(
|
30
|
-
|
31
|
-
|
32
|
-
expect(output[0][:
|
33
|
-
expect(output[0][:
|
34
|
-
expect(output[0][:
|
35
|
-
expect(output[0][:
|
30
|
+
expect(output[0][:title]).to eq '2010 Nashville Predators Schedule'
|
31
|
+
expect(output[0][:link]).to eq 'http://soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.10875359-nas-sked'
|
32
|
+
expect(output[0][:document_id]).to eq 'xt.10875359-nas-sked'
|
33
|
+
expect(output[0][:date]).to eq DateTime.parse(
|
34
|
+
'February 14, 2010 16:14 PM CDT'
|
35
|
+
)
|
36
|
+
expect(output[0][:publisher]).to eq 'sportsnetwork.com'
|
37
|
+
expect(output[0][:priority]).to eq 'normal'
|
38
|
+
expect(output[0][:sport]).to eq '15031000'
|
39
|
+
expect(output[0][:league]).to eq 'l.nhl.com'
|
40
|
+
expect(output[0][:conference]).to eq 'c.western'
|
41
|
+
expect(output[0][:team]).to eq 'l.nhl.com-t.19'
|
36
42
|
end
|
37
43
|
|
38
|
-
let(:input)
|
44
|
+
let(:input) do
|
39
45
|
{
|
40
46
|
sandbox: true,
|
41
47
|
league_id: 'l.nhl.com',
|
@@ -44,7 +50,7 @@ describe "SodaXmlTeam" do
|
|
44
50
|
start_datetime: '2010-01-01 00:00:00 CDT',
|
45
51
|
end_datetime: '2011-01-01 00:00:00 CDT'
|
46
52
|
}
|
47
|
-
|
53
|
+
end
|
48
54
|
let(:output) { subject.content_finder(input) }
|
49
55
|
|
50
56
|
it 'has seven items with string timestamp' do
|
@@ -52,28 +58,30 @@ describe "SodaXmlTeam" do
|
|
52
58
|
end
|
53
59
|
|
54
60
|
it 'has attributes that match with string timestamp' do
|
55
|
-
expect(output[1][:title]).to eq
|
56
|
-
expect(output[1][:link]).to eq
|
57
|
-
expect(output[1][:document_id]).to eq
|
58
|
-
expect(output[1][:date]).to eq DateTime.parse(
|
59
|
-
|
60
|
-
|
61
|
-
expect(output[1][:
|
62
|
-
expect(output[1][:
|
63
|
-
expect(output[1][:
|
64
|
-
expect(output[1][:
|
61
|
+
expect(output[1][:title]).to eq '2010 Nashville Predators Schedule'
|
62
|
+
expect(output[1][:link]).to eq 'http://soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.10860136-nas-sked'
|
63
|
+
expect(output[1][:document_id]).to eq 'xt.10860136-nas-sked'
|
64
|
+
expect(output[1][:date]).to eq DateTime.parse(
|
65
|
+
'February 12, 2010 22:49 PM CDT'
|
66
|
+
)
|
67
|
+
expect(output[1][:publisher]).to eq 'sportsnetwork.com'
|
68
|
+
expect(output[1][:priority]).to eq 'normal'
|
69
|
+
expect(output[1][:sport]).to eq '15031000'
|
70
|
+
expect(output[1][:league]).to eq 'l.nhl.com'
|
71
|
+
expect(output[1][:conference]).to eq 'c.western'
|
72
|
+
expect(output[1][:team]).to eq 'l.nhl.com-t.19'
|
65
73
|
end
|
66
74
|
|
67
75
|
end
|
68
76
|
|
69
77
|
describe '.get_document' do
|
70
78
|
|
71
|
-
let(:input)
|
79
|
+
let(:input) do
|
72
80
|
{
|
73
81
|
sandbox: true,
|
74
82
|
document_id: 'xt.10875359-nas-sked'
|
75
83
|
}
|
76
|
-
|
84
|
+
end
|
77
85
|
let(:output) { subject.get_document(input) }
|
78
86
|
|
79
87
|
it 'has one schedule node' do
|
@@ -86,4 +94,4 @@ describe "SodaXmlTeam" do
|
|
86
94
|
|
87
95
|
end
|
88
96
|
|
89
|
-
end
|
97
|
+
end
|
@@ -6,12 +6,14 @@ describe SodaXmlTeam do
|
|
6
6
|
|
7
7
|
describe '.parse_standings' do
|
8
8
|
|
9
|
-
let(:input)
|
10
|
-
SodaXmlTeam::Client.new(
|
9
|
+
let(:input) do
|
10
|
+
SodaXmlTeam::Client.new(
|
11
|
+
ENV['SODA_USERNAME'], ENV['SODA_PASSWORD']
|
12
|
+
).get_document(
|
11
13
|
sandbox: true,
|
12
14
|
document_id: 'xt.10878197-standings'
|
13
|
-
|
14
|
-
|
15
|
+
)
|
16
|
+
end
|
15
17
|
let(:output) { subject.parse_standings(input) }
|
16
18
|
|
17
19
|
it 'has a division name' do
|
@@ -36,4 +38,4 @@ describe SodaXmlTeam do
|
|
36
38
|
|
37
39
|
end
|
38
40
|
|
39
|
-
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,17 +9,17 @@ RSpec.configure do |config|
|
|
9
9
|
ENV['SODA_PASSWORD'] = 'testpassword'
|
10
10
|
end
|
11
11
|
|
12
|
-
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getListings?earliest-date-time=20100101T000000-0500&fixture-keys=schedule-single-team&latest-date-time=20110101T000000-0500&league-keys=l.nhl.com&max-result-count=10&revision-control=latest-only&stylesheet=sportsml2rss-1.0-s&team-keys=l.nhl.com-t.19")
|
13
|
-
to_return(:
|
12
|
+
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getListings?earliest-date-time=20100101T000000-0500&fixture-keys=schedule-single-team&latest-date-time=20110101T000000-0500&league-keys=l.nhl.com&max-result-count=10&revision-control=latest-only&stylesheet=sportsml2rss-1.0-s&team-keys=l.nhl.com-t.19")
|
13
|
+
.to_return(status: 200, body: File.new('spec/fixtures/get_listing_schedule.xml').read, headers: {})
|
14
14
|
|
15
|
-
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.10875359-nas-sked")
|
16
|
-
to_return(:
|
15
|
+
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.10875359-nas-sked")
|
16
|
+
.to_return(status: 200, body: File.new('spec/fixtures/get_document_schedule.xml').read, headers: {})
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.3329967-NAS-2005-OUTLOOK")
|
19
|
+
.to_return(status: 200, body: File.new('spec/fixtures/get_document_news.xml').read, headers: {})
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
stub_request(:get, "https://#{ENV['SODA_USERNAME']}:#{ENV['SODA_PASSWORD']}@soda.xmlteam.com/api-trial/getDocuments?doc-ids=xt.10878197-standings")
|
22
|
+
.to_return(status: 200, body: File.new('spec/fixtures/get_document_standings.xml').read, headers: {})
|
23
23
|
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/tasks/rspec.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soda_xml_team
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Yeargin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,16 +97,20 @@ dependencies:
|
|
97
97
|
description: A basic layer for interacting with XML Team's Sports On Demand API (SODA)
|
98
98
|
email:
|
99
99
|
- stephen@seatsha.re
|
100
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- soda-league-directory
|
101
102
|
extensions: []
|
102
103
|
extra_rdoc_files: []
|
103
104
|
files:
|
104
105
|
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".rubocop_todo.yml"
|
105
108
|
- ".travis.yml"
|
106
109
|
- Gemfile
|
107
110
|
- LICENSE.txt
|
108
111
|
- README.md
|
109
112
|
- Rakefile
|
113
|
+
- bin/soda-league-directory
|
110
114
|
- lib/ca-certificates.crt
|
111
115
|
- lib/soda_xml_team.rb
|
112
116
|
- lib/soda_xml_team/address.rb
|