Class: Megam::Domains

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

Instance Attribute Summary

Attributes inherited from RestAdapter

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Domains

Returns a new instance of Domains.



3
4
5
6
7
8
9
# File 'lib/megam/core/domains.rb', line 3

def initialize(o)
    @id = nil
    @org_id = nil
    @name = nil
    @created_at = nil
    super(o)
end

Class Method Details

.create(o) ⇒ Object



96
97
98
99
# File 'lib/megam/core/domains.rb', line 96

def self.create(o)
    dom = from_hash(o)
    dom.create
end

.from_hash(o) ⇒ Object



81
82
83
84
85
# File 'lib/megam/core/domains.rb', line 81

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

.json_create(o) ⇒ Object

Create a Megam::Domains from JSON (used by the backgroud job workers)



72
73
74
75
76
77
78
79
# File 'lib/megam/core/domains.rb', line 72

def self.json_create(o)
    dmn = new({})
    dmn.id(o["id"]) if o.has_key?("id")
    dmn.org_id(o["org_id"]) if o.has_key?("org_id")
    dmn.name(o["name"]) if o.has_key?("name")
    dmn.created_at(o["created_at"]) if o.has_key?("created_at")
    dmn
end

.list(o) ⇒ Object



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

def self.list(o)
    dom = from_hash(o)
    dom.megam_rest.get_domains
end

Instance Method Details

#createObject



106
107
108
# File 'lib/megam/core/domains.rb', line 106

def create
    megam_rest.post_domains(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#domainObject



11
12
13
# File 'lib/megam/core/domains.rb', line 11

def domain
    self
end

#for_jsonObject



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

def for_json
    result = {
        "id" => id,
        "org_id" => org_id,
        "name" => name,
        "created_at" => created_at
    }
    result
end

#from_hash(o) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/megam/core/domains.rb', line 88

def from_hash(o)
    @id        = o[:id] if o.has_key?(:id)
    @org_id        = o[:org_id] if o.has_key?(:org_id)
    @name     = o[:name] if o.has_key?(:name)
    @created_at = o[:created_at] if o.has_key?(:created_at)
    self
end

#id(arg = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/megam/core/domains.rb', line 15

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

#name(arg = nil) ⇒ Object



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

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

#org_id(arg = nil) ⇒ Object



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

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

#showObject



110
111
112
# File 'lib/megam/core/domains.rb', line 110

def show
    megam_rest.get_domains(to_hash)
end

#to_hashObject



47
48
49
50
51
52
53
54
55
# File 'lib/megam/core/domains.rb', line 47

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

#to_json(*a) ⇒ Object



57
58
59
# File 'lib/megam/core/domains.rb', line 57

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

#to_sObject



114
115
116
# File 'lib/megam/core/domains.rb', line 114

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