2017-06-01 114 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')