Есть =>
[{:name=>"Футбол. Китай. Суперлига", :team1=>"Хэбэй Чайна Форчун", :team2=>"Гуанчжоу Эвергранд", :score=>"0-1", :timer=>"63:47", :markets=>[{"Исходы"=>[{"1"=>62.0}]}]}, {:name=>"Футбол. Китай. Суперлига", :team1=>"Хэбэй Чайна Форчун", :team2=>"Гуанчжоу Эвергранд", :score=>"0-1", :timer=>"63:47", :markets=>[{"Исходы"=>[{"X"=>10.0}]}]}, {:name=>"Футбол. Китай. Суперлига", :team1=>"Хэбэй Чайна Форчун", :team2=>"Гуанчжоу Эвергранд", :score=>"0-1", :timer=>"63:47", :markets=>[{"Исходы"=>[{"2"=>1.06}]}]},
Надо =>
[{:name=>"Футбол. Китай. Суперлига", :team1=>"Хэбэй Чайна Форчун", :team2=>"Гуанчжоу Эвергранд", :score=>"0-1", :timer=>"63:47", :markets=>[{"Исходы"=>[{"1"=>62.0}, {"X"=>10}, {"2"=>1.06}]}]}]
Код =>
def inplay
events = Array.new
Async do
KIND.each do |sport|
BARRIER.async do
response = CLIENT.get INPLAY + sport.to_s
JSON.parse(response.read)['events'].each do |outcomes|
# if outcomes['parentId']
next unless outcomes['parentId'] == 0
begin
# delet this line unless we need it onli win markets
# next unless outcomes['subcategories'][0]['type'] == 0
events << {
"name":outcomes['sportName'],
"timer":outcomes['timer'],
"score":outcomes['score'],
"team1":outcomes['team1'],
"team2":outcomes['team2'],
"coeff":outcomes['subcategories'],
"id":outcomes['id'],
}
rescue => exception
end
end
end
end
BARRIER.wait
ensure
CLIENT&.close
end
events
end
EVENTS = Array.new
inplay.each do |outcomes|
begin
outcomes[:coeff].each do |market|
market['quotes'].each do |v|
EVENTS << {
"name":outcomes[:name],
"team1":outcomes[:team1],
"team2":outcomes[:team2],
"score":outcomes[:score],
"timer":outcomes[:timer],
"markets":[
{
market['name']=>[{v['name']=>v['value']}]
}
],
}
# puts v['name'], v['value']
end
end
rescue => exception
end
end
p EVENTS