Class: Uplink::UplinkUtil
- Inherits:
-
Object
- Object
- Uplink::UplinkUtil
- Defined in:
- lib/uplink/uplink_util.rb
Class Method Summary collapse
- .build_custom_metadata(custom) ⇒ Object
- .build_uplink_config(config) ⇒ Object
- .build_upload_options(options) ⇒ Object
- .get_custom_metadata(object) ⇒ Object
- .get_system_values(object) ⇒ Object
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 |
.build_uplink_config(config) ⇒ Object
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? = 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] [:user_agent] = user_agent [:dial_timeout_milliseconds] = config[:dial_timeout_milliseconds]&.to_i || 0 [:temp_directory] = temp_directory end |
.build_upload_options(options) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/uplink/uplink_util.rb', line 47 def () = nil if && !.empty? = UplinkLib::UplinkUploadOptions.new [:expires] = [:expires].to_i if [:expires] end 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 |