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



48
49
50
51
# File 'lib/infostrada/call_refresh.rb', line 48

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

.get_latestObject



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

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
# File 'lib/infostrada/call_refresh.rb', line 44

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

.since(date) ⇒ Object



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

def self.since(date)
  date = date.strftime(DATE_FORMAT)

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

  self.last_update = api_time(Time.now)

  endpoints = []
  list.each do |hash|
    lang = hash['c_QueryString'].scan(/languagecode=(\d+)/).flatten.first.to_i

    endpoints << Endpoint.new(hash) if LANGUAGE_CODES.include?(lang)
  end

  endpoints
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