ruby-on-rails - Ruby - 没有将 HTTParty::Response 隐式转换为 String exotel api

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

我无法使用 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。怎么解决这个问题?

最佳答案

该库使用 0.9.0 版本的 httparty 进行了测试,该版本用于使用 Hash 响应 http 请求,并且代码假设它是这样的如果不是哈希,则为 string,这就是它失败的原因

这是导致问题的行

exotel/response.rb

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

您可以使用

gem "httparty","0.9.0"

这是一个工作示例代码,请使用您的更新 account_sid 和 token

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

关于ruby-on-rails - Ruby - 没有将 HTTParty::Response 隐式转换为 String exotel api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46199467/

相关文章:

ruby-on-rails - 如何修改rails 4中的bootstrap flash消息

javascript - 为什么我收到 TypeError X is not a function

javascript - 如何处理未定义属性 javascript 类型错误的未定义属性?

solr - 如何从文件中找到当前的 Solr 版本

java - 按版本日期表示 hibernate 实体中连接表的单个元素

javascript - 未捕获的类型错误 : Cannot read property 'toLowerCase' of undefined

ruby-on-rails - ActionCable - Puma - Nginx - SSL

ruby-on-rails - Fedex gem,多个包裹

javascript - Ruby on Rails : How to add a link_to in a select_tag

编译代码的 Java(JRE) 版本兼容性