Class: Infostrada::CallRefresh

Inherits:
BaseRequest show all
Defined in:
lib/infostrada/call_refresh.rb

Constant Summary collapse

URL =
'/GetAPICallRefresh_Module'
TIMEZONE =

The API timezone. This is very important since all the dates passed as argument to the refresh call must be in the correct timezone.

'Europe/Amsterdam'
LANGUAGE_CODES =

Which languages are you interested in? The GetAPICallRefresh_Module call can return multiple endpoints for the same thing if multiple languages are available.

languageCode can be one of the following: 1 = dutch 2 = english 4 = french 8 = german 128 = norwegian 256 = swedish 1024 = danish

[2]
OUTPUT_TYPE =

The outputType parameter can be one of the following: 1 = xml 2 = json 3 = soap

2
DATE_FORMAT =

How to format the date. This string will be used on a Date#strftime. Infostrada will work with formats like this: 2013-09-21T22:22:22.

'%FT%T'

Constants inherited from BaseRequest

BaseRequest::RETRIES

Class Method Summary collapse

Methods inherited from BaseRequest

get!

Class Method Details

.api_time(date) ⇒ Object



51
52
53
54
# File 'lib/infostrada/call_refresh.rb', line 51

def self.api_time(date)
  @timezone ||= TZInfo::Timezone.get(TIMEZONE)
  @timezone.utc_to_local(date.utc)
end

.get_latestObject



56
57
58
# File 'lib/infostrada/call_refresh.rb', line 56

def self.get_latest
  since(last_update || api_time(Time.now))
end

.last_updateObject



40
41
42
# File 'lib/infostrada/call_refresh.rb', line 40

def self.last_update
  store.transaction { store[:last_update] }
end

.last_update=(date) ⇒ Object



44
45
46
47
48
49
# File 'lib/infostrada/call_refresh.rb', line 44

def self.last_update=(date)
  store.transaction {
    store[:last_update] = date
    store.commit
  }
end

.since(date) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/infostrada/call_refresh.rb', line 60

def self.since(date)
  self.last_update = api_time(Time.now)

  date_str = date.strftime(DATE_FORMAT)

  list = get!(URL, query: { from: date_str, outputType: OUTPUT_TYPE, module: 'football' })

  puts "Refresh call with #{date_str}"
  list.each_with_object([]) do |hash, endpoints|
    lang = hash['c_QueryString'].scan(/languagecode=(\d+)/).flatten.first.to_i
    endpoints << Endpoint.new(hash) if LANGUAGE_CODES.include?(lang)
  end
end

.storeObject



36
37
38
# File 'lib/infostrada/call_refresh.rb', line 36

def self.store
  @store ||= PStore.new(Infostrada.configuration.last_update_file)
end