Class: Spree::Admin::SolidusMe::AccountsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controller/spree/admin/solidus_me/accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#authorizeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 44

def authorize
  code = params[:code]
   = ::SolidusMe::Account.first
  authorize_json = MeApi::Client.new.authorize(
    client_id: .client_id,
    client_secret: .client_secret,
    code: code,
    redirect_url: .redirect_url
  ).json
  .update(
    access_token: authorize_json["access_token"],
    refresh_token: authorize_json["refresh_token"],
    token_expires_in: (DateTime.now + authorize_json["expires_in"].seconds).to_s
  )
  redirect_to  
end

#createObject



19
20
21
22
23
24
25
26
27
28
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 19

def create
   = ::SolidusMe::Account.new 
  if .save
    flash[:success] = "Conta criada com sucesso"
    redirect_to admin_solidus_me_accounts_path
  else
    flash[:error] = .errors.full_messages.join("\n")
    redirect_to 
  end
end

#destroyObject



39
40
41
42
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 39

def destroy
  @me_account.delete
  redirect_to admin_solidus_me_accounts_path
end

#editObject



30
31
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 30

def edit
end

#indexObject



7
8
9
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 7

def index
  @accounts = ::SolidusMe::Account.all
end

#newObject



11
12
13
14
15
16
17
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 11

def new
  if ::SolidusMe::Account.any?
    flash[:error] = "Você só pode ter uma conta Melhor Envio cadastrada"
    redirect_to admin_solidus_me_accounts_path
  end
  @me_account = ::SolidusMe::Account.new
end

#updateObject



33
34
35
36
37
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 33

def update
  @me_account.update 
  flash[:success] = "Conta atualizada com sucesso"
  redirect_to (@me_account.id)
end