Created
June 3, 2015 04:03
-
-
Save PositiveControl/2e3352907986c9186407 to your computer and use it in GitHub Desktop.
Stage one... get RAX file URLs
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
require "fog" | |
require "pry" | |
class RaxUserFileSet | |
def initialize(limit = nil) | |
conn = Fog::Storage.new({ | |
:provider => "Rackspace", | |
:rackspace_username => RAX_UN, | |
:rackspace_api_key => RAX_API_KEY, | |
:rackspace_region => :dfw | |
}) | |
@dir = conn.directories.get "teamsnap_production" | |
@rax_array = [] | |
@limit = limit || 10_000 | |
end | |
def retrieve(last_file = nil) | |
loop do | |
urls = get_user_file_urls(@limit, last_file) | |
@rax_array << urls | |
@rax_array.flatten! | |
last_file = @rax_array.last.split(/rackcdn.com\//).last | |
break if urls.count < @limit | |
end | |
@rax_array.to_set | |
end | |
private | |
def get_user_file_urls(limit, last_file = nil) | |
@dir.files.all( | |
:limit => limit, | |
:marker => last_file || nil, | |
:prefix => "user_files/") | |
.map(&:public_url) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns a Set or URLs for later comparison against UserFiles table URL Set.
Example: