ruby-miradore 4.4.3 → 4.4.4

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: c3966923afe8342fe94ceaa1e6e10239eaad50307923e7780023b6c6af1824b0
4
- data.tar.gz: 83b089745b8d959986bacf5e7e0bd4ae4330a4a1724cb23ad266271076c2ee32
3
+ metadata.gz: 6f593a23d0e8d61e532551e6d9a6937f1bcd6620cd5c63d5e368abe1a7233210
4
+ data.tar.gz: 5fd985ccdae20fe0f1dafb5f7e33dc4662b9f80c25e6150cace217d176453b88
5
5
  SHA512:
6
- metadata.gz: a3671cf3e70e176a35ac87d57f0b050731706d29f2b76a1d59b890de5b5864eeeb3bceb65f56b0eb56b1e60d100f498c814bc90ea636bc36e45f27c2519f7c50
7
- data.tar.gz: f4bfedcb6e728e05eaba3165562c7020df6d39aa6f643820b2cfb83dc65395acb0c6f9fecc04b9b8e6fe28e41d3e0c8d64ca07f146d618cebc83c2abe1136059
6
+ metadata.gz: 3e7f2e1c73b7932a599d7de0e8a7d8fd76c73f293044bbd77aaccc3127a942b4d597d9ec16383008998bb161dd7a658fde32b8339be524913f0a7c5e55457e2a
7
+ data.tar.gz: 4cbb4045fd90ff8fa58be37ba2df92861c7572d0a2705afadb8ebf58f8eb9c4da81e52303f0f0695b1dcb9aa579fff43889989a94c0effb3f8624907fbe9db97
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-miradore (4.4.3)
4
+ ruby-miradore (4.4.4)
5
5
  activesupport (~> 7.0)
6
6
  builder (~> 3.1)
7
7
  crack (~> 0.4)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby
4
4
  module Miradore
5
- VERSION = '4.4.3'
5
+ VERSION = '4.4.4'
6
6
  end
7
7
  end
data/lib/ruby/miradore.rb CHANGED
@@ -3,13 +3,32 @@
3
3
  require_relative 'miradore/version'
4
4
  require 'active_support/isolated_execution_state'
5
5
  require 'active_support/core_ext/hash/conversions'
6
+ require 'active_support/core_ext/hash/indifferent_access'
6
7
  require 'active_support/core_ext/module/attribute_accessors'
7
8
  require 'httparty'
8
9
  require 'json'
9
10
  require 'crack/xml'
10
11
  require 'finest/builder'
11
12
 
13
+ # Ruby::Miradore module
14
+ # The response will be an array of Ruby::Miradore::Device objects with the attributes of the device.
15
+ # Ruby::Miradore::Device object is an open struct so you can access the attributes using the dot notation and any
16
+ # missing method will return +nil+.
17
+ # @example Usage example for Ruby::Miradore::Device
18
+ # device = Ruby::Miradore::Device.new(subdomain: 'testXX', auth: '1xxxxxx')
19
+ # device.all(filter: 'ID eq 37')
12
20
  module Ruby
21
+ # Ruby::Miradore module
22
+ # Miradore has two main API versions, v1 and v2.
23
+ # The v1 version is used to retrieve devices based on filters and the v2 version is used to retrieve a device based on the ID and
24
+ # perform actions on the device.
25
+ # The v1 version works with XML and it's used to perform CRUD operations on users, groups, categories, and devices.
26
+ # The v2 version works with JSON and it's used to perform actions on devices.
27
+ # @see https://www.miradore.com/knowledge/integrations/programmers-guide-to-api-v1/
28
+ # @see https://www.miradore.com/knowledge/integrations/miradore-api-v2/
29
+ # @example Usage example for Ruby::Miradore
30
+ # Ruby::Miradore::Device.new(subdomain: 'subdomain', auth: 'api_token').all(attribute: 'InvDevice.*,InvOS.*,InvStorage.*,Security.*,Location.*,Enrollment.*,User.*')
31
+ #
13
32
  module Miradore
14
33
 
15
34
  mattr_accessor :url, default: {
@@ -34,6 +53,10 @@ module Ruby
34
53
  yield(self)
35
54
  end
36
55
 
56
+ # Ruby::Miradore::Request class
57
+ # This class is the base class for all the requests and implement the CRUD methods towards the API v1 version.
58
+ # The class is using the +HTTParty+ gem to perform the requests and the Finest::Builder gem to transform the XML response into
59
+ # an array of Ruby::Miradore::Request objects.
37
60
  class Request
38
61
  include Finest::Builder
39
62
  include HTTParty
@@ -41,10 +64,13 @@ module Ruby
41
64
 
42
65
  attr_writer :subdomain, :auth, :json
43
66
 
67
+ # @param args [Hash] The arguments to be passed to the API blank hash by default
68
+ # @example Usage example for Ruby::Miradore::Request without arguments, it will use the default values
69
+ # Ruby::Miradore::Request.new.all
44
70
  def initialize(args = {})
45
71
  super args
46
- @subdomain ||= args[:subdomain]
47
- @auth ||= args[:auth]
72
+ @subdomain ||= args.with_indifferent_access[:subdomain]
73
+ @auth ||= args.with_indifferent_access[:auth]
48
74
  @json ||= args.to_json
49
75
  remove_instance_variable(:@subdomain) if @subdomain.nil?
50
76
  remove_instance_variable(:@auth) if @auth.nil?
@@ -55,7 +81,7 @@ module Ruby
55
81
  # The version would be determined based on the superclass name.
56
82
  # If the superclass is Request the GET will call simple_v1 which will require the item which is class name.
57
83
  # otherwise will call to retrieve devices based on filters.
58
- #
84
+ # @param args [Hash] The arguments to be passed to the API
59
85
  def all(args = {})
60
86
  transform(
61
87
  Crack::XML.parse(
@@ -76,12 +102,14 @@ module Ruby
76
102
  @json
77
103
  end
78
104
 
105
+ # Constructs the URL adding parameters to the URL based on the arguments passed and using the API v1 format.
106
+ # Transforms the +body+ argument into XML format.
79
107
  def http_method_v1(args)
80
108
  url = Miradore.url[:v1] % args.merge(
81
109
  subdomain: @subdomain || args[:subdomain],
82
110
  auth: args.fetch(:auth, @auth),
83
111
  id: args.fetch(:id, nil),
84
- item: self.class.to_s.split('::').last,
112
+ item: self.class.name&.demodulize,
85
113
  attribute: args.fetch(:attribute, Miradore.select_attributes),
86
114
  filter: args.fetch(:filter, nil),
87
115
  options: args.fetch(:options, nil)&.to_query&.sub('&', ',')
@@ -100,21 +128,30 @@ module Ruby
100
128
  end
101
129
  self.class.new(args.merge(res.values.first&.transform_keys(&:downcase)))
102
130
  rescue StandardError
103
- { error: "#{self.class.to_s.split('::').last}(s) not found", status: :not_found }
131
+ { error: "#{self.class.name&.demodulize}(s) not found", status: :not_found }
104
132
  end
105
133
 
106
134
  end
107
135
 
136
+ # Ruby::Miradore::Device class
137
+ # This class is used to perform actions on devices using the API v2 version.
138
+ # +Device+ class implements the following methods to perform actions on devices:
139
+ # * lock - Lock the device remotely
140
+ # * lostmode - Activates the lost mode actions on cellphone devices (Android, iOS, WindowsPhone) only.
141
+ # * reboot - Reboot the device remotely, this action depends on the device OS.
142
+ # * wipe - Wipe the device remotely, this action depends on the device OS.
143
+ # * location - Retrieve the device location remotely only on mobile devices.
144
+ #
145
+ # @example Usage example for Ruby::Miradore::Device actions
146
+ # Miradore::Device.new(subdomain: 'subdomain', auth: 'api_token').lock(id: 1)
147
+ # @example Usage example for Ruby::Miradore::Device actions but getting the device first using Request class
148
+ # Miradore::Request.new(subdomain: 'subdomain', auth: 'api_token').call(id: 1).lock
108
149
  class Device < Request
109
150
  include HTTParty
110
151
  format :json
111
152
  headers "Content-Type": 'application/json'
112
153
  headers "Accept": 'application/json'
113
154
 
114
- def initialize(args = {})
115
- super args
116
- end
117
-
118
155
  def lock(args = {})
119
156
  http_method(args.merge(method: :post, id: id, action: __method__))
120
157
  end
@@ -177,6 +214,7 @@ module Ruby
177
214
 
178
215
  private
179
216
 
217
+ # Generates the URL and calls the HTTParty method based on the arguments passed and using the API v2 format.
180
218
  def http_method(args)
181
219
  self.class.headers 'X-API-Key' => @auth || args[:auth]
182
220
  url = Miradore.url[:v2] % {
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: 4.4.3
4
+ version: 4.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduard Garcia Castelló
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-31 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -168,9 +168,6 @@ files:
168
168
  - fixtures/vcr_cassettes/user_alredy_exist_in_miradore.yml
169
169
  - lib/ruby/miradore.rb
170
170
  - lib/ruby/miradore/version.rb
171
- - ruby-miradore-2.0.1.gem
172
- - ruby-miradore-2.0.2.gem
173
- - ruby-miradore-2.1.2.gem
174
171
  - ruby-miradore.gemspec
175
172
  homepage: https://github.com/eddygarcas/ruby-miradore
176
173
  licenses:
Binary file
Binary file
Binary file