访问 Garb Gem 结果
我正在使用 ruby 的 Garb gem,但我无法访问结果。
这是我的代码。
Garb::Session.login('[email protected]', 'password')
profile = Garb::Management::Profile.all.detect {|profile| profile.web_property_id == 'UA-XXXXX-X'}
@ga = profile.stats(:start_date => (Date.today - 1), :end_date => Date.today)
如果我在视图上使用调试,我可以看到结果,但无论我尝试什么,我都无法访问结果。
这是调试结果
--- !ruby/object:Garb::ResultSet
results:
- !ruby/object:OpenStruct
table:
:exits: "7820"
:pageviews: "24171"
sampled: false
total_results: 1
,即
- @ga.results.table.exits
- @ga.exits
- @ga.table.exits
我也尝试将其放入数组,但没有成功。
您以前使用过这个宝石吗?如果是这样,我如何访问这些结果。
I am playing with the Garb gem for ruby but I'm having trouble accessing the results.
Here is my code.
Garb::Session.login('[email protected]', 'password')
profile = Garb::Management::Profile.all.detect {|profile| profile.web_property_id == 'UA-XXXXX-X'}
@ga = profile.stats(:start_date => (Date.today - 1), :end_date => Date.today)
And if I use debug on the view I can see the results but whatever I try I cant access the results.
Here is the debug result
--- !ruby/object:Garb::ResultSet
results:
- !ruby/object:OpenStruct
table:
:exits: "7820"
:pageviews: "24171"
sampled: false
total_results: 1
ie
- @ga.results.table.exits
- @ga.exits
- @ga.table.exits
I have tried making it to an array as well with no luck.
Have you used this gem before? If so how do I access those results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Garb::ResultSet
是一个枚举器,因此您可以在其上使用任何枚举器方法(each
、map
等)。各个结果是 OpenStruct,因此您可以直接访问它们。The
Garb::ResultSet
is an enumerator, so you can use any of the enumerator methods on it (each
,map
, etc.). The individual results areOpenStruct
s, so you can access them directly.我使用这段代码来使用 GARB 提取我想要的内容。
要查找 cacert.pem 文件,请转到此处 http://curl.haxx.se/ca/cacert。质子交换膜
将其保存为文件并在代码中引用它。
需要注意的一件事是,您需要在 pascalcase 中请求指标和维度,然后使用下划线将它们放入 CSV 中(为什么,我不知道)。
除此之外,你就像金子一样。完成后只需打开 CSV 文件即可。
I use this code to pull what i want using GARB.
To find the cacert.pem file go here http://curl.haxx.se/ca/cacert.pem
save that as a file and reference it in the code.
One thing to note is that you will need to request the metrics and dimensions in pascalcase but then put them into your CSV with the underscore case (why, i do not know).
Other than that you're good as gold. Just open the CSV file when you're done.