Class: Furaffinity::QueueHook

Inherits:
Object
  • Object
show all
Includes:
SemanticLogger::Loggable
Defined in:
lib/furaffinity/queue_hook.rb

Defined Under Namespace

Classes: HookRunner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, file_info) ⇒ QueueHook

Returns a new instance of QueueHook.



37
38
39
40
41
42
43
44
45
46
# File 'lib/furaffinity/queue_hook.rb', line 37

def initialize(client, file_info)
  @client = client
  @file_info = file_info.each_with_object({}) do |(file_name, info), h|
    # Hash#except duplicates the hash, which is good here as we don't want
    # to modify the queue.
    # exclude after_upload as it's not needed, and create_folder_name and
    # type is only relevant when initially uploading the submission.
    h[file_name] = info.except(:create_folder_name, :after_upload, :type)
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



35
36
37
# File 'lib/furaffinity/queue_hook.rb', line 35

def client
  @client
end

#file_infoObject (readonly)

Returns the value of attribute file_info.



35
36
37
# File 'lib/furaffinity/queue_hook.rb', line 35

def file_info
  @file_info
end

Instance Method Details

#run_hook(file_name, code) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/furaffinity/queue_hook.rb', line 57

def run_hook(file_name, code)
  logger.debug { "Running hook" }
  logger.trace { "Hook code:\n#{code}" }
  HookRunner
    .new(client, file_info, file_name)
    .instance_eval(code, File.join(Dir.pwd, "#{file_name}.info.yml"), 0)
end

#update_ids(upload_status) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/furaffinity/queue_hook.rb', line 48

def update_ids(upload_status)
  logger.trace { "Updating file info ids" }
  upload_status.each do |file_name, status|
    next unless status[:uploaded]

    @file_info[file_name][:id] = status[:url].match(%{/view/(?<id>[^/]+)})[:id]
  end
end