Class: Zm::Client::Upload
- Inherits:
-
Object
- Object
- Zm::Client::Upload
- Defined in:
- lib/zm/client/upload/upload.rb
Overview
class for upload account file
Constant Summary collapse
- FMT_TYPES_H =
{ 'ics' => ['appointment'], 'vcard' => ['contact'] }
Instance Method Summary collapse
- #download_file(folder_path, fmt, types, ids, dest_file_path) ⇒ Object
- #download_file_url(folder_path, fmt, types, ids = []) ⇒ Object
- #download_file_with_url(url, dest_file_path) ⇒ Object
- #download_folder(id, fmt, dest_file_path) ⇒ Object
- #download_folder_url(id, fmt) ⇒ Object
-
#initialize(parent, rac = nil) ⇒ Upload
constructor
A new instance of Upload.
- #is_blank?(v) ⇒ Boolean
- #query_ids(ids) ⇒ Object
- #query_value_types(types, fmt) ⇒ Object
- #send_attachment(src_file_path) ⇒ Object
- #send_file(folder_path, fmt, types, resolve, src_file_path) ⇒ Object
- #send_file_url(folder_path, fmt, types, resolve) ⇒ Object
- #upload_attachment(src_file_path) ⇒ Object
- #upload_attachment_url ⇒ Object
Constructor Details
#initialize(parent, rac = nil) ⇒ Upload
Returns a new instance of Upload.
12 13 14 15 |
# File 'lib/zm/client/upload/upload.rb', line 12 def initialize(parent, rac = nil) @parent = parent @rac = rac || @parent.rac end |
Instance Method Details
#download_file(folder_path, fmt, types, ids, dest_file_path) ⇒ Object
22 23 24 |
# File 'lib/zm/client/upload/upload.rb', line 22 def download_file(folder_path, fmt, types, ids, dest_file_path) @rac.download(download_file_url(folder_path, fmt, types, ids), dest_file_path) end |
#download_file_url(folder_path, fmt, types, ids = []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/zm/client/upload/upload.rb', line 52 def download_file_url(folder_path, fmt, types, ids = []) url_folder_path = File.join(@parent.home_url, folder_path.to_s) h = { fmt: fmt, types: query_value_types(types, fmt), emptyname: 'Vide', charset: 'UTF-8', auth: 'qp', zauthtoken: @parent.token, disp: 'a' } h.merge!(query_ids(ids)) h.reject! { |_, v| is_blank?(v) } uri = Addressable::URI.new uri.query_values = h url_folder_path << '?' << uri.query # puts url_folder_path url_folder_path end |
#download_file_with_url(url, dest_file_path) ⇒ Object
17 18 19 20 |
# File 'lib/zm/client/upload/upload.rb', line 17 def download_file_with_url(url, dest_file_path) url = File.join(@parent.home_url, url) unless url.start_with?('http') @rac.download(url, dest_file_path) end |
#download_folder(id, fmt, dest_file_path) ⇒ Object
26 27 28 |
# File 'lib/zm/client/upload/upload.rb', line 26 def download_folder(id, fmt, dest_file_path) @rac.download(download_folder_url(id, fmt), dest_file_path) end |
#download_folder_url(id, fmt) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zm/client/upload/upload.rb', line 30 def download_folder_url(id, fmt) url_folder_path = @parent.home_url h = { fmt: fmt, id: id, emptyname: 'Vide', charset: 'UTF-8', auth: 'qp', zauthtoken: @parent.token, disp: 'a' } uri = Addressable::URI.new uri.query_values = h url_folder_path << '?' << uri.query # puts url_folder_path url_folder_path end |
#is_blank?(v) ⇒ Boolean
135 136 137 138 139 |
# File 'lib/zm/client/upload/upload.rb', line 135 def is_blank?(v) return false if v.is_a?(Numeric) v.nil? || v.empty? end |
#query_ids(ids) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/zm/client/upload/upload.rb', line 121 def query_ids(ids) return {} if ids.nil? return { id: ids } unless ids.is_a?(Array) return { id: ids.first } if ids.length == 1 return { list: ids.join(',') } end |
#query_value_types(types, fmt) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/zm/client/upload/upload.rb', line 128 def query_value_types(types, fmt) types = FMT_TYPES_H[fmt] if types.nil? types = [types] unless types.is_a?(Array) types.join(',') end |
#send_attachment(src_file_path) ⇒ Object
103 104 105 106 |
# File 'lib/zm/client/upload/upload.rb', line 103 def (src_file_path) str = (src_file_path) AttachmentResponse.new(str) end |
#send_file(folder_path, fmt, types, resolve, src_file_path) ⇒ Object
78 79 80 |
# File 'lib/zm/client/upload/upload.rb', line 78 def send_file(folder_path, fmt, types, resolve, src_file_path) @rac.upload(send_file_url(folder_path, fmt, types, resolve), src_file_path) end |
#send_file_url(folder_path, fmt, types, resolve) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/zm/client/upload/upload.rb', line 82 def send_file_url(folder_path, fmt, types, resolve) # resolve=[modfy|replace|reset|skip] url_folder_path = File.join(@parent.home_url, folder_path.to_s) h = { fmt: fmt, types: query_value_types(types, fmt), resolve: resolve, auth: 'qp', zauthtoken: @parent.token } h.reject! { |_, v| is_blank?(v) } uri = Addressable::URI.new uri.query_values = h url_folder_path << '?' << uri.query url_folder_path end |
#upload_attachment(src_file_path) ⇒ Object
108 109 110 |
# File 'lib/zm/client/upload/upload.rb', line 108 def (src_file_path) @rac.upload(, src_file_path) end |
#upload_attachment_url ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/zm/client/upload/upload.rb', line 112 def @rac.("ZM_AUTH_TOKEN=#{@parent.token}") uri = Addressable::URI.new uri.query_values = { fmt: 'extended,raw' } File.join(@parent.public_url, 'service/upload') << '?' << uri.query end |