Ruby hipchat gem无效发送文件

时间:2017-06-01 18:17:50

标签: ruby rubygems hipchat

所以这与我在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'

2 个答案:

答案 0 :(得分:0)

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

查看他们使用self.class.post发送请求的question you referencedthe source posted by another user,您的调试输出显示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)

答案 1 :(得分: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')