Class: Cradlepoint::Config

Inherits:
CradlepointObject show all
Defined in:
lib/cradlepoint/config.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CradlepointObject

build_new_url, #build_new_url, #build_url, build_url, ecm_object_blob?, #ecm_object_blob?, #params, #successful_response?, successful_response?

Constructor Details

#initialize(router, config_settings = nil) ⇒ Config

Returns a new instance of Config.



15
16
17
18
# File 'lib/cradlepoint/config.rb', line 15

def initialize(router, config_settings = nil)
  self.router = router
  self.config_settings = config_settings
end

Instance Attribute Details

#config_editor_idObject

Returns the value of attribute config_editor_id.



13
14
15
# File 'lib/cradlepoint/config.rb', line 13

def config_editor_id
  @config_editor_id
end

#config_settingsObject

Returns the value of attribute config_settings.



13
14
15
# File 'lib/cradlepoint/config.rb', line 13

def config_settings
  @config_settings
end

#dataObject

Returns the value of attribute data.



13
14
15
# File 'lib/cradlepoint/config.rb', line 13

def data
  @data
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/cradlepoint/config.rb', line 13

def id
  @id
end

#routerObject

Returns the value of attribute router.



13
14
15
# File 'lib/cradlepoint/config.rb', line 13

def router
  @router
end

Class Method Details

.rel_urlObject



20
21
22
# File 'lib/cradlepoint/config.rb', line 20

def self.rel_url
  '/configuration_editors/'
end

.rel_url_from_router(router) ⇒ Object



36
37
38
# 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) ⇒ Object



28
29
30
# File 'lib/cradlepoint/config.rb', line 28

def self.rel_url_with_id(id)
  "#{ rel_url }#{ id }/"
end

Instance Method Details

#apply_config_to_editorObject



53
54
55
56
57
58
# 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_editorObject



44
45
46
47
48
49
50
51
# 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_urlObject



24
25
26
# File 'lib/cradlepoint/config.rb', line 24

def rel_url
  Cradlepoint::Config.rel_url
end

#rel_url_from_routerObject



40
41
42
# File 'lib/cradlepoint/config.rb', line 40

def rel_url_from_router
  Cradlepoint::Config.rel_url_from_router(router)
end

#rel_url_with_idObject



32
33
34
# File 'lib/cradlepoint/config.rb', line 32

def rel_url_with_id
  Cradlepoint::Config.rel_url_with_id(id)
end

#remove_editorObject



60
61
62
63
64
# 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