2017-06-01 37 views
0

所以这与我在此method上发表的一篇早期文章有关。这基本上是我在用通过hipchat发送文件:红宝石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/[email protected]/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' 
+0

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

+0

您使用的是什么版本的宝石? '猫Gemfile.lock | grep hipchat' –

+0

'hipchat(1.5.4)' –

回答

0

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

纵观question you referencedthe 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) 
+0

我收到了同样的错误。 –

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')