Class: Mutx::API::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/API/input.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Input

Returns a new instance of Input.



7
8
9
10
11
12
13
14
15
# File 'lib/mutx/API/input.rb', line 7

def initialize definition
  Mutx::Support::Log.debug "definition in new => #{definition}"
  id = definition["_id"] || Mutx::Database::MongoConnector.generate_id
  @id       = id
  @reference = definition["reference"] 
  @name     = definition["name"]
  @value    = definition["value"]
  @created_at = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def options
  @options
end

#referenceObject (readonly)

Returns the value of attribute reference.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def reference
  @reference
end

#requiredObject (readonly)

Returns the value of attribute required.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/mutx/API/input.rb', line 5

def value
  @value
end

Class Method Details

.delete(param_id) ⇒ Object



75
76
77
# File 'lib/mutx/API/input.rb', line 75

def self.delete param_id
  Mutx::Database::MongoConnector.delete_custom_param param_id
end

.delete_this(data) ⇒ Object

GET



45
46
47
48
49
50
51
# File 'lib/mutx/API/input.rb', line 45

def self.delete_this data
  if self.delete data["_id"]
    {action:"delete", success:true, message:"Custom Param #{data["name"]} deleted"}
  else
    {action:"delete", success:false, message:"Could not delete custom param #{data["name"]}"}
  end
end

.get_data(id, query_string = nil) ⇒ Object

GET



36
37
38
# File 'lib/mutx/API/input.rb', line 36

def self.get_data id, query_string=nil
  result = self.info id
end

.info(id) ⇒ Object



40
41
42
# File 'lib/mutx/API/input.rb', line 40

def self.info id
  result = Mutx::Database::MongoConnector.input_data_for_id(id)
end

.insert!(definition) ⇒ Object



65
66
67
68
# File 'lib/mutx/API/input.rb', line 65

def self.insert! definition
  #definition.delete("action")
  Mutx::Database::MongoConnector.insert_input(self.new(definition).structure)
end

.update!(definition) ⇒ Object



70
71
72
73
# File 'lib/mutx/API/input.rb', line 70

def self.update! definition
  definition.delete("action")
  Mutx::Database::MongoConnector.update_custom_param(self.new(definition).structure)
end

.validate_and_create(definition) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mutx/API/input.rb', line 27

def self.validate_and_create definition
  if insert!(definition)
    {action:"create", success:true, message:"Input #{definition["name"]} created"}
  else
    {action:"create", success:false, message:"Input #{definition["name"]} could not be created"}
  end
end

.validate_json_format(definition) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/mutx/API/input.rb', line 54

def self.validate_json_format definition
  Mutx::Support::Log.debug "Value is a => #{definition['value'].class} => #{definition["value"]}"
  begin
    value = JSON.parse(definition["value"])
    Mutx::Support::Log.debug "NOW Value is a => #{value.class} => #{value}"
    nil
  rescue
    return "Invalid json format"
  end
end

Instance Method Details

#structureObject



17
18
19
20
21
22
23
24
25
# File 'lib/mutx/API/input.rb', line 17

def structure
  {
    "_id" => id,
    "reference" => reference,
    "name" => name,
    "value" => value,
    "created_at" => created_at
  }
end