Class: Megam::Organizations
- Inherits:
-
ServerAPI
- Object
- ServerAPI
- Megam::Organizations
- Defined in:
- lib/megam/core/organizations.rb
Class Method Summary collapse
- .create(o) ⇒ Object
- .from_hash(o) ⇒ Object
-
.json_create(o) ⇒ Object
Create a Megam::Organization from JSON (used by the backgroud job workers).
- .list(o) ⇒ Object
-
.show(o) ⇒ Object
Load a organization by email_p.
- .update(o) ⇒ Object
Instance Method Summary collapse
- #accounts_id(arg = nil) ⇒ Object
- #create ⇒ Object
- #created_at(arg = nil) ⇒ Object
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(o) ⇒ Organizations
constructor
A new instance of Organizations.
- #name(arg = nil) ⇒ Object
- #organization ⇒ Object
- #related_orgs(arg = []) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
-
#update ⇒ Object
Create the node via the REST API.
Constructor Details
#initialize(o) ⇒ Organizations
Returns a new instance of Organizations.
19 20 21 22 23 24 25 26 |
# File 'lib/megam/core/organizations.rb', line 19 def initialize(o) @id = nil @name = nil @accounts_id = nil = [] @created_at = nil super(o) end |
Class Method Details
.create(o) ⇒ Object
125 126 127 128 |
# File 'lib/megam/core/organizations.rb', line 125 def self.create(o) org = from_hash(o) org.create end |
.from_hash(o) ⇒ Object
110 111 112 113 114 |
# File 'lib/megam/core/organizations.rb', line 110 def self.from_hash(o) org = self.new(o) org.from_hash(o) org end |
.json_create(o) ⇒ Object
Create a Megam::Organization from JSON (used by the backgroud job workers)
100 101 102 103 104 105 106 107 108 |
# File 'lib/megam/core/organizations.rb', line 100 def self.json_create(o) org = new({}) org.id(o["id"]) if o.has_key?("id") org.name(o["name"]) if o.has_key?("name") org.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id") org.(o["related_orgs"]) if o.has_key?("related_orgs") org.created_at(o["created_at"]) if o.has_key?("created_at") org end |
.list(o) ⇒ Object
146 147 148 149 |
# File 'lib/megam/core/organizations.rb', line 146 def self.list(o) org = from_hash(o) org.megam_rest.get_organizations end |
.show(o) ⇒ Object
Load a organization by email_p
131 132 133 134 |
# File 'lib/megam/core/organizations.rb', line 131 def self.show(o) org = from_hash(o) org.megam_rest.get_organizations(email) end |
.update(o) ⇒ Object
136 137 138 139 |
# File 'lib/megam/core/organizations.rb', line 136 def self.update(o) org = from_hash(o) org.update end |
Instance Method Details
#accounts_id(arg = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/megam/core/organizations.rb', line 40 def accounts_id(arg=nil) if arg != nil @accounts_id = arg else @accounts_id end end |
#create ⇒ Object
151 152 153 |
# File 'lib/megam/core/organizations.rb', line 151 def create megam_rest.post_organization(to_hash) end |
#created_at(arg = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/megam/core/organizations.rb', line 64 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#for_json ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/megam/core/organizations.rb', line 88 def for_json result = { "id" => id, "name" => name, "accounts_id" => accounts_id, "related_orgs" => , "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/megam/core/organizations.rb', line 116 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) = o[:related_orgs] if o.has_key?(:related_orgs) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/megam/core/organizations.rb', line 32 def id(arg=nil) if arg != nil @id = arg else @id end end |
#name(arg = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/megam/core/organizations.rb', line 48 def name(arg=nil) if arg != nil @name = arg else @name end end |
#organization ⇒ Object
28 29 30 |
# File 'lib/megam/core/organizations.rb', line 28 def organization self end |
#related_orgs(arg = []) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/megam/core/organizations.rb', line 56 def (arg=[]) if arg != [] = arg else end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/megam/core/organizations.rb', line 73 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["related_orgs"] = index_hash["created_at"] = created_at index_hash end |
#to_json(*a) ⇒ Object
84 85 86 |
# File 'lib/megam/core/organizations.rb', line 84 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
155 156 157 |
# File 'lib/megam/core/organizations.rb', line 155 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
Create the node via the REST API
142 143 144 |
# File 'lib/megam/core/organizations.rb', line 142 def update megam_rest.update_organization(to_hash) end |