Class: FlexibleApiServer::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/flexible_api_server.rb

Constant Summary collapse

FILTERED_COLUMNS =
[:password, :password_confirmation]
ALLOWED_FORMATS =
[:js, :xml, :jsonp]

Instance Method Summary collapse

Instance Method Details

#assign(k, v) ⇒ Object



41
42
43
44
45
# File 'lib/flexible_api_server.rb', line 41

def assign(k, v)
  @assign ||= {}
  @assign[k] = v
  nil
end

#free_render(code, hash = '') ⇒ Object

blank by default, not nil



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/flexible_api_server.rb', line 47

def free_render(code, hash = '') # blank by default, not nil
  status code
  # Filter some things out
  FILTERED_COLUMNS.each do |column|
    hash[column] = '[filtered]' if hash.has_key?(column)
  end if hash.is_a?(Hash)
  # and respond
  charset 'utf-8'
  format :js unless ALLOWED_FORMATS.include? format
  respond_to do |wants|
    wants.jsonp do
      (params[:callback] || 'callback') + "(#{hash.to_json});"
    end
    wants.js do
      hash.to_json
    end
    wants.xml do
      hash.to_xml
    end
  end
end