Class: Scorespro::SoccerMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/scorespro_parser/soccer_match.rb

Constant Summary collapse

SPORT_ID =
1

Class Method Summary collapse

Class Method Details

.between(initial_date, finish_date) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scorespro_parser/soccer_match.rb', line 6

def self.between(initial_date, finish_date)
  options = { 
    state: 'clientUpdate',
    usr: Scorespro.user, 
    pwd: Scorespro.password, 
    type: Scorespro::Type::BETWEEN_DATES,
    start: initial_date,
    :end => finish_date,
    s: SPORT_ID,
    tz: "America/Sao_Paulo"
  }
  
  http_response = JSON.parse(HTTParty.get('http://data2.scorespro.com/exporter/json.php', query: options))
  if http_response["error"]
    result = { error: http_response["error"], matches: {} }
  else 
    matches = http_response["list"]["Sport"]["1"].key?("Matchday") ? http_response["list"]["Sport"]["1"]["Matchday"][Date.today.to_s]["Match"] : {}
    result = { matches: matches}
  end
  
  result
end

.get_latest_soccer_hidObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/scorespro_parser/soccer_match.rb', line 52

def self.get_latest_soccer_hid
  options = { 
    state: 'clientStructure',
    type: Scorespro::Type::SPORTS,
  }
  response = JSON.parse(HTTParty.get('http://data2.scorespro.com/exporter/json.php', query: options))
  soccer_last_hid = response["list"]["1"]["hid"]
  
  soccer_last_hid
end

.live(last_update) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/scorespro_parser/soccer_match.rb', line 29

def self.live(last_update)
  hid = last_update.blank? ? SoccerMatch.get_latest_soccer_hid : last_update
  options = { 
    state: 'clientUpdate',
    usr: Scorespro.user, 
    pwd: Scorespro.password, 
    type: Scorespro::Type::LIVE, 
    s: SPORT_ID,
    h: hid,
    tz: "America/Sao_Paulo"
  }

  http_response = JSON.parse(HTTParty.get('http://data2.scorespro.com/exporter/json.php', query: options))
  if http_response["error"]
    result = { error: http_response["error"], matches: {} }
  else 
    matches = http_response["list"]["Sport"]["1"].key?("Matchday") ? http_response["list"]["Sport"]["1"]["Matchday"][Date.today.to_s]["Match"] : {}
    result = { hid: http_response["list"]["Sport"]["1"]["hid"], matches: matches}
  end

  result
end