class Magellan::Cli::Messaging::Base
Constants
- DEFAULT_MAGELLAN_HTTP_SERVER_URL
- DEFAULT_MAGELLAN_MQTT_SERVER_HOST
- DEFAULT_MAGELLAN_MQTT_SERVER_PORT
Public Instance Methods
build_core()
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 33 def build_core proj = find(Resources::Project) client_version = load_selection!(Resources::ClientVersion.parameter_name)["version"] options = { consumer_key: proj["consumer_key"], consumer_secret: proj["consumer_secret"], client_version: client_version, mqtt_host: ENV["MAGELLAN_MQTT_SERVER_HOST"] || DEFAULT_MAGELLAN_MQTT_SERVER_HOST, mqtt_port: ENV["MAGELLAN_MQTT_SERVER_PORT"] || DEFAULT_MAGELLAN_MQTT_SERVER_PORT, verbose: verbose?, } uri = ENV["MAGELLAN_HTTP_SERVER_URL"] || DEFAULT_MAGELLAN_HTTP_SERVER_URL log_verbose("HTTP URL : #{uri.inspect}") log_verbose("HTTP options: #{options.inspect}") Libmagellan::Core.new(uri, options) end
core()
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 14 def core @core ||= build_core end
find(klass, id = nil)
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 24 def find(klass, id = nil) id ||= load_selection!(klass.parameter_name)["id"] r = get_json("/admin/#{klass.resource_key}/#{id}.json") end
load_selection!(name, &block)
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 20 def load_selection!(name, &block) return http_access{ load_selection(name, &block) } end
try_reading_file(value)
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 50 def try_reading_file(value) return nil if value.nil? if File.readable?(value) return File.read(value) else return value end end
try_reading_hash(value)
click to toggle source
# File lib/magellan/cli/messaging/base.rb, line 59 def try_reading_hash(value) return nil if value.nil? obj = if File.readable?(value) case File.extname(value) when ".json" then JSON.parse(File.read(value)) when ".yml" then YAML.load_file(value) else raise "Unsupported file type: #{value.inspect}, .json and .yml are supported." end else JSON.parse(value) end raise "#{value.inspect} contains #{obj.class.name} but it must be a Hash" unless obj.is_a?(Hash) return obj end