Class: ConstantContact::Services::LibraryService
- Inherits:
-
BaseService
- Object
- BaseService
- ConstantContact::Services::LibraryService
- Defined in:
- lib/constantcontact/services/library_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#add_library_file(file_name, folder_id, description, source, file_type, contents) ⇒ LibraryFile
Adds a new MyLibrary file using the multipart content-type.
-
#add_library_folder(folder) ⇒ LibraryFolder
Create a new MyLibrary folder.
-
#delete_library_file(file_id) ⇒ Boolean
Delete one or more MyLibrary files specified by the fileId path parameter; separate multiple file IDs with a comma.
-
#delete_library_folder(folder_id) ⇒ Boolean
Delete a MyLibrary folder.
-
#delete_library_trash ⇒ Boolean
Permanently deletes all files in the Trash folder.
-
#get_library_file(file_id) ⇒ LibraryFile
Retrieve a MyLibrary file using the file_id path parameter.
-
#get_library_files(params = {}) ⇒ ResultSet<LibraryFile>
Retrieve a collection of MyLibrary files in the Constant Contact account.
-
#get_library_files_by_folder(folder_id, params = {}) ⇒ ResultSet<LibraryFile>
Retrieves all files from a MyLibrary folder specified by the folder_id path parameter.
-
#get_library_files_upload_status(file_id) ⇒ Array<UploadStatus>
Retrieve the upload status for one or more MyLibrary files using the file_id path parameter; separate multiple file IDs with a comma.
-
#get_library_folder(folder_id) ⇒ LibraryFolder
Retrieve a specific MyLibrary folder using the folder_id path parameter.
-
#get_library_folders(params) ⇒ ResultSet<LibraryFolder>
Retrieve a list of MyLibrary folders.
-
#get_library_info ⇒ LibrarySummary
Retrieve MyLibrary usage information.
-
#get_library_trash(params) ⇒ ResultSet<LibraryFile>
Retrieve all files in the Trash folder.
-
#move_library_files(folder_id, file_id) ⇒ Array<MoveResults>
Move one or more MyLibrary files to a different folder in the user's account specify the destination folder using the folder_id path parameter.
-
#update_library_file(file) ⇒ LibraryFile
Update information for a specific MyLibrary file.
-
#update_library_folder(folder) ⇒ LibraryFolder
Update a specific MyLibrary folder.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from ConstantContact::Services::BaseService
Instance Method Details
#add_library_file(file_name, folder_id, description, source, file_type, contents) ⇒ LibraryFile
Adds a new MyLibrary file using the multipart content-type
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/constantcontact/services/library_service.rb', line 202 def add_library_file(file_name, folder_id, description, source, file_type, contents) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_files') url = build_url(url) payload = { :file_name => file_name, :folder_id => folder_id, :description => description, :source => source, :file_type => file_type, :data => contents, :multipart => true } response = RestClient.post(url, payload, get_headers()) location = response.headers[:location] || '' location.split('/').last end |
#add_library_folder(folder) ⇒ LibraryFolder
Create a new MyLibrary folder
49 50 51 52 53 54 55 |
# File 'lib/constantcontact/services/library_service.rb', line 49 def add_library_folder(folder) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_folders') url = build_url(url) payload = folder.to_json response = RestClient.post(url, payload, get_headers()) Components::LibraryFolder.create(JSON.parse(response.body)) end |
#delete_library_file(file_id) ⇒ Boolean
Delete one or more MyLibrary files specified by the fileId path parameter; separate multiple file IDs with a comma. Deleted files are moved from their current folder into the system Trash folder, and its status is set to Deleted.
233 234 235 236 237 238 |
# File 'lib/constantcontact/services/library_service.rb', line 233 def delete_library_file(file_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_file'), file_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#delete_library_folder(folder_id) ⇒ Boolean
Delete a MyLibrary folder
85 86 87 88 89 90 |
# File 'lib/constantcontact/services/library_service.rb', line 85 def delete_library_folder(folder_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_folder'), folder_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#delete_library_trash ⇒ Boolean
Permanently deletes all files in the Trash folder
125 126 127 128 129 130 |
# File 'lib/constantcontact/services/library_service.rb', line 125 def delete_library_trash() url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_folder_trash') url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#get_library_file(file_id) ⇒ LibraryFile
Retrieve a MyLibrary file using the file_id path parameter
183 184 185 186 187 188 |
# File 'lib/constantcontact/services/library_service.rb', line 183 def get_library_file(file_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_file'), file_id) url = build_url(url) response = RestClient.get(url, get_headers()) Components::LibraryFile.create(JSON.parse(response.body)) end |
#get_library_files(params = {}) ⇒ ResultSet<LibraryFile>
Retrieve a collection of MyLibrary files in the Constant Contact account
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/constantcontact/services/library_service.rb', line 147 def get_library_files(params = {}) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_files') url = build_url(url, params) response = RestClient.get(url, get_headers()) files = [] body = JSON.parse(response.body) body['results'].each do |file| files << Components::LibraryFile.create(file) end Components::ResultSet.new(files, body['meta']) end |
#get_library_files_by_folder(folder_id, params = {}) ⇒ ResultSet<LibraryFile>
Retrieves all files from a MyLibrary folder specified by the folder_id path parameter
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/constantcontact/services/library_service.rb', line 166 def get_library_files_by_folder(folder_id, params = {}) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_files_by_folder'), folder_id) url = build_url(url, params) response = RestClient.get(url, get_headers()) files = [] body = JSON.parse(response.body) body['results'].each do |file| files << Components::LibraryFile.create(file) end Components::ResultSet.new(files, body['meta']) end |
#get_library_files_upload_status(file_id) ⇒ Array<UploadStatus>
Retrieve the upload status for one or more MyLibrary files using the file_id path parameter; separate multiple file IDs with a comma
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/constantcontact/services/library_service.rb', line 245 def get_library_files_upload_status(file_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_file_upload_status'), file_id) url = build_url(url) response = RestClient.get(url, get_headers()) statuses = [] JSON.parse(response.body).each do |status| statuses << Components::UploadStatus.create(status) end statuses end |
#get_library_folder(folder_id) ⇒ LibraryFolder
Retrieve a specific MyLibrary folder using the folder_id path parameter
61 62 63 64 65 66 |
# File 'lib/constantcontact/services/library_service.rb', line 61 def get_library_folder(folder_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_folder'), folder_id) url = build_url(url) response = RestClient.get(url, get_headers()) Components::LibraryFolder.create(JSON.parse(response.body)) end |
#get_library_folders(params) ⇒ ResultSet<LibraryFolder>
Retrieve a list of MyLibrary folders
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/constantcontact/services/library_service.rb', line 33 def get_library_folders(params) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_folders') url = build_url(url, params) response = RestClient.get(url, get_headers()) folders = [] body = JSON.parse(response.body) body['results'].each do |folder| folders << Components::LibraryFolder.create(folder) end Components::ResultSet.new(folders, body['meta']) end |
#get_library_info ⇒ LibrarySummary
Retrieve MyLibrary usage information
13 14 15 16 17 18 |
# File 'lib/constantcontact/services/library_service.rb', line 13 def get_library_info() url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_info') response = RestClient.get(url, get_headers()) Components::LibrarySummary.create(JSON.parse(response.body).first) end |
#get_library_trash(params) ⇒ ResultSet<LibraryFile>
Retrieve all files in the Trash folder
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/constantcontact/services/library_service.rb', line 110 def get_library_trash(params) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.library_folder_trash') url = build_url(url, params) response = RestClient.get(url, get_headers()) files = [] body = JSON.parse(response.body) body['results'].each do |file| files << Components::LibraryFile.create(file) end Components::ResultSet.new(files, body['meta']) end |
#move_library_files(folder_id, file_id) ⇒ Array<MoveResults>
Move one or more MyLibrary files to a different folder in the user's account specify the destination folder using the folder_id path parameter.
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/constantcontact/services/library_service.rb', line 263 def move_library_files(folder_id, file_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_file_move'), folder_id) url = build_url(url) payload = file_id.split(',').map {|id| id.strip}.to_json response = RestClient.put(url, payload, get_headers()) results = [] JSON.parse(response.body).each do |result| results << Components::MoveResults.create(result) end results end |
#update_library_file(file) ⇒ LibraryFile
Update information for a specific MyLibrary file
219 220 221 222 223 224 225 |
# File 'lib/constantcontact/services/library_service.rb', line 219 def update_library_file(file) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_file'), file.id) url = build_url(url) payload = file.to_json response = RestClient.put(url, payload, get_headers()) Components::LibraryFile.create(JSON.parse(response.body)) end |
#update_library_folder(folder) ⇒ LibraryFolder
Update a specific MyLibrary folder
72 73 74 75 76 77 78 79 |
# File 'lib/constantcontact/services/library_service.rb', line 72 def update_library_folder(folder) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.library_folder'), folder.id) url = build_url(url) payload = folder.to_json response = RestClient.put(url, payload, get_headers()) Components::LibraryFolder.create(JSON.parse(response.body)) end |