This file contains hidden or 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
require "dropbox_sdk" | |
class MyDropboxSession < ActiveRecord::Base | |
# This can obviously live anywhere you store your credentials or settings. | |
APP_KEY = "*********" | |
APP_SECRET = "%%%%%%%%%" | |
scope :authorized, where(authorized: true) |
This file contains hidden or 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
class CreateMyDropboxSessions < ActiveRecord::Migration | |
def change | |
create_table :my_dropbox_sessions do |t| | |
t.string :app_key | |
t.string :app_secret | |
t.string :account_email | |
t.boolean :authorized, default: false | |
t.text :serialized_session | |
t.timestamps |
This file contains hidden or 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
# 1. Create a new record (account email is optional) | |
@db_session = MyDropboxSession.create({app_key: MyDropboxSession::APP_KEY, | |
app_secret: MyDropboxSession::APP_SECRET, | |
account_email: "[email protected]"}) | |
# 2. Get the authorization url and visit it in your browser and then authorize the Application | |
@db_session.authorization_url | |
# 3. After authorizing in the browser, complete the authorization | |
# - This gets the access token, serializes the session and saves it in the database |
This file contains hidden or 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
# A. Puting a file to dropbox | |
@db_session.client.put_file("/Some Shared Dropbox Folder the User has access to/my_data_file.csv","#{Rails.root}/tmp/my_data_file.csv") | |
# B. Getting a file from dropbox (from dropbox site) | |
contents, metadata = @db_session.client.get_file_and_metadata('/magnum-opus.txt') | |
open('magnum-opus.txt', 'w') {|f| f.puts contents } | |
This file contains hidden or 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
# To try and fix the sort order, switching to an integer instead of time. | |
integer :listed_at do |item| | |
original_listed_at_time = nil | |
original_item = item.original_item if item.original_item_id.present? && item.payout_policy == "upfront" | |
if original_item && original_item.created_at < Time.parse("April 1 2014") | |
original_listed_at_time = original_item.listed_at | |
end |
OlderNewer