class Cradlepoint::Config
In order to apply a configuration to the ECM you can simply call Cradlepoint::Config.update(router), where the router is currently an ActiveRecord object, this will soon merely require a ruby dictionary instead.
When update is called, a few steps must be undergone:
1. We must facilitate a POST to create a configuration_editor with the ECM API. 2. We must then perform a PUT of the configuration data to the configuration_editor. 3. Then we simply DELETE the configuration_editor, the ECM API does the rest.
Attributes
config_editor_id[RW]
config_settings[RW]
data[RW]
id[RW]
router[RW]
Public Class Methods
new(router, config_settings = nil)
click to toggle source
# File lib/cradlepoint/config.rb, line 15 def initialize(router, config_settings = nil) self.router = router self.config_settings = config_settings end
rel_url()
click to toggle source
# File lib/cradlepoint/config.rb, line 20 def self.rel_url '/configuration_editors/' end
rel_url_from_router(router)
click to toggle source
# File lib/cradlepoint/config.rb, line 36 def self.rel_url_from_router(router) "#{ Cradlepoint::Router.rel_url }/#{ router.id }/configuration_manager/" end
rel_url_with_id(id)
click to toggle source
# File lib/cradlepoint/config.rb, line 28 def self.rel_url_with_id(id) "#{ rel_url }#{ id }/" end
Public Instance Methods
apply_config_to_editor()
click to toggle source
# File lib/cradlepoint/config.rb, line 53 def apply_config_to_editor self.data = Cradlepoint.handle_response RestClient.put(build_url(rel_url_with_id), get_config_data_with_wrapper(config_settings).to_json, content_type: :json, accept: :json) end
create_editor()
click to toggle source
# File lib/cradlepoint/config.rb, line 44 def create_editor self.data = Cradlepoint.handle_response RestClient.post(build_url(rel_url), router.get_configuration_editor_data.to_json, content_type: :json, accept: :json) self.id = self.data[:id] self.data end
rel_url()
click to toggle source
# File lib/cradlepoint/config.rb, line 24 def rel_url Cradlepoint::Config.rel_url end
rel_url_from_router()
click to toggle source
# File lib/cradlepoint/config.rb, line 40 def rel_url_from_router Cradlepoint::Config.rel_url_from_router(router) end
rel_url_with_id()
click to toggle source
# File lib/cradlepoint/config.rb, line 32 def rel_url_with_id Cradlepoint::Config.rel_url_with_id(id) end
remove_editor()
click to toggle source
# File lib/cradlepoint/config.rb, line 60 def remove_editor self.data = Cradlepoint.handle_response RestClient.delete(build_url(rel_url_with_id), content_type: :json, accept: :json) end
Private Instance Methods
get_config_data_with_wrapper(config_settings = {})
click to toggle source
# File lib/cradlepoint/config.rb, line 68 def get_config_data_with_wrapper(config_settings = {}) editor_data = router.get_configuration_editor_data editor_data[:resource_uri] = '/api/v1' + rel_url_with_id editor_data[:committed] = true editor_data[:id] = self.id editor_data[:diff_from_baseline] = [wifi_values_wrapper(config_settings), []] editor_data end
wifi_values(config_settings)
click to toggle source
# File lib/cradlepoint/config.rb, line 91 def wifi_values(config_settings) { system: { ui_activated: true }, radius0ip: config_settings[:radius_ip1], radius1ip: config_settings[:radius_ip2], radius0key: config_settings[:shared_secret] || :foobarbaz, ssid: config_settings[:ssid] || '@uceem_ECM' } end
wifi_values_wrapper(config_settings)
click to toggle source
# File lib/cradlepoint/config.rb, line 77 def wifi_values_wrapper(config_settings) { radio: { :'0' => { wlan: { bss: { :'0' => wifi_values(config_settings) } } } } } end