bntzio
10/4/2015 - 2:36 AM

parser

parser

class BettingController < ApplicationController
    require 'net/http'
    require 'rubygems'
    require 'xmlsimple'
    require 'mechanize'

    def xmlLigaMXToRb()
        agent = Mechanize.new
        xml = agent.get("http://api.sportradar.us/soccer-t2/na/matches/schedule.xml?api_key=jfsf5q9bpke6byevu7chvn2x")
        document = REXML::Document.new(xml.body)

        status = XPath.match(document, "//match/status").map {|x| x.text} 
        puts (status)
        
        if status == "scheduled" then
            country_code =  XPath.match(document, "//match/category/country_code").map {|x| x.text} 
            puts (country_code)
            if country_code == "MEX" then
                match_id =  XPath.match(document, "//match/id").map {|x| x.text} 
                puts (match_id)
                @partido = match_id
                
                away_id =  XPath.match(document, "//match/away/id").map {|x| x.text} 
                puts (away_id)
                
                home_id =  XPath.match(document, "//match/home/id").map {|x| x.text} 
                puts (home_id)
            end
        end
    end
    
    def goToGameBox()
        agent = Mechanize.new
        xml = agent.get("http://api.sportradar.us/soccer-t2/na/matches/"+match_id+"/boxscore.xml?api_key=jfsf5q9bpke6byevu7chvn2x")
        document = REXML::Document.new(xml.body)

        away_id =  XPath.match(document, "//match/away/id").map {|x| x.text} 
        puts (away_id)
                
        home_id =  XPath.match(document, "//match/home/id").map {|x| x.text} 
        puts (home_id)
    end
    
    def index
        @partido = xmlLigaMXToRb()
    end
    
end