Class: Spree::Admin::AnalyticsController

Inherits:
Admin::BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/analytics_controller.rb

Instance Method Summary collapse

Instance Method Details

#registerObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/spree/admin/analytics_controller.rb', line 4

def register
  redirect_if_registered and return

  begin
    store = Spree::Dash::Jirafe.register(store_hash)
    Spree::Dash::Config.app_id = store[:app_id]
    Spree::Dash::Config.app_token = store[:app_token]
    Spree::Dash::Config.site_id = store[:site_id]
    Spree::Dash::Config.token = store[:site_token]
    Spree::Dash::Config.jirafe_available = true
    redirect_to admin_path

  rescue Spree::Dash::JirafeUnavailable => e
    session[:jirafe_unavailable_since] = Time.now.to_i
    flash[:error] = e.message
    Spree::Dash::Config.jirafe_available = false
    redirect_to spree.admin_path
  rescue Spree::Dash::JirafeException => e
    flash[:error] = e.message
    redirect_to root_path
  end
end

#syncObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/spree/admin/analytics_controller.rb', line 27

def sync
  session[:last_jirafe_sync] = DateTime.now
  begin
    store = Spree::Dash::Jirafe.synchronize_resources(store_hash)
  rescue SocketError
    flash[:error] = Spree.t(:could_not_connect_to_jirafe)
  rescue Spree::Dash::JirafeException => e
    flash[:error] = e.message
  ensure
    redirect_to admin_path
  end
end

#updateObject



40
41
42
43
44
45
46
47
# File 'app/controllers/spree/admin/analytics_controller.rb', line 40

def update
  Spree::Dash::Config.app_id = params[:app_id]
  Spree::Dash::Config.app_token = params[:app_token]
  Spree::Dash::Config.site_id = params[:site_id]
  Spree::Dash::Config.token = params[:token]
  flash[:success] = Spree.t(:jirafe_settings_updated, :scope => "dash")
  redirect_to admin_analytics_path
end