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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 29 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] response = Mash.new(response) if response.is_a? Hash begin unless response.nil? response else raise NoResponseError end end 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 22 23 24 25 26 27 |
# File 'lib/minecraft_jsonapiv2/api.rb', line 11 def call(method) if method.is_a? Array method.each { |m| call m } else if method.is_a? Hash response = Minecraft::JSONAPIv2::Response.new( @conn.make_request(method) ).response[method[:name].gsub(/\./, '_')] response = Mash.new(response) if response.is_a? Hash end end begin unless response.nil? response else raise NoResponseError end end end |