Class: Aphro::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
# File 'lib/client/aphro.rb', line 13

def initialize site
  @base_uri = site

  get @base_uri
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/client/aphro.rb', line 23

def method_missing action, *args, &block
  raise Aphro::ActionNotFound unless actions.include? action

  if get_actions.include? action
    get action, *args
  elsif post_actions.include? action
    post action, *args
  end
end

Instance Method Details

#actionsObject



19
20
21
# File 'lib/client/aphro.rb', line 19

def actions
  get_actions.merge post_actions
end

#attributes_for(action) ⇒ Object



33
34
35
36
37
38
# File 'lib/client/aphro.rb', line 33

def attributes_for action
  unless post_actions.keys.include? action
    raise Aphro::ActionNotFound.new("Action #{action} not found at: #{page}")
  end
  form(action).fields.map &:name
end