如何打印API调用Ruby的响应

时间:2015-08-23 12:38:32

标签: ruby api response

我希望使用Kickbox的api打印API调用的响应。

这就是我所拥有的

require "kickbox"

client   = Kickbox::Client.new('XXXXXXXXXXXXXXXXXXXXXXXXXXXX')
kickbox  = client.kickbox()
response = kickbox.verify("test@example.com")

puts response

尝试在终端中运行文件时,我没有得到任何响应。

1 个答案:

答案 0 :(得分:1)

尝试response.body

{
  "result"  =>"unknown",
  "reason"  =>"no_connect",
  "role"  =>true,
  "free"  =>false,
  "disposable"  =>false,
  "accept_all"  =>false,
  "did_you_mean"  =>nil,
  "sendex"  =>0.35,
  "email"  =>"test@example.com",
  "user"  =>"test",
  "domain"  =>"example.com",
  "success"  =>true,
  "message"  =>nil
}

您还可以从response.headers

的标题中获取响应时间和余额
{
  "content-type"  =>"application/json",
  "x-kickbox-balance"  =>"99",
  "x-kickbox-response-time"=>"17"
}