Class: Megam::Assemblies

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/assemblies.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ Assemblies

Returns a new instance of Assemblies.



19
20
21
22
23
24
25
26
27
# File 'lib/megam/core/assemblies.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @accounts_id = nil
  @name = nil
  @assemblies = []
  @inputs = []
  @created_at = nil
  super(email, api_key)
end

Class Method Details

.create(params) ⇒ Object



145
146
147
148
# File 'lib/megam/core/assemblies.rb', line 145

def self.create(params)
  asm = from_hash(params, params["email"] || params[:email], params["api_key"] || params[:api_key])
  asm.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



129
130
131
132
133
# File 'lib/megam/core/assemblies.rb', line 129

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  asm = self.new(tmp_email, tmp_api_key)
  asm.from_hash(o)
  asm
end

.json_create(o) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/megam/core/assemblies.rb', line 118

def self.json_create(o)
  asm = new
  asm.id(o["id"]) if o.has_key?("id")
  asm.name(o["name"]) if o.has_key?("name")
  asm.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
  asm.assemblies(o["assemblies"]) if o.has_key?("assemblies") #this will be an array? can hash store array?
  asm.inputs(o["inputs"]) if o.has_key?("inputs")     
  asm.created_at(o["created_at"]) if o.has_key?("created_at")
  asm
end

.list(params) ⇒ Object



161
162
163
164
# File 'lib/megam/core/assemblies.rb', line 161

def self.list(params)
  asm = self.new(params["email"], params["api_key"])
  asm.megam_rest.get_assemblies
end

.show(one_assemblies_id, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Load a account by email_p



156
157
158
159
# File 'lib/megam/core/assemblies.rb', line 156

def self.show(one_assemblies_id, tmp_email=nil, tmp_api_key=nil)
  asm = self.new(tmp_email, tmp_api_key)
  asm.megam_rest.get_one_assemblies(one_assemblies_id)
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/megam/core/assemblies.rb', line 42

def accounts_id(arg=nil)
  if arg != nil
    @accounts_id = arg
  else
  @accounts_id
  end
end

#assemblies(arg = []) ⇒ Object



29
30
31
# File 'lib/megam/core/assemblies.rb', line 29

def assemblies
  self
end

#createObject

Create the node via the REST API



151
152
153
# File 'lib/megam/core/assemblies.rb', line 151

def create
  megam_rest.post_assemblies(to_hash)
end

#created_at(arg = nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/megam/core/assemblies.rb', line 75

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/megam/core/assemblies.rb', line 83

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/megam/core/assemblies.rb', line 106

def for_json
  result = {
    "id" => id,
    "name" => name,
    "accounts_id" => accounts_id,
    "assemblies" => assemblies,
    "inputs" => inputs,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'lib/megam/core/assemblies.rb', line 135

def from_hash(o)
  @id                = o["id"] if o.has_key?("id")
  @name              = o["name"] if o.has_key?("name")
  @accounts_id       = o["accounts_id"] if o.has_key?("accounts_id")
  @assemblies        = o["assemblies"] if o.has_key?("assemblies")
  @inputs             = o["inputs"] if o.has_key?("inputs")
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/megam/core/assemblies.rb', line 34

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#inputs(arg = []) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/megam/core/assemblies.rb', line 67

def inputs(arg=[])
  if arg != []
    @inputs = arg
  else
  @inputs
  end
end

#name(arg = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/megam/core/assemblies.rb', line 50

def name(arg=nil)
  if arg != nil
    @name = arg
  else
  @name
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/megam/core/assemblies.rb', line 88

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["accounts_id"] = accounts_id
  index_hash["inputs"] = inputs
  index_hash["assemblies"] = assemblies
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



102
103
104
# File 'lib/megam/core/assemblies.rb', line 102

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



166
167
168
# File 'lib/megam/core/assemblies.rb', line 166

def to_s
  Megam::Stuff.styled_hash(to_hash)
end