Skip to content

Instantly share code, notes, and snippets.

@NaiyaShah-BTC
Created August 16, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaiyaShah-BTC/c93e702f6c4281359fec0c207a0a2766 to your computer and use it in GitHub Desktop.
Save NaiyaShah-BTC/c93e702f6c4281359fec0c207a0a2766 to your computer and use it in GitHub Desktop.
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