ruby-miradore 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae4429c886f0c83f4f8e45ed0e5ca2c8a33b3c3b170e60c0061180a476ed5edf
4
- data.tar.gz: f8ee91a7f7893fbc7a1b43976a5673ee0d8aed2e5cf40097862a182b5127e453
3
+ metadata.gz: bbe3675a437a4f1a7db9f1970b5ffff9f49d7767f8f074212b1d4c115bb4a352
4
+ data.tar.gz: d62031266909082c468a35bd316c642f46c7342bb788283aee194f13cc21c4a0
5
5
  SHA512:
6
- metadata.gz: 29c3cba4f3ec8e0708a737c9217de99caed9880bc3b24e56b220c5cac27f148e3acba2fb53a2715340a2ee379fa67ea5c12b4cfb66297a7477b515fc95e79520
7
- data.tar.gz: 199c7dddd4b12a9c79ee411a9bdca3ac314afa12db5c9c7d5a0a63fc29151352fbf2834f51eba0a96cdb688ec2e7280aa4a036824ef7fd13f773c76e79ecbce2
6
+ metadata.gz: 391f48e2cf12a8837494506f3badf713fa7c0ad27f3b29b67cedaa9f4cfcbea98f43d70cfa7bd810f9ab7526de9982b7139b77375dec7115d18b7b5b558b5e14
7
+ data.tar.gz: a6c04e0cc89456c175855c73cbde0f7f6b172193fc612b828ae93dbf656c921f7ff41fe33cc72a2dec7708bbe2ac365620f0db28c4a6569cf53bd37d71c848b1
data/Gemfile CHANGED
@@ -4,3 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in ruby-miradore.gemspec
6
6
  gemspec
7
+
8
+ group :test do
9
+ gem "webmock"
10
+ gem "vcr"
11
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-miradore (0.2.1)
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.13.0)
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.2.0, < 2.0)
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 'httparty'
5
- require 'json'
6
- require 'crack/xml'
7
- require 'finest/builder'
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['MSP_API_KEY']
14
+ @@msp_api_key = ENV["MSP_API_KEY"]
15
15
  end
16
16
 
17
17
  def self.api_urls
18
18
  {
19
- v1: 'https://%{subdomain}.online.miradore.com/API/Device?auth=%{auth}&select=*,Category.*,InvDevice.*,InvStorage.*,InvOS.*,Enrollment.*,Client.*,User.*,Location.*,Security.*,ReportedLocation.*',
20
- v2: 'https://%{subdomain}.online.miradore.com/API/v2/Device/%{id}/%{method}'
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::api_urls[version] % { subdomain: args[0], id: args[1], method: args[2], auth: Miradore::api_key }
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 Listing
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(Crack::XML.parse(get(Miradore::url(:v1, subdomain)).body).to_json, :quirks_mode => true).dig("Content", "Items", "Device")
36
-
37
- if response.is_a?(Array)
38
- response.map! { |e| Device.new(e.transform_keys(&:downcase), subdomain) }
39
- else
40
- Device.new(response.transform_keys(&:downcase), subdomain)
41
- end
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.new("Error connecting to manager service provider")
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 (args[0])
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 'X-API-Key' => Miradore::api_key
85
- self.class.method(args[0]).call(Miradore::url(:v2, subdomain, args[1], args[2]))
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.new("Error connecting to manager service provider")
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby
4
4
  module Miradore
5
- VERSION = "0.2.1"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  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.2.1
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-03 00:00:00.000000000 Z
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake