Class: Apify::Api

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

Class Method Summary collapse

Class Method Details

.action(method, name, args = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/apify/api.rb', line 5

def action(method, name, args = {}, &block)
  method = method.to_sym
  name = name.to_sym
  if block
    action = Apify::Action.new(method, name, &block)
    indexed_actions[name][method] = action
    actions << action
  else
    action = indexed_actions[name][method] or raise "Unknown API action: #{name}"
    action.respond(args)
  end
end

.actionsObject



34
35
36
# File 'lib/apify/api.rb', line 34

def actions
  @actions ||= []
end

.delete(*args, &block) ⇒ Object



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

def delete(*args, &block)
  action(:delete, *args, &block)
end

.draw_routes(map, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/apify/api.rb', line 42

def draw_routes(map, options = {})
  options[:base_path] ||= 'api'
  options[:controller] ||= 'api'
  indexed_actions.each do |name, methods|
    methods.each do |method, action|
      connect_route(map, name, method, options)
    end
  end
  connect_route(map, 'docs', :get, options)
end

.get(*args, &block) ⇒ Object



18
19
20
# File 'lib/apify/api.rb', line 18

def get(*args, &block)
  action(:get, *args, &block)
end

.indexed_actionsObject



38
39
40
# File 'lib/apify/api.rb', line 38

def indexed_actions
  @indexed_actions ||= Hash.new { |hash, k| hash[k] = {} }
end

.post(*args, &block) ⇒ Object



22
23
24
# File 'lib/apify/api.rb', line 22

def post(*args, &block)
  action(:post, *args, &block)
end

.put(*args, &block) ⇒ Object



26
27
28
# File 'lib/apify/api.rb', line 26

def put(*args, &block)
  action(:put, *args, &block)
end