【发布时间】:2017-10-12 13:14:09
【问题描述】:
我正在创建一个从 API 中提取一些数据的 Dashing 作业(这运行 Ruby)
SCHEDULER.every '15m', :first_in => 0 do |job|
url = "https://blah.com
response = RestClient.get(url, {:Authorization => 'blahblah'})
current_timelist = JSON.parse(response)
acctitems = current_timelist.map do |row|
row = {
:label => row['member']['name'],
:value => row['actualHours']
}
end
# Update the List widget
send_event('timelist', { items: acctitems } )
end
我想根据成员名称进行总结,但它列出了每个条目。
从 API 接收到的 JSON 如下所示(我已经缩短了这个,并且只更改了名称),注意 actualHours 可以是 0:
[
{
"member": {
"name": "User 1"
},
"actualHours": 0.2
},
{
"member": {
"name": "User 2"
},
"actualHours": 1.5
},
{
"member": {
"name": "User 2"
},
"actualHours": 0.17
}
]
我还想对此进行排序,以便我可以让顶级成员排在首位。我还想与列表中的第一人发送第二个事件(这样他们就可以获得金星)。
【问题讨论】:
标签: json ruby associative-array dashing