ruby-miradore 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/Gemfile.lock +14 -3
- data/lib/ruby/miradore.rb +64 -21
- data/lib/ruby/miradore/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe3675a437a4f1a7db9f1970b5ffff9f49d7767f8f074212b1d4c115bb4a352
|
4
|
+
data.tar.gz: d62031266909082c468a35bd316c642f46c7342bb788283aee194f13cc21c4a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 391f48e2cf12a8837494506f3badf713fa7c0ad27f3b29b67cedaa9f4cfcbea98f43d70cfa7bd810f9ab7526de9982b7139b77375dec7115d18b7b5b558b5e14
|
7
|
+
data.tar.gz: a6c04e0cc89456c175855c73cbde0f7f6b172193fc612b828ae93dbf656c921f7ff41fe33cc72a2dec7708bbe2ac365620f0db28c4a6569cf53bd37d71c848b1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-miradore (0.
|
4
|
+
ruby-miradore (1.0.0)
|
5
5
|
crack (~> 0.4.5)
|
6
6
|
finest-builder (~> 0.0.4)
|
7
7
|
httparty (~> 0.18.1)
|
@@ -12,11 +12,14 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
+
addressable (2.7.0)
|
16
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
17
|
ast (2.4.2)
|
16
18
|
crack (0.4.5)
|
17
19
|
rexml
|
18
20
|
diff-lcs (1.4.4)
|
19
21
|
finest-builder (0.0.5)
|
22
|
+
hashdiff (1.0.1)
|
20
23
|
httparty (0.18.1)
|
21
24
|
mime-types (~> 3.0)
|
22
25
|
multi_xml (>= 0.5.2)
|
@@ -27,6 +30,7 @@ GEM
|
|
27
30
|
parallel (1.20.1)
|
28
31
|
parser (3.0.1.1)
|
29
32
|
ast (~> 2.4.1)
|
33
|
+
public_suffix (4.0.6)
|
30
34
|
rainbow (3.0.0)
|
31
35
|
rake (13.0.3)
|
32
36
|
regexp_parser (2.1.1)
|
@@ -44,19 +48,24 @@ GEM
|
|
44
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
49
|
rspec-support (~> 3.10.0)
|
46
50
|
rspec-support (3.10.2)
|
47
|
-
rubocop (1.
|
51
|
+
rubocop (1.14.0)
|
48
52
|
parallel (~> 1.10)
|
49
53
|
parser (>= 3.0.0.0)
|
50
54
|
rainbow (>= 2.2.2, < 4.0)
|
51
55
|
regexp_parser (>= 1.8, < 3.0)
|
52
56
|
rexml
|
53
|
-
rubocop-ast (>= 1.
|
57
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
54
58
|
ruby-progressbar (~> 1.7)
|
55
59
|
unicode-display_width (>= 1.4.0, < 3.0)
|
56
60
|
rubocop-ast (1.5.0)
|
57
61
|
parser (>= 3.0.1.1)
|
58
62
|
ruby-progressbar (1.11.0)
|
59
63
|
unicode-display_width (2.0.0)
|
64
|
+
vcr (6.0.0)
|
65
|
+
webmock (3.12.2)
|
66
|
+
addressable (>= 2.3.6)
|
67
|
+
crack (>= 0.3.2)
|
68
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
60
69
|
|
61
70
|
PLATFORMS
|
62
71
|
x86_64-darwin-20
|
@@ -64,6 +73,8 @@ PLATFORMS
|
|
64
73
|
|
65
74
|
DEPENDENCIES
|
66
75
|
ruby-miradore!
|
76
|
+
vcr
|
77
|
+
webmock
|
67
78
|
|
68
79
|
BUNDLED WITH
|
69
80
|
2.2.15
|
data/lib/ruby/miradore.rb
CHANGED
@@ -1,48 +1,71 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "miradore/version"
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
4
|
+
require "httparty"
|
5
|
+
require "json"
|
6
|
+
require "crack/xml"
|
7
|
+
require "finest/builder"
|
8
8
|
|
9
9
|
module Ruby
|
10
10
|
module Miradore
|
11
11
|
class MspConnectionError < StandardError; end
|
12
12
|
|
13
13
|
def self.api_key
|
14
|
-
@@msp_api_key = ENV[
|
14
|
+
@@msp_api_key = ENV["MSP_API_KEY"]
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.api_urls
|
18
18
|
{
|
19
|
-
|
20
|
-
|
19
|
+
simple_v1: "https://%{subdomain}.online.miradore.com/API/Device?auth=%{auth}&select=ID,%{item}.*&filters=%{filter}",
|
20
|
+
v1: "https://%{subdomain}.online.miradore.com/API/Device?auth=%{auth}&select=*,Category.*,InvDevice.*,InvStorage.*,InvOS.*,Enrollment.*,Client.*,User.*,Location.*,Security.*,ReportedLocation.*&filters=%{filter}",
|
21
|
+
v2: "https://%{subdomain}.online.miradore.com/API/v2/Device/%{id}/%{method}"
|
21
22
|
}
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.url(version = :v1, *args)
|
25
|
-
Miradore
|
26
|
+
Miradore.api_urls[version] % {
|
27
|
+
subdomain: args[0],
|
28
|
+
item: args[1],
|
29
|
+
id: args[1],
|
30
|
+
method: args[2],
|
31
|
+
filter: args[2][0].nil? ? nil : "(InvDevice.SerialNumber eq #{args[2][0]})",
|
32
|
+
auth: Miradore.api_key
|
33
|
+
}
|
26
34
|
end
|
27
35
|
|
28
|
-
class
|
36
|
+
class Request
|
29
37
|
include HTTParty
|
30
38
|
format :json
|
31
39
|
|
32
40
|
attr_reader :subdomain
|
33
41
|
|
34
42
|
def self.all(subdomain, *args)
|
35
|
-
response = JSON.parse(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
response = JSON.parse(
|
44
|
+
Crack::XML.parse(
|
45
|
+
get(
|
46
|
+
Miradore.url(version, subdomain, class_name, args)
|
47
|
+
).body
|
48
|
+
).to_json,
|
49
|
+
quirks_mode: true
|
50
|
+
).dig("Content", "Items", "Device")
|
51
|
+
transform(response, subdomain)
|
42
52
|
rescue StandardError
|
43
|
-
raise MspConnectionError
|
53
|
+
raise MspConnectionError, "Error connecting to manager service provider"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.transform(response, subdomain)
|
57
|
+
return response.map! { |e| Device.new(e.transform_keys(&:downcase), subdomain) } if response.is_a?(Array)
|
58
|
+
|
59
|
+
Device.new(response.transform_keys(&:downcase), subdomain)
|
44
60
|
end
|
45
61
|
|
62
|
+
def self.version
|
63
|
+
superclass == Request ? :simple_v1 : :v1
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.class_name
|
67
|
+
to_s.split("::").last
|
68
|
+
end
|
46
69
|
end
|
47
70
|
|
48
71
|
class Device
|
@@ -63,7 +86,7 @@ module Ruby
|
|
63
86
|
end
|
64
87
|
|
65
88
|
def lostmode(*args)
|
66
|
-
if
|
89
|
+
if args[0]
|
67
90
|
http_method(:post, id, __method__)
|
68
91
|
else
|
69
92
|
http_method(:delete, id, __method__)
|
@@ -81,13 +104,33 @@ module Ruby
|
|
81
104
|
private
|
82
105
|
|
83
106
|
def http_method(*args)
|
84
|
-
self.class.headers
|
85
|
-
self.class.method(args[0]).call(Miradore
|
107
|
+
self.class.headers "X-API-Key" => Miradore.api_key
|
108
|
+
self.class.method(args[0]).call(Miradore.url(:v2, subdomain, args[1], args[2]))
|
86
109
|
rescue StandardError
|
87
|
-
raise MspConnectionError
|
110
|
+
raise MspConnectionError, "Error connecting to manager service provider"
|
88
111
|
end
|
89
112
|
|
90
113
|
end
|
91
114
|
|
115
|
+
class Category < Request; end
|
116
|
+
|
117
|
+
class InvDevice < Request; end
|
118
|
+
|
119
|
+
class InvStorage < Request; end
|
120
|
+
|
121
|
+
class InvOS < Request; end
|
122
|
+
|
123
|
+
class Enrollment < Request; end
|
124
|
+
|
125
|
+
class Client < Request; end
|
126
|
+
|
127
|
+
class User < Request; end
|
128
|
+
|
129
|
+
class Location < Request; end
|
130
|
+
|
131
|
+
class Security < Request; end
|
132
|
+
|
133
|
+
class ReportedLocation < Request; end
|
134
|
+
|
92
135
|
end
|
93
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-miradore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|