logicmonitor_simple 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/logicmonitor_simple.rb +35 -30
- metadata +3 -4
data/lib/logicmonitor_simple.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Simple LogicMonitor API library - a spartan wrapper around the LogicMonitor API
|
4
4
|
#
|
5
5
|
# Author: Michael Mittelstadt (<meek@getsatisfaction.com>)
|
6
|
-
# Version: 0.1.
|
6
|
+
# Version: 0.1.3
|
7
7
|
#
|
8
8
|
# Usage:
|
9
9
|
#
|
@@ -21,38 +21,43 @@ require 'multi_json'
|
|
21
21
|
require 'cgi'
|
22
22
|
|
23
23
|
module Logicmonitor
|
24
|
-
|
25
|
-
def initialize(domain, username, password)
|
26
|
-
@domain = domain
|
27
|
-
@username = username
|
28
|
-
@password = password
|
29
|
-
@cookies = []
|
30
|
-
self.sign_in({ 'c' => @domain, 'u' => @username, 'p' => @password })
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_missing(method, *args)
|
34
|
-
method = method.to_s.split('_').each_with_index.map { |e,i| i>0 ? e.capitalize : e }.join
|
35
|
-
http_args = args[0].to_camelback_keys.map do |k,v|
|
36
|
-
if v.is_a? Array
|
37
|
-
v = v.join(',')
|
38
|
-
end
|
39
|
-
"#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
|
40
|
-
end.join('&') rescue ""
|
41
|
-
g = Curl.get("https://#{@domain}.logicmonitor.com/santaba/rpc/#{method}?#{http_args}") do |http|
|
42
|
-
if @cookies.size > 0
|
43
|
-
http.headers['Cookie'] = @cookies.join('; ')
|
44
|
-
end
|
45
|
-
end
|
24
|
+
class Simple
|
46
25
|
|
47
|
-
|
48
|
-
|
49
|
-
|
26
|
+
def auth_credentials
|
27
|
+
{ 'c' => @domain, 'u' => @username, 'p' => @password }
|
28
|
+
end
|
50
29
|
|
51
|
-
|
52
|
-
|
53
|
-
|
30
|
+
def initialize(domain, username, password)
|
31
|
+
@domain = domain
|
32
|
+
@username = username
|
33
|
+
@password = password
|
34
|
+
@cookies = []
|
35
|
+
end
|
54
36
|
|
55
|
-
|
37
|
+
def method_missing(method, *args)
|
38
|
+
method = method.to_s.split('_').each_with_index.map { |e,i| i>0 ? e.capitalize : e }.join
|
39
|
+
http_args = (args[0] || {}).merge(auth_credentials).to_camelback_keys.map do |k,v|
|
40
|
+
if v.is_a? Array
|
41
|
+
v = v.join(',')
|
56
42
|
end
|
43
|
+
"#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
|
44
|
+
end.join('&')
|
45
|
+
|
46
|
+
g = Curl.get("https://#{@domain}.logicmonitor.com/santaba/rpc/#{method}?#{http_args}") do |http|
|
47
|
+
if @cookies.size > 0
|
48
|
+
http.headers['Cookie'] = @cookies.join('; ')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if @cookies.empty?
|
53
|
+
@cookies = g.header_str.scan(/^Set-Cookie: ([^\r]+)?\r/m)
|
54
|
+
end
|
55
|
+
|
56
|
+
if g.status.to_i > 399
|
57
|
+
raise "Received unexpected HTTP status #{g.status} Response Body: #{g.body_str}"
|
58
|
+
end
|
59
|
+
|
60
|
+
MultiJson.decode(g.body_str) or raise Logicmonitor::Simple::Error 'Received invalid JSON from LogicMonitor'
|
57
61
|
end
|
62
|
+
end
|
58
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logicmonitor_simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: curb
|
@@ -88,9 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.23
|
92
92
|
signing_key:
|
93
93
|
specification_version: 3
|
94
94
|
summary: Simple API client for LogicMonitor
|
95
95
|
test_files: []
|
96
|
-
has_rdoc:
|