我正在尝试使用 ruby gem 设置一个示例批量上传到 Keen.io。从他们的文档中:
Keen.publish_batch(
:signups => [
{ :name => "Bob" },
{ :name => "Mary" }
],
:purchases => [
{ :price => 10 },
{ :price => 20 }
]
)
我在 rake 任务中尝试生成类似的东西:
task backfill_keen_jobs: :environment do
jobs_array = Array.new
Job.last(5).each do |j|
job_type = j.job_type.present? ? j.job_type.description : nil
job = {
:keen => {
:timestamp => j.created_at.to_time.iso8601
},
:id => j.id,
:title => j.title,
:type => job_type,
:company => j.company
}
jobs_array << JSON.generate(job)
end
puts jobs_array
puts Keen.publish_batch(:jobs => [jobs_array.to_json])
end
我收到以下错误:
{"jobs"=>[{"success"=>false, "error"=>{"name"=>"InvalidPropertyNameError", "description"=>"An event should be a JSON object of properties."}}]}
我确定我只是以某种方式弄乱了 JSON 输出,但我似乎无法弄清楚如何/在哪里?
谢谢!