8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/guardian/notifier.rb', line 8
def self.notify system_id, attributes
assert_valid_keys! attributes, :online, :description, :data
unless attributes.has_key? :online
raise ArgumentError, ":online missing! Must specify :online as a boolean."
end
if !attributes.has_key?(:description) && attributes[:online] == false
raise ArgumentError, ":description missing! Must specify description when offline"
end
uri = URI.parse "#{Guardian::API_URL}/systems/#{system_id}/updates"
params = {:update => attributes, :account_id => Guardian.account_id}
request = Net::HTTP::Post.new(uri.path)
request.content_type = 'application/json'
request.body = params.to_json
response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(request) }
if response.is_a?(Net::HTTPUnauthorized)
raise RuntimeError, "Request unauthorized! You must specify correct account and system tokens"
end
unless response.is_a?(Net::HTTPCreated)
raise RuntimeError, "Guardian did something unexpected!\n #{response.body}"
end
true
end
|