Class: E621::API

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

Instance Method Summary collapse

Constructor Details

#initialize(user = nil, pass = nil) ⇒ API

Returns a new instance of API.



24
25
26
27
# File 'lib/api.rb', line 24

def initialize(user=nil,pass=nil)
  @http   = HTTP.new
  (user,pass) if !defined? @@login
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Send commands to API and parse all answers, even errors. Also make it work with POST and GET requests.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/api.rb', line 34

def method_missing(method,*args)
  request = request2body(args.first)
  method = method.to_s.split("_")
  m = case method[0]
      when "post" then
        case method[1]
        when "show" then :get
        else :post
        end
      else :post
      end
  @http.__send__(m,"/#{method.join("/")}.json",request)
end

Instance Method Details

#post_list(*args) ⇒ Object

A wrapper function to fit into the general theme better.



29
30
31
# File 'lib/api.rb', line 29

def post_list(*args)
  post_index(*args)
end