class Ruby::Miradore::Request
Attributes
auth[W]
subdomain[W]
Public Class Methods
all(**args)
click to toggle source
This call will perform all GET calls regardless the API version that it's calling. The version would be determined based on the superclass name. If the superclass is Request
the GET will call simple_v1 which will require the item which is class name. otherwise will call to retrieve devices based on filters.
# File lib/ruby/miradore.rb, line 41 def self.all(**args) response = JSON.parse( Crack::XML.parse( get( Miradore.url[version] % args.merge( item: object_name, attribute: args.fetch(:attribute, "*"), auth: args.fetch(:auth, nil), filter: args.fetch(:filter, nil) ) ).body ).to_json, quirks_mode: true ).dig("Content", "Items") transform(response, args) rescue StandardError => e MiradoreError.new({ error: e&.message || "Error connecting to manager service provider", status: :not_found }) end
new(json = {})
click to toggle source
Calls superclass method
# File lib/ruby/miradore.rb, line 27 def initialize(json = {}) super json @subdomain ||= json[:subdomain] @auth ||= json[:auth] remove_instance_variable(:@subdomain) if @subdomain.nil? remove_instance_variable(:@auth) if @auth.nil? end
Private Class Methods
object_name()
click to toggle source
# File lib/ruby/miradore.rb, line 80 def object_name to_s.split("::").last end
transform(res, args = {})
click to toggle source
# File lib/ruby/miradore.rb, line 63 def transform(res, args = {}) instance_name = "Ruby::Miradore::#{res.keys.first.capitalize}" if res.values.first.is_a?(Array) return res.values.first.map! do |e| Object.const_get(instance_name).new(args.merge(e.transform_keys(&:downcase))) end end Object.const_get(instance_name).new(args.merge(res.values.first&.transform_keys(&:downcase))) rescue StandardError MiradoreError.new({ error: "#{object_name}(s) not found", status: :not_found }) end
version()
click to toggle source
# File lib/ruby/miradore.rb, line 76 def version superclass == Object ? :request_v1 : :item_v1 end