Sha256: eadf062f3059f858880dd4385b6356f278900e4605a1850d08e3ec0273ebf083
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
require "fileutils" require "dribbble_bucket_api" require "dribbble_bucket_sync/version" require "dribbble_bucket_sync/folder" class DribbbleBucketSync attr_reader :username def initialize(username) @username = username end def sync_to(directory) # ensure the directory exists unless File.directory?(directory) raise ArgumentError, "Sync destination must be a valid directory:\n#{directory}" end # get the first page response = connection.buckets(page: 1) # load the total pages total_pages = response.total_pages # return if total pages is none return if total_pages < 1 # print how many buckets there are puts "#{@username} has #{response.total_entries} buckets." # loop through each page 1.upto(total_pages) do |page| # load the buckets for this page buckets = connection.buckets(page: page) # sync each bucket buckets.each do |bucket| sync_bucket(bucket, directory) end end end private def sync_bucket(bucket, directory) # create the folder for the bucket folder = Folder.new(directory, bucket.name) # get the first page response = bucket.shots(page: 1) # load the total pages total_pages = response.total_pages # return if total pages is none return if total_pages < 1 # print how many shots there are puts "#{bucket.name} has #{response.total_entries} shots." # loop through each page 1.upto(total_pages) do |page| # load the buckets for this page shots = bucket.shots(page: page) # add each shot to the folder shots.each do |shot| folder.add_shot(shot) end end # remove old shots folder.remove_old_shots end def connection @connection = DribbbleBucketApi.connect(username: @username) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dribbble-bucket-sync-0.0.1 | lib/dribbble_bucket_sync.rb |