0

所以这与我之前在这个方法上发表的一篇文章有​​关。这基本上就是我用来通过 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'
4

2 回答 2

0

问题是我试图通过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')
于 2017-06-02T21:13:02.683 回答
0

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

查看您引用的问题以及他们使用发送请求的另一个用户发布的源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)
于 2017-06-01T20:46:12.763 回答