class Rubyfocus::OSSFetcher

This fetcher fetches data from the OmniSyncServer. NOTE: This does not register a client with the OmniSyncServer. As such, if you don't sync with the database regularly, you will likely lose track of the head and have to re-sync.

Attributes

fetcher[RW]

The engine used to fetch data. Defaults to HTTParty

password[RW]
username[RW]

Used to log in to the Omni Sync Server. Also determines the URL of your file

Public Class Methods

new(u,p) click to toggle source

Initialise with username and password

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 16
def initialize(u,p)
        @username = u
        @password = p
        @fetcher = HTTParty
end

Public Instance Methods

base() click to toggle source

Fetches the contents of the base file

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 30
def base
        @base ||= if self.patches.size > 0
                fetch_file(self.patches.first.file)
        else
                raise Rubyfocus::OSSFetcherError, "Looking for zip files at #{url}: none found."
        end
end
base_id() click to toggle source

Fetches the ID Of the base file

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 39
def base_id
        if self.patches.size > 0
                base_file = self.patches.first
                if base_file.file =~ /^\d+\=.*\+(.*)\.zip$/
                        $1
                else
                        raise Rubyfocus::OSSFetcherError, "Malformed patch file #{base_file}."
                end
        else
                raise Rubyfocus::OSSFetcherError, "Looking for zip files at #{url}: none found."
        end
end
encode_with(coder) click to toggle source

Save to disk

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 82
def encode_with(coder)
        coder.map = {
                "username" => @username,
                "password" => @password
        }
end
encrypted?() click to toggle source

Is this encrypted?

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 77
def encrypted?
        files.find{ |f| File.basename(f) == "encrypted" }
end
files() click to toggle source

Fetches a list of all files contained within the database

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 53
def files
        @files ||= begin
                response = self.fetcher.get(url, digest_auth: auth).body
                # Text is in first table, let's assume
                table = response[/<table>(.*?)<\/table>/m,1]
                if table
                        table.scan(/<a href="([^"]+)"/).flatten
                else
                        []
                end
        end
end
init_with(coder) click to toggle source

Init from yaml

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 23
def init_with(coder)
        @username = coder["username"]
        @password = coder["password"]
        @fetcher = HTTParty
end
patch(file) click to toggle source

Fetches the contents of a given patch file

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 72
def patch(file)
        fetch_file(file)
end
patches() click to toggle source

Fetches a list of every patch file

# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 67
def patches
        @patches ||= files.select{ |f| f.end_with?(".zip") }.map{ |u| Rubyfocus::Patch.new(self,u) }
end

Private Instance Methods

auth() click to toggle source
# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 92
def auth
        {username: @username, password: @password}
end
fetch_file(f) click to toggle source
# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 100
def fetch_file(f)
        fq_zipfile = File.join(url,f)
        data = self.fetcher.get(fq_zipfile, digest_auth: auth).body
        io = StringIO.new(data)
        Zip::InputStream.open(io) do |io|
                while (entry = io.get_next_entry)
                        return io.read if entry.name == "contents.xml"
                end
                raise Rubyfocus::OSSFetcherError, "Malformed OmniFocus zip file #{fq_zipfile}."
        end
end
url() click to toggle source
# File lib/rubyfocus/fetchers/oss_fetcher.rb, line 96
def url
        "https://sync.omnigroup.com/#{@username}/OmniFocus.ofocus"
end