Class: ZeusSdk::V1::ApiResponse
- Inherits:
-
Object
- Object
- ZeusSdk::V1::ApiResponse
- Defined in:
- lib/zeus_sdk/v1/models/api_response.rb
Instance Attribute Summary collapse
-
#num_pages ⇒ Object
Returns the value of attribute num_pages.
-
#page ⇒ Object
Returns the value of attribute page.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#success ⇒ Object
Returns the value of attribute success.
-
#total ⇒ Object
Returns the value of attribute total.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(raw) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
- #object ⇒ Object
- #objects ⇒ Object
- #to_json(options = {}) ⇒ Object
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_pages ⇒ Object
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 |
#page ⇒ Object
Returns the value of attribute page.
3 4 5 |
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3 def page @page end |
#raw ⇒ Object
Returns the value of attribute raw.
3 4 5 |
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3 def raw @raw end |
#success ⇒ Object
Returns the value of attribute success.
3 4 5 |
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3 def success @success end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/zeus_sdk/v1/models/api_response.rb', line 3 def total @total end |
#type ⇒ Object
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(={}) self.raw end |
#object ⇒ Object
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 |
#objects ⇒ Object
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(={}) self.as_json().to_json end |