Module: Glib::Json::Libs

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/glib/json/libs.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#glib_force_json_uiObject



43
44
45
46
47
# File 'app/controllers/concerns/glib/json/libs.rb', line 43

def glib_force_json_ui
  if params[:_render] != 'v1'
    redirect_to url_for(params.to_unsafe_h.merge(_render: 'v1'))
  end
end

#glib_json_handle_403Object



49
50
51
# File 'app/controllers/concerns/glib/json/libs.rb', line 49

def glib_json_handle_403
  render file: Rails.root.join('public', '404.html'), status: :forbidden
end

#glib_json_handle_404Object

Raises:

  • (ActionController::RoutingError)


53
54
55
56
57
58
59
60
61
# File 'app/controllers/concerns/glib/json/libs.rb', line 53

def glib_json_handle_404
  raise ActionController::RoutingError.new('Not Found')

  # if json_ui_activated?
  #   render file: Rails.root.join('public', '404.html'), status: :not_found
  # else
  #   raise exception
  # end
end

#glib_json_handle_500(exception) ⇒ Object



63
64
65
66
67
68
69
70
# File 'app/controllers/concerns/glib/json/libs.rb', line 63

def glib_json_handle_500(exception)
  if json_ui_activated? && Rails.env.production?
    Rollbar.error(exception, :use_exception_level_filters => true) if defined?(Rollbar)
    render file: Rails.root.join('public', '500.html'), status: :internal_server_error
  else
    raise exception
  end
end

#glib_json_redirect_to(url) ⇒ Object



72
73
74
75
76
# File 'app/controllers/concerns/glib/json/libs.rb', line 72

def glib_json_redirect_to(url)
  render json: {
    onResponse: { action: 'dialogs/close', onClose: { action: 'windows/open', url: url } }
  }
end

#json_ui_app_build_versionObject



15
16
17
18
19
# File 'app/controllers/concerns/glib/json/libs.rb', line 15

def json_ui_app_build_version
  @json_ui_app_build_version ||= request.headers['GApp-Build-Version'] || request.headers['JsonUiApp-Build-Version']
  @json_ui_app_build_version = params[:build_version] if @json_ui_app_build_version.nil? && Rails.env.development?  # For easy testing
  @json_ui_app_build_version
end

#json_ui_app_bundle_idObject



11
12
13
# File 'app/controllers/concerns/glib/json/libs.rb', line 11

def json_ui_app_bundle_id
  @json_ui_app_bundle_id ||= request.headers['GApp-Bundle-Id'] || request.headers['JsonUiApp-Bundle-Id']
end

#json_ui_app_device_osObject



21
22
23
24
25
# File 'app/controllers/concerns/glib/json/libs.rb', line 21

def json_ui_app_device_os
  @json_ui_app_device_os ||= request.headers['GApp-Device-Os'] || request.headers['JsonUiApp-Device-Os']
  @json_ui_app_device_os = params[:device_os] if @json_ui_app_device_os.nil? && Rails.env.development?  # For easy testing
  @json_ui_app_device_os || 'web'
end

#json_ui_app_is_android?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/controllers/concerns/glib/json/libs.rb', line 27

def json_ui_app_is_android?
  json_ui_app_device_os == 'android'
end

#json_ui_app_is_ios?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/controllers/concerns/glib/json/libs.rb', line 31

def json_ui_app_is_ios?
  json_ui_app_device_os == 'ios'
end

#json_ui_app_is_web?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/controllers/concerns/glib/json/libs.rb', line 35

def json_ui_app_is_web?
  json_ui_app_device_os == 'web'
end

#json_ui_render(template, args = {}) ⇒ Object



39
40
41
# File 'app/controllers/concerns/glib/json/libs.rb', line 39

def json_ui_render(template, args = {})
  JSON.parse(render_to_string(template, locals: args))
end