Class: Rubyfocus::OSSFetcher

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/rubyfocus/fetchers/oss_fetcher.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fetcher

#can_patch?, #can_reach_head_from?, #head, #next_patch, #reset, #update_full, #update_once

Constructor Details

#initialize(u, p) ⇒ OSSFetcher

Initialise with username and password



16
17
18
19
20
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 16

def initialize(u,p)
  @username = u
  @password = p
  @fetcher = HTTParty
end

Instance Attribute Details

#fetcherObject

The engine used to fetch data. Defaults to HTTParty



10
11
12
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 10

def fetcher
  @fetcher
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 7

def password
  @password
end

#usernameObject

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



6
7
8
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 6

def username
  @username
end

Instance Method Details

#baseObject

Fetches the contents of the base file



30
31
32
33
34
35
36
# 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_idObject

Fetches the ID Of the base file



39
40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object

Save to disk



82
83
84
85
86
87
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 82

def encode_with(coder)
  coder.map = {
    "username" => @username,
    "password" => @password
  }
end

#encrypted?Boolean

Is this encrypted?



77
78
79
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 77

def encrypted?
  files.find{ |f| File.basename(f) == "encrypted" }
end

#filesObject

Fetches a list of all files contained within the database



53
54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object

Init from yaml



23
24
25
26
27
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 23

def init_with(coder)
  @username = coder["username"]
  @password = coder["password"]
  @fetcher = HTTParty
end

#patch(file) ⇒ Object

Fetches the contents of a given patch file



72
73
74
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 72

def patch(file)
  fetch_file(file)
end

#patchesObject

Fetches a list of every patch file



67
68
69
# 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