【问题标题】:Ruby hipchat gem invalid send fileRuby hipchat gem 无效的发送文件
【发布时间】:2017-06-01 18:17:49
【问题描述】:

所以这与我之前在method 上发表的帖子有关。这基本上就是我用来通过 hipchat 发送文件的方式:

#!/usr/bin/env ruby
require 'hipchat'

client = HipChat::Client.new('HIPCHAT_TOKEN', :api_version => 'v2', :server_url => 'HIPCHAT_URL')
client.user('some_username').send_file('message', File.open('./output/some-file.csv') )
client['some_hipchat_room'].send_file('some_user', 'message', File.open('./output/some-file.csv') ) 

现在由于某种原因 send_file 方法无效:

/path/to/gems/hipchat-1.5.4/lib/hipchat/errors.rb:40:in `response_code_to_exception_for': You requested an invalid method. path:https://hipchat.illum.io/v2/user/myuser@myemail/share/file?auth_token=asdfgibberishasdf method:Net::HTTP::Get (HipChat::MethodNotAllowed)
    from /path/to/gems/gems/hipchat-1.5.4/lib/hipchat/user.rb:50:in `send_file'

【问题讨论】:

  • 我认为这表明你应该使用 POST 而不是 GET,但我不确定,因为我没有使用过这个库,也没有使用 Hipchat。
  • 您使用的是什么版本的 gem? cat Gemfile.lock | grep hipchat
  • hipchat (1.5.4)
  • 我编辑了我的帖子以帮助调试。

标签: ruby rubygems hipchat


【解决方案1】:

我认为这表明您应该使用 POST 而不是 GET,但我不确定,因为我没有使用过这个库或 Hipchat。

查看question you referenced 和the source posted by another user,他们使用self.class.post 发送请求,您的调试输出显示Net::HTTP::Get

要调试,你能不能试试,

file = Tempfile.new('foo').tap do |f|
  f.write("the content")
  f.rewind
end

user = client.user(some_username)
user.send_file('some bytes', file)

【讨论】:

    【解决方案2】:

    问题是我试图通过http 而不是https 连接到服务器。如果以下客户端导致问题:

    client = HipChat::Client.new('HIPCHAT_TOKEN', :api_version => 'v2', :server_url => 'my.company.com')
    

    然后尝试将https:// 添加到您公司名称的开头。

    client = HipChat::Client.new('HIPCHAT_TOKEN', :api_version => 'v2', :server_url => 'https://my.company.com')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      相关资源
      最近更新 更多