Class: Apify::Api

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

Class Method Summary collapse

Class Method Details

.action(method, name, &block) ⇒ Object



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

def action(method, name, &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
    indexed_actions[name][method] or raise "Unknown API action: #{name}"
  end
end

.actionsObject



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

def actions
  @actions ||= []
end

.delete(name, &block) ⇒ Object



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

def delete(name, &block)
  action(:delete, name, &block)
end

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



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

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(name, &block) ⇒ Object



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

def get(name, &block)
  action(:get, name, &block)
end

.indexed_actionsObject



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

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

.post(name, &block) ⇒ Object



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

def post(name, &block)
  action(:post, name, &block)
end

.put(name, &block) ⇒ Object



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

def put(name, &block)
  action(:put, name, &block)
end