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



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

def initialize(client, file_info)
  @client = client
  @file_info = file_info.transform_values do |info|
    # 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.
    info.except(:create_folder_name, :after_upload, :type)
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



37
38
39
# File 'lib/furaffinity/queue_hook.rb', line 37

def client
  @client
end

#file_infoObject (readonly)

Returns the value of attribute file_info.



37
38
39
# File 'lib/furaffinity/queue_hook.rb', line 37

def file_info
  @file_info
end

Instance Method Details

#run_hook(file_name, code) ⇒ Object



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

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



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

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