Created
August 16, 2018 11:37
-
-
Save NaiyaShah-BTC/c93e702f6c4281359fec0c207a0a2766 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_tokens(access, refresh) | |
TokenCred.create!(access: access, refresh: refresh) | |
end | |
def upload_zip_to_box | |
token_refresh_callback = lambda { |access, refresh, identifier| save_tokens(access, refresh) } | |
client = Boxr::Client.new(TokenCred.last.access, | |
refresh_token: TokenCred.last.refresh, | |
client_id: ENV['CLIENT_ID'], | |
client_secret: ENV['CLIENT_SECRET'], | |
&token_refresh_callback) | |
folder = client.folder_from_path('/images') | |
file = client.upload_file(Rails.public_path.join('goodsImages.zip').to_s, folder) | |
updated_file = client.create_shared_link_for_file(file, access: :open) | |
puts "URL of the uploaded file is: #{updated_file.shared_link.url}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment