Class: ZeusSdk::V1::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/zeus_sdk/v1/models/api_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ ApiResponse

Returns a new instance of ApiResponse.



5
6
7
8
9
10
11
12
13
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 5

def initialize(raw)
    return if raw.blank?
    self.raw = raw
    self.success = raw["success"] if raw.has_key?("success")
    self.num_pages = raw["num_pages"] if raw.has_key?("num_pages")
    self.total = raw["total"] if raw.has_key?("total")
    self.page = raw["page"] if raw.has_key?("page")
    self.type = raw["type"] if raw.has_key?("type")
end

Instance Attribute Details

#num_pagesObject

Returns the value of attribute num_pages.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def num_pages
  @num_pages
end

#pageObject

Returns the value of attribute page.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def page
  @page
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def raw
  @raw
end

#successObject

Returns the value of attribute success.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def success
  @success
end

#totalObject

Returns the value of attribute total.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def total
  @total
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3

def type
  @type
end

Instance Method Details

#as_json(options = {}) ⇒ Object



47
48
49
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 47

def as_json(options={})
    self.raw
end

#objectObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 31

def object
    obj = self.raw["object"]
    return nil if obj.blank?
    case self.type
    when "Zeus::Auth::User" then User.new(obj)
    when "Zeus::Auth::Permission" then Permission.new(obj)
    when "Zeus::Auth::Role" then Role.new(obj)
    when "Zeus::Auth::RoleUser" then RoleUser.new(obj)
    when "Zeus::Auth::WaitingList" then WaitingList.new(obj)
    when "Zeus::Auth::WaitingListEmail" then WaitingListEmail.new(obj)
    when "Zeus::Assets::Image" then Image.new(obj)
    when "Zeus::Multiplayer::Document" then Document.new(obj)
    when "Zeus::Multiplayer::Node" then Node.new(obj)
    end
end

#objectsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 15

def objects
    objs = self.raw["objects"]
    return [] if objs.blank?
    case self.type
    when "Zeus::Auth::User" then objs.map {|obj| User.new(obj) }
    when "Zeus::Auth::Permission" then objs.map {|obj| Permission.new(obj) }
    when "Zeus::Auth::Role" then objs.map {|obj| Role.new(obj) }
    when "Zeus::Auth::RoleUser" then objs.map {|obj| RoleUser.new(obj) }
    when "Zeus::Auth::WaitingList" then objs.map {|obj| WaitingList.new(obj) }
    when "Zeus::Auth::WaitingListEmail" then objs.map {|obj| WaitingListEmail.new(obj) }
    when "Zeus::Assets::Image" then objs.map {|obj| Image.new(obj) }
    when "Zeus::Multiplayer::Document" then objs.map {|obj| Document.new(obj) }
    when "Zeus::Multiplayer::Node" then objs.map {|obj| Node.new(obj) }
    end
end

#to_json(options = {}) ⇒ Object



51
52
53
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 51

def to_json(options={})
    self.as_json(options).to_json
end