12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/thong/api.rb', line 12
def self.post_json(endpoint, hash)
disable_net_blockers!
url = endpoint_to_url(endpoint)
puts "[Thong] Submitting to #{ENDPOINT}".colorize(:cyan)
hash = hash.merge(CONFIG)
response = RestClient.post(url, :json_file => hash_to_file(hash))
response_hash = MultiJson.load(response.to_str)
puts "[Thong] #{ response_hash['message'] }".colorize(:cyan)
if response_hash['message']
puts "[Thong] #{response_hash['url'].underline}".colorize(:cyan)
end
rescue RestClient::ServiceUnavailable
puts "[Thong] API timeout ocurred, but data should still be processed".colorize(:red)
rescue RestClient::InternalServerError
puts "[Thong] API internal error occured, please check the log files in your Thong Server".colorize(:red)
end
|