Class: EasyApiDoc::Action

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
app/models/easy_api_doc/action.rb

Instance Method Summary collapse

Methods included from Configurable

#[], #[]=, #defaults, included, #inherited_overridable, #initialize, #load_children

Instance Method Details

#authenticationObject



50
51
52
# File 'app/models/easy_api_doc/action.rb', line 50

def authentication
  @authentication ||= inherited_overridable('authentication', :from => ['resource', 'namespace', 'apiversion'])
end

#formatsObject



45
46
47
48
# File 'app/models/easy_api_doc/action.rb', line 45

def formats
  v = inherited_overridable('formats', :from => ['resource', 'namespace'])
  v.split(/\,\s/) if v
end

#hostObject



36
37
38
39
40
41
42
43
# File 'app/models/easy_api_doc/action.rb', line 36

def host
  v = @parents['apiversion']
  if v && v.attributes['defaults']
    v.attributes['defaults']['domain']
  else
    nil
  end
end

#optionsObject



54
55
56
# File 'app/models/easy_api_doc/action.rb', line 54

def options
  @attributes['options']
end

#parametersObject

def run(params, method, format)

uri = URI(path + "." + format)
res = Net::HTTP.send(method.downcase, uri) # TODO works with get only
# {:body => res.body, :status => res.status}
res

end



23
24
25
# File 'app/models/easy_api_doc/action.rb', line 23

def parameters
  @parameters ||= load_children(EasyApiDoc::Parameter, 'parameters')
end

#pathObject



7
8
9
10
11
12
13
14
# File 'app/models/easy_api_doc/action.rb', line 7

def path
  uri = attributes['uri']
  if host
    "#{protocol}://#{host}#{uri}"
  else
    uri
  end
end

#post_dataObject



27
28
29
# File 'app/models/easy_api_doc/action.rb', line 27

def post_data
  attributes['post_data']
end

#protocolObject



31
32
33
34
# File 'app/models/easy_api_doc/action.rb', line 31

def protocol
  v = @parents['apiversion']
  v.attributes['defaults']['protocol'] || 'http'
end