Class: Megam::Quotas

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/quotas.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Quotas

Returns a new instance of Quotas.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/megam/core/quotas.rb', line 3

def initialize(o)
    @id = nil
    @account_id = nil
    @name = nil
    @cost = nil
    @allowed = nil
    @allocated_to = nil
    @quota_type = nil
    @status = nil
    @inputs = []
    @created_at = nil
    @updated_at = nil
    super(o)
end

Class Method Details

.create(params) ⇒ Object



197
198
199
200
# File 'lib/megam/core/quotas.rb', line 197

def self.create(params)
    quo = from_hash(params)
    quo.create
end

.from_hash(o) ⇒ Object



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

def self.from_hash(o)
    quo = new(o)
    quo.from_hash(o)
    quo
end

.json_create(o) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/megam/core/quotas.rb', line 146

def self.json_create(o)
    quo = new({})
    quo.id(o['id']) if o.key?('id')
    quo.(o["account_id"]) if o.has_key?("account_id")
    quo.name(o['name']) if o.key?('name')
    quo.allowed(o['allowed']) if o.key?('allowed')
    quo.allocated_to(o['allocated_to']) if o.key?('allocated_to') # this will be an array? can hash store array?
    quo.inputs(o['inputs']) if o.key?('inputs')
    quo.quota_type(o['quota_type']) if o.key?('quota_type')
    quo.status(o['status']) if o.key?('status')
    quo.created_at(o['created_at']) if o.key?('created_at')
    quo.updated_at(o['updated_at']) if o.key?('updated_at')
    quo
end

.list(params) ⇒ Object



192
193
194
195
# File 'lib/megam/core/quotas.rb', line 192

def self.list(params)
    quo = self.new(params)
    quo.megam_rest.list_quotas
end

.show(params) ⇒ Object



182
183
184
185
# File 'lib/megam/core/quotas.rb', line 182

def self.show(params)
    quo = new(params)
    quo.megam_rest.get_one_quota(params['id'])
end

.update(params) ⇒ Object



187
188
189
190
# File 'lib/megam/core/quotas.rb', line 187

def self.update(params)
    quo = from_hash(params)
    quo.update
end

Instance Method Details

#account_id(arg = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/megam/core/quotas.rb', line 30

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

#allocated_to(arg = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/megam/core/quotas.rb', line 54

def allocated_to(arg = nil)
    if !arg.nil?
        @allocated_to = arg
    else
        @allocated_to
    end
end

#allowed(arg = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/megam/core/quotas.rb', line 46

def allowed(arg = nil)
    if !arg.nil?
        @allowed = arg
    else
        @allowed
    end
end

#createObject



202
203
204
# File 'lib/megam/core/quotas.rb', line 202

def create
    megam_rest.post_quotas(to_hash)
end

#created_at(arg = nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/megam/core/quotas.rb', line 86

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

#error?Boolean

Returns:

  • (Boolean)


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

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

#for_jsonObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/megam/core/quotas.rb', line 129

def for_json
    result = {
        'id' => id,
        'account_id' => ,
        'name' => name,
        'allowed' => allowed,
        'allocated_to' => allocated_to,
        'inputs' => inputs,
        'quota_type' => quota_type,
        'status' => status,
        'created_at' => created_at,
        'updated_at' => updated_at
    }

    result
end

#from_hash(o) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/megam/core/quotas.rb', line 167

def from_hash(o)
    @id                = o['id'] if o.key?('id')
    @account_id        = o["account_id"] if o.has_key?("account_id")
    @name              = o['name'] if o.key?('name')
    @allowed           = o['allowed'] if o.key?('allowed')
    @allocated_to      = o['allocated_to'] if o.key?('allocated_to')
    @inputs            = o['inputs'] if o.key?('inputs')
    @quota_type        = o['quota_type'] if o.key?('quota_type')
    @status            = o['status'] if o.key?('status')
    @created_at        = o['created_at'] if o.key?('created_at')
    @updated_at        = o['updated_at'] if o.key?('updated_at')
    self
end

#id(arg = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/megam/core/quotas.rb', line 22

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

#inputs(arg = []) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/megam/core/quotas.rb', line 62

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

#name(arg = nil) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/megam/core/quotas.rb', line 38

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

#quota_type(arg = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/megam/core/quotas.rb', line 70

def quota_type(arg = nil)
    if !arg.nil?
        @quota_type = arg
    else
        @quota_type
    end
end

#quotasObject



18
19
20
# File 'lib/megam/core/quotas.rb', line 18

def quotas
    self
end

#status(arg = nil) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/megam/core/quotas.rb', line 78

def status(arg = nil)
    if !arg.nil?
        @status = arg
    else
        @status
    end
end

#to_hashObject

Transform the ruby obj -> to a Hash



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/megam/core/quotas.rb', line 107

def to_hash
    index_hash = {}
    index_hash['json_claz'] = self.class.name
    index_hash['id'] = id
    index_hash["account_id"] = 
    index_hash['name'] = name
    index_hash['allowed'] = allowed
    index_hash['allocated_to'] = allocated_to
    index_hash['quota_type'] = quota_type
    index_hash['status'] = status
    index_hash['inputs'] = inputs
    index_hash['created_at'] = created_at
    index_hash['updated_at'] = updated_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.



125
126
127
# File 'lib/megam/core/quotas.rb', line 125

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

#to_sObject



211
212
213
# File 'lib/megam/core/quotas.rb', line 211

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

#updateObject

Create the node via the REST API



207
208
209
# File 'lib/megam/core/quotas.rb', line 207

def update
    megam_rest.update_quotas(to_hash)
end

#updated_at(arg = nil) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/megam/core/quotas.rb', line 94

def updated_at(arg = nil)
 if !arg.nil?
  @updated_at = arg
 else
  @updated_at
 end
end