Class: Interwetten::LivescoreClient
- Inherits:
-
Object
- Object
- Interwetten::LivescoreClient
- Defined in:
- lib/interwetten/clients/livescore_client.rb
Instance Method Summary collapse
- #common_process(event) ⇒ Object
- #get_events ⇒ Object
- #get_events_clone_id ⇒ Object
- #get_events_id ⇒ Object
- #get_last_entry_by_clone_id(event_id) ⇒ Object
- #get_score(event_id) ⇒ Object
- #get_score_by_clone_id(event_id) ⇒ Object
- #get_value_in_score(score, attribute) ⇒ Object
-
#initialize(affiliate, options = {}) ⇒ LivescoreClient
constructor
A new instance of LivescoreClient.
- #pluck_events(attribute) ⇒ Object
- #process_default(event) ⇒ Object
- #process_score(event) ⇒ Object
- #process_tennis(event) ⇒ Object
- #transform_format(value) ⇒ Object
Constructor Details
#initialize(affiliate, options = {}) ⇒ LivescoreClient
Returns a new instance of LivescoreClient.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/interwetten/clients/livescore_client.rb', line 3 def initialize(affiliate, = {}) params = { "LanguageID" => [:language] || "EN", "Filter" => [:filter], "b" => affiliate } url = "https://ad.interwetten.com/ticker_temp/offer.asmx/GetLiveEventList?" + params.to_query begin @xml = Nokogiri::XML(open(URI.escape(url))).remove_namespaces! rescue end end |
Instance Method Details
#common_process(event) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/interwetten/clients/livescore_client.rb', line 62 def common_process(event) gametime = event.get_attribute("GAMETIME").delete("ยด") sport_id = event.get_attribute("LIVE_KOSID") status = event.get_attribute("STATUS") interwetten_id = event.get_attribute("ID") name = event.get_attribute("NAME").gsub("(LIVE)", "").gsub("(live)", "") name = name.split("-").map { |contender| contender.strip }.join("-") {interwetten_id: interwetten_id, :gametime => gametime, :status => status, :name => name, sport_id: sport_id} end |
#get_events ⇒ Object
29 30 31 |
# File 'lib/interwetten/clients/livescore_client.rb', line 29 def get_events get_events_clone_id end |
#get_events_clone_id ⇒ Object
25 26 27 |
# File 'lib/interwetten/clients/livescore_client.rb', line 25 def get_events_clone_id @events_clone_id ||= pluck_events('CLONEID') end |
#get_events_id ⇒ Object
21 22 23 |
# File 'lib/interwetten/clients/livescore_client.rb', line 21 def get_events_id @events_id ||= pluck_events('ID') end |
#get_last_entry_by_clone_id(event_id) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/interwetten/clients/livescore_client.rb', line 42 def get_last_entry_by_clone_id(event_id) event = @xml.search("EVENT[CLONEID='#{event_id}']").first entry = event.search("ENTRY").first { :id => entry.get_attribute("ID"), :display_time => entry.get_attribute("DISPLAYTIME"), :message => entry.get_attribute("MESSAGE") } end |
#get_score(event_id) ⇒ Object
38 39 40 |
# File 'lib/interwetten/clients/livescore_client.rb', line 38 def get_score(event_id) get_score_by_clone_id(event_id) end |
#get_score_by_clone_id(event_id) ⇒ Object
33 34 35 36 |
# File 'lib/interwetten/clients/livescore_client.rb', line 33 def get_score_by_clone_id(event_id) event = @xml.search("EVENT[CLONEID='#{event_id}']").first process_score(event) end |
#get_value_in_score(score, attribute) ⇒ Object
92 93 94 |
# File 'lib/interwetten/clients/livescore_client.rb', line 92 def get_value_in_score(score, attribute) transform_format(score.detect { |value| value =~/^#{attribute}/ }) end |
#pluck_events(attribute) ⇒ Object
17 18 19 |
# File 'lib/interwetten/clients/livescore_client.rb', line 17 def pluck_events(attribute) @xml.search("EVENT").map { |value| value.get_attribute(attribute).to_i } if @xml end |
#process_default(event) ⇒ Object
72 73 74 75 |
# File 'lib/interwetten/clients/livescore_client.rb', line 72 def process_default(event) result = transform_format(event.get_attribute("SCORE").split("|").first) common_process(event).merge(:result => result) end |
#process_score(event) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/interwetten/clients/livescore_client.rb', line 49 def process_score(event) case event.get_attribute("LIVE_KOSID") when "10", "15" process_default(event) when "11" process_tennis(event) end end |
#process_tennis(event) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/interwetten/clients/livescore_client.rb', line 77 def process_tennis(event) score = event.get_attribute("SCORE") splitted_score = score.split "|" sets = splitted_score.select { |value| value=~/^Set / }.map do |set| transform_format(set) end in_game = get_value_in_score(splitted_score, "InGame") tie_break = get_value_in_score(splitted_score, "Tiebreak") serving = get_value_in_score(splitted_score, "#Serving") common_process(event).merge(:sets => sets, :in_game => in_game, :serving => serving, :tie_break => tie_break) end |
#transform_format(value) ⇒ Object
58 59 60 |
# File 'lib/interwetten/clients/livescore_client.rb', line 58 def transform_format(value) value.split('=').last.delete(' ').gsub(':', '-') end |