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?, #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



73
74
75
76
77
78
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 73

def encode_with(coder)
  coder.map = {
    "username" => @username,
    "password" => @password
  }
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



68
69
70
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 68

def patch(file)
  fetch_file(file)
end

#patchesObject

Fetches a list of every patch file



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubyfocus/fetchers/oss_fetcher.rb', line 53

def patches
  @patches ||= 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
      links = table.scan(/<a href="([^"]+)"/).flatten.select{ |f| f.end_with?(".zip") }
      links.map{ |u| Rubyfocus::Patch.new(self,u) }
    else
      []
    end
  end
end