Module: PrestoHTTP::API

Includes:
PrestoCore::Utils, Rack::Utils
Included in:
ClassAPI, InstanceAPI
Defined in:
lib/presto/http.rb,
lib/presto/http/api.rb

Constant Summary

Constant Summary

Constants included from PrestoCore::Utils

PrestoCore::Utils::PATH_MODIFIERS, PrestoCore::Utils::STATUS__NOT_FOUND, PrestoCore::Utils::STATUS__OK, PrestoCore::Utils::STATUS__PERMANENT_REDIRECT, PrestoCore::Utils::STATUS__REDIRECT, PrestoCore::Utils::STATUS__RESTRICTED, PrestoCore::Utils::STATUS__SERVER_ERROR

Instance Method Summary (collapse)

Methods included from PrestoCore::Utils

build_path, #extract_controllers, is_controller?, normalize_path, rootify_url

Instance Method Details

- (Object) authorization_form Also known as: auth_form



72
73
74
# File 'lib/presto/http/api.rb', line 72

def authorization_form
  @authorization_form ||= ::PrestoHTTP::HTMLAuth.authorization_form
end

- (String) build_path(*args)

builds path from given args

Returns:

  • (String)


64
65
66
# File 'lib/presto/http/api.rb', line 64

def build_path *args
  ::PrestoCore::Utils.build_path *args
end

- (String) get(*args, &proc)

performing an internal GET request

Returns:

  • (String)


81
82
83
# File 'lib/presto/http/api.rb', line 81

def get *args, &proc
  ::PrestoCore::Browser.new(@controller, env).body *args, &proc
end

- (String) mime_type(type)

get mime-type by extension

Examples:

http.mime_type '.html'  #=> "text/html"
http.mime_type '.css'   #=> "text/css"
http.mime_type '.js'    #=> "text/js"
http.mime_type '.txt'   #=> "text/plain"

Returns:

  • (String)


57
58
59
# File 'lib/presto/http/api.rb', line 57

def mime_type type
  ::Rack::Mime.mime_type type
end

- (Object) normalize_path(*args)



68
69
70
# File 'lib/presto/http/api.rb', line 68

def normalize_path *args
  ::PrestoCore::Utils.normalize_path *args
end

- (String) post(*args, &proc)

performing an internal POST request

Returns:

  • (String)


88
89
90
# File 'lib/presto/http/api.rb', line 88

def post *args, &proc
  ::PrestoCore::Browser.new(@controller, env, 'POST').body *args, &proc
end

- (String) route(action = nil, *args) Also known as: r

return controller root + action route. any other arguments will be added to path.

Examples:

class SomeController
  include Presto
  http.map '/some-path'

  def index
    http.route #=> /some-path
    http.route(:edit, 1, 2) #=> /some-path/edit/1/2
    http.route(:edit, k: 'v') #=> /some-path/edit/?k=v
    SomeController.http.route #=> /some-path/
    SomeController.http.route(:some_method) #=> /some-path/some_method
  end
end

Parameters:

  • action (Symbol, nil) (defaults to: nil)
  • args (Array)

Returns:

  • (String)


27
28
29
30
31
32
# File 'lib/presto/http/api.rb', line 27

def route action = nil, *args
  if (map = @controller.ctrl.action_map) && (route = map[action])
    return build_path route, *args
  end
  build_path @controller.http.root, action, *args
end

- (String) xhr_get(*args, &proc) Also known as: xhr

performing an internal XMLHttpRequest GET request

Returns:

  • (String)


95
96
97
# File 'lib/presto/http/api.rb', line 95

def xhr_get *args, &proc
  ::PrestoCore::Browser.new(@controller, env, 'GET', true).body *args, &proc
end

- (String) xhr_post(*args, &proc)

performing an internal XMLHttpRequest POST request

Returns:

  • (String)


104
105
106
# File 'lib/presto/http/api.rb', line 104

def xhr_post *args, &proc
  ::PrestoCore::Browser.new(@controller, env, 'POST', true).body *args, &proc
end