Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Improve code style for Welcome Controller #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ def submit
@response_code = nil
onenote_client = OneNoteSharer.new
access_token = cookies['access_token']
result = nil

case params[:submit]
when 'text'
result = onenote_client.create_page_with_simple_text(access_token)
when 'textimage'
result = onenote_client.create_page_with_text_and_image(access_token)
when 'url'
result = onenote_client.create_page_with_screenshot_from_url(access_token)
when 'html'
result = onenote_client.create_page_with_screenshot_from_html(access_token)
when 'file'

result = onenote_client.create_page_with_file(access_token)
end

result = case params[:submit]
when 'text'
onenote_client.create_page_with_simple_text(access_token)
when 'textimage'
onenote_client.create_page_with_text_and_image(access_token)
when 'url'
onenote_client.create_page_with_screenshot_from_url(access_token)
when 'html'
onenote_client.create_page_with_screenshot_from_html(access_token)
when 'file'
onenote_client.create_page_with_file(access_token)
end
@oneNoteWeb_url = result['links']['oneNoteWebUrl']['href'] if result.present?

rescue Exception => e
Expand All @@ -39,15 +35,13 @@ def submit
def callback
onenote_client = OneNoteSharer.new
token_set = onenote_client.handle_callback_request(params)
if token_set.present?
expire_in = token_set['expires_in'].to_i
cookies['access_token'] = { :value => token_set['access_token'], :expires => expire_in.seconds.from_now }
cookies['authentication_token'] = { :value => token_set['authentication_token'], :expires => expire_in.seconds.from_now }
cookies['scope'] = { :value => token_set['scope'], :expires => expire_in.seconds.from_now }
refresh_token = token_set['refresh_token']

onenote_client.save_refresh_token(refresh_token) if refresh_token.present?
end
return unless token.present?
expire_in = token_set['expires_in'].to_i
cookies['access_token'] = { :value => token_set['access_token'], :expires => expire_in.seconds.from_now }
cookies['authentication_token'] = { :value => token_set['authentication_token'], :expires => expire_in.seconds.from_now }
cookies['scope'] = { :value => token_set['scope'], :expires => expire_in.seconds.from_now }
refresh_token = token_set['refresh_token']
onenote_client.save_refresh_token(refresh_token) if refresh_token.present?
end

end