Class: Uplink::UplinkUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/uplink/uplink_util.rb

Class Method Summary collapse

Class Method Details

.build_custom_metadata(custom) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/uplink/uplink_util.rb', line 57

def (custom)
  count = custom.size
  mem_entries = FFI::MemoryPointer.new(UplinkLib::UplinkCustomMetadataEntry, count)

  custom.to_a.each_with_index do |(key, value), i|
    mem_key = FFI::MemoryPointer.from_string(key.to_s) if key
    mem_value = FFI::MemoryPointer.from_string(value.to_s) if value

    entry = UplinkLib::UplinkCustomMetadataEntry.new(mem_entries + (i * UplinkLib::UplinkCustomMetadataEntry.size))
    entry[:key] = mem_key
    entry[:key_length] = key ? key.length : 0
    entry[:value] = mem_value
    entry[:value_length] = value ? value.to_s.length : 0
  end

   = UplinkLib::UplinkCustomMetadata.new
  [:count] = count
  [:entries] = mem_entries

  
end

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/uplink/uplink_util.rb', line 34

def build_uplink_config(config)
  raise ArgumentError, 'config argument is nil' if config.nil?

  config_options = UplinkLib::UplinkConfig.new
  user_agent = FFI::MemoryPointer.from_string(config[:user_agent]) if config[:user_agent]
  temp_directory = FFI::MemoryPointer.from_string(config[:temp_directory]) if config[:temp_directory]
  config_options[:user_agent] = user_agent
  config_options[:dial_timeout_milliseconds] = config[:dial_timeout_milliseconds]&.to_i || 0
  config_options[:temp_directory] = temp_directory

  config_options
end

.build_upload_options(options) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/uplink/uplink_util.rb', line 47

def build_upload_options(options)
  upload_options = nil
  if options && !options.empty?
    upload_options = UplinkLib::UplinkUploadOptions.new
    upload_options[:expires] = options[:expires].to_i if options[:expires]
  end

  upload_options
end

.get_custom_metadata(object) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uplink/uplink_util.rb', line 12

def (object)
  custom = {}

  return custom if object.null? || object[:custom].null?

  count = object[:custom][:count]
  mem_entries = object[:custom][:entries]

  return custom if mem_entries.null?

  count.times do |i|
    entry = UplinkLib::UplinkCustomMetadataEntry.new(mem_entries + (i * UplinkLib::UplinkCustomMetadataEntry.size))
    next if entry.null?

    key = entry[:key].read_string
    value = entry[:value].read_string
    custom[key] = value
  end

  custom
end

.get_system_values(object) ⇒ Object



6
7
8
9
10
# File 'lib/uplink/uplink_util.rb', line 6

def get_system_values(object)
  return if object.null? || object[:system].null?

  [object[:system][:created], object[:system][:expires], object[:system][:content_length]]
end