Class: Minecraft::JSONAPIv2::API

Inherits:
Object
  • Object
show all
Defined in:
lib/minecraft_jsonapiv2/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



6
7
8
9
# File 'lib/minecraft_jsonapiv2/api.rb', line 6

def initialize(options={})
    @user= options[:user]
    @conn = Minecraft::JSONAPIv2::Request.new(options)
end

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

#userObject (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