【问题标题】:Ruby - no implicit conversion of HTTParty::Response into String exotel apiRuby - 没有将 HTTParty::Response 隐式转换为 String exotel api
【发布时间】:2017-09-13 13:54:11
【问题描述】:

我无法使用 exotel ruby​​gem http://www.rubydoc.info/gems/exotel/0.2 上提供的文档获取响应或向 exotel sms api 发送请求

文档说要获取响应如下:

sms = Exotel::Sms.details(sms_id)

但是当我使用 sms_id 执行此操作时,例如。 sms_id='12345678901234567890' 喜欢

sms = Exotel::Sms.details("12345678901234567890")

报错

TypeError: no implicit conversion of HTTParty::Response into String

我确实安装了 httparty gem。如何解决?

【问题讨论】:

  • 'exotel' 最后更新于 2013 年 2 月 23 日。它很有可能在 httpary 上期待不同的版本。在这个 gem 的源代码中,他们使用的是 httparty (0.10.2)。我会尝试将 httparty 更改为该版本,看看您是否收到相同的错误。

标签: ruby-on-rails version typeerror httparty exotel-api


【解决方案1】:

使用 httpartyhttparty 版本的 0.9.0 对该库进行测试,该版本过去使用 Hash 响应 http 请求,代码假设它是 string 如果不是 Hash,这就是它失败的原因

这是导致问题的行

exotel/response.rb

快速解决方法是使用 'httparty=0.9.0'

你可以使用

gem "httparty","0.9.0"

这是一个工作示例代码,请用你的更新 account_sid 和令牌

gem "httparty","0.9.0"
require "exotel"

account_sid = "testexotel"
token = "9dcb4*******************e1dc2174fc47" 

Exotel.configure do |c|
  c.exotel_sid   = account_sid
  c.exotel_token = token
end

sms = Exotel::Sms.details("40a7*********258d411898b18b")
puts sms.status
puts sms.date_sent

【讨论】:

  • 它是 nit 官方 exotel ruby​​ 库。我建议使用较新的库 gem install exotel-api-client 最近更新 2 年
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多