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
- #get_response_for(request) ⇒ 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
28 29 30 31 32 33 34 35 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 28 def method_missing(name, *args, &block) if block_given? block.call Minecraft::JSONAPIv2::Namespace.new(self, name.to_s) else request = Minecraft::JSONAPIv2::Response.new( @conn.make_request(name: name.to_s.gsub(/_/, '.'), args: args) ) get_response_for request 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 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 11 def call(method) request = Minecraft::JSONAPIv2::Response.new( @conn.make_request(method) ) get_response_for request end |
#get_response_for(request) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 16 def get_response_for(request) response = request.response begin unless response.nil? response else raise NoResponseError end end end |