Skip to content

Commit

Permalink
Fixed session storage
Browse files Browse the repository at this point in the history
  • Loading branch information
CognitiveDisson committed Feb 20, 2018
1 parent f740a91 commit 5b2ee87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 9 additions & 6 deletions lib/fabricio/authorization/file_param_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require 'yaml'

# Constants
FABRICIO_DIRECTORY_PATH = "#{Dir.home}/.fabricio"
PARAM_FILE_PATH = "#{CREDENTIAL_DIRECTORY_PATH}/.params"
PARAM_FILE_PATH = "#{FABRICIO_DIRECTORY_PATH}/.params"

module Fabricio
module Authorization
Expand All @@ -16,7 +15,9 @@ class FileParamStorage < AbstractParamStorage
# @return [Hash]
def obtain
return nil unless File.exist?(PARAM_FILE_PATH)
return YAML.load_file(PARAM_FILE_PATH) || {}
params = YAML.load_file(PARAM_FILE_PATH)
return {} unless params
return params
end

# Save variable
Expand All @@ -32,11 +33,13 @@ def reset_all
end

def organization_id
obtain['organization_id']
hash = obtain || {}
hash['organization_id']
end

def app_id
obtain['app_id']
hash = obtain || {}
hash['app_id']
end

def store_organization_id(organization_id)
Expand All @@ -55,7 +58,7 @@ def store_app_id(app_id)

def save_to_file(hash)
FileUtils.mkdir_p(FABRICIO_DIRECTORY_PATH)
File.open(SESSION_FILE_PATH,'w') do |f|
File.open(PARAM_FILE_PATH,'w') do |f|
f.write hash.to_yaml
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/fabricio/authorization/file_session_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Constants
FABRICIO_DIRECTORY_PATH = "#{Dir.home}/.fabricio"
SESSION_FILE_PATH = "#{CREDENTIAL_DIRECTORY_PATH}/.session"
SESSION_FILE_PATH = "#{FABRICIO_DIRECTORY_PATH}/.session"

module Fabricio
module Authorization
Expand All @@ -17,7 +17,8 @@ class FileSessionStorage < AbstractSessionStorage
def obtain_session
return nil unless File.exist?(SESSION_FILE_PATH)
session_hash = YAML.load_file(SESSION_FILE_PATH)
session = Session(session_hash)
return nil unless session_hash
session = Session.new(session_hash)
return nil unless session.access_token
return nil unless session.refresh_token
session
Expand Down

0 comments on commit 5b2ee87

Please sign in to comment.