Class: Minecraft::JSONAPIv2::API
- Inherits:
-
Object
- Object
- Minecraft::JSONAPIv2::API
- Defined in:
- lib/minecraft_jsonapiv2/api.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #call(method) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 23 def method_missing(name, *args, &block) if block_given? block.call Minecraft::JSONAPIv2::Namespace.new(self, name.to_s) else response = Minecraft::JSONAPIv2::Response.new( @conn.make_request(name: name.to_s.gsub(/_/, '.'), args: args) ).response[name.to_s] super if (response.nil?) response = Mash.new(response) if response.is_a? Hash or response.is_a? Array response end end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 4 def user @user end |
Instance Method Details
#call(method) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 11 def call(method) response = Minecraft::JSONAPIv2::Response.new( @conn.make_request(method) ).response[method[:name].gsub(/\./, '_')] response = Mash.new(response) if response.is_a? Hash or response.is_a? Array begin unless response.nil? response else raise NoResponseError end end end |