Class: MailRU::API::DSL

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

Instance Method Summary collapse

Constructor Details

#initialize(api, group, &block) ⇒ DSL

Returns a new instance of DSL.



6
7
8
9
10
11
12
# File 'lib/mailru-api/dsl.rb', line 6

def initialize api, group,  &block
  @api = api
  @group = group
  if block_given?
    instance_eval(&block)
  end
end

Instance Method Details

#api(name, method = :get, secure = Request::Secure::Any) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/mailru-api/dsl.rb', line 14

def api name, method = :get, secure = Request::Secure::Any
  self.class.send(:define_method, underscore(name)) do |params = {}|
    return GetRequest.new(@api, "#{@group}.#{name}", params, secure).get if method == :get
    return PostRequest.new(@api, "#{@group}.#{name}", params, secure).post if method == :post
    raise Error.create(0, 'HTTP method must be GET or POST!')
  end
end