18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/astrobot/client.rb', line 18
def self.http_post(opts, try_counter = 0)
post_options = {
:body => opts.to_json,
:headers => { "x-transmission-session-id" => Astrobot.config[:session_id] }
}
post_options.merge!( :basic_auth => Astrobot.config[:basic_auth]) unless
Astrobot.config[:basic_auth].nil?
Astrobot::Logger.add "url: #{Astrobot.config[:url]}"
Astrobot::Logger.add "post_body:"
Astrobot::Logger.add JSON.parse(post_options[:body]).to_yaml
Astrobot::Logger.add "------------------"
response = HTTParty.post(Astrobot.config[:url], post_options)
Astrobot::Logger.debug response
if( response.code == 409 and try_counter <= 3)
Astrobot::Logger.add "changing session_id"
Astrobot.configure(:session_id => response.["x-transmission-session-id"])
try_counter.next
response = http_post(opts, try_counter)
end
response
end
|