Class: ConstantContact::Services::LibraryService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/constantcontact/services/library_service.rb

Class Method Summary collapse

Class 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



203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/constantcontact/services/library_service.rb', line 203

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



50
51
52
53
54
55
56
# File 'lib/constantcontact/services/library_service.rb', line 50

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.



234
235
236
237
238
239
# File 'lib/constantcontact/services/library_service.rb', line 234

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



86
87
88
89
90
91
# File 'lib/constantcontact/services/library_service.rb', line 86

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_trashBoolean

Permanently deletes all files in the Trash folder



126
127
128
129
130
131
# File 'lib/constantcontact/services/library_service.rb', line 126

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



184
185
186
187
188
189
# File 'lib/constantcontact/services/library_service.rb', line 184

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



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/constantcontact/services/library_service.rb', line 148

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



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/constantcontact/services/library_service.rb', line 167

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



246
247
248
249
250
251
252
253
254
255
256
# File 'lib/constantcontact/services/library_service.rb', line 246

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



62
63
64
65
66
67
# File 'lib/constantcontact/services/library_service.rb', line 62

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



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/constantcontact/services/library_service.rb', line 34

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_infoLibrarySummary

Retrieve MyLibrary usage information



14
15
16
17
18
19
# File 'lib/constantcontact/services/library_service.rb', line 14

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



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/constantcontact/services/library_service.rb', line 111

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.



264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/constantcontact/services/library_service.rb', line 264

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



220
221
222
223
224
225
226
# File 'lib/constantcontact/services/library_service.rb', line 220

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



73
74
75
76
77
78
79
80
# File 'lib/constantcontact/services/library_service.rb', line 73

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