class ConstantContact::Services::LibraryService

Public Class Methods

add_library_file(file_name, folder_id, description, source, file_type, contents) click to toggle source

Adds a new MyLibrary file using the multipart content-type @param [String] file_name - The name of the file (ie: dinnerplate-special.jpg) @param [String] folder_id - Folder id to add the file to @param [String] description - The description of the file provided by user @param [String] source - indicates the source of the original file;

image files can be uploaded from the following sources :
MyComputer, StockImage, Facebook - MyLibrary Plus customers only,
Instagram - MyLibrary Plus customers only, Shutterstock, Mobile

@param [String] file_type - Specifies the file type, valid values are: JPEG, JPG, GIF, PDF, PNG @param [String] contents - The content of the file @return [LibraryFile]

# 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) click to toggle source

Create a new MyLibrary folder @param [LibraryFolder] folder - MyLibrary folder to be created @return [LibraryFolder]

# 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) click to toggle source

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. @param [String] file_id - Specifies the MyLibrary file to delete @return [Boolean]

# 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) click to toggle source

Delete a MyLibrary folder @param [String] folder_id - The ID for the MyLibrary folder to delete @return [Boolean]

# 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_trash() click to toggle source

Permanently deletes all files in the Trash folder @return [Boolean]

# 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) click to toggle source

Retrieve a MyLibrary file using the file_id path parameter @param [String] file_id - Specifies the MyLibrary file for which to retrieve information @return [LibraryFile]

# 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 = {}) click to toggle source

Retrieve a collection of MyLibrary files in the Constant Contact account @param [Hash] params - hash of query parameters and values to append to the request.

Allowed parameters include:
type - Specifies the type of files to retrieve, valid values are : ALL, IMAGES, or DOCUMENTS
source - Specifies to retrieve files from a particular source, valid values are :
    ALL - (default) files from all sources
    MyComputer
    StockImage
    Facebook
    Instagram
    Shutterstock
    Mobile
limit -  Specifies the number of results displayed per page of output, from 1 - 1000, default = 50.

@return [ResultSet<LibraryFile>]

# 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 = {}) click to toggle source

Retrieves all files from a MyLibrary folder specified by the folder_id path parameter @param [String] folder_id - Specifies the folder from which to retrieve files @param [Hash] params - hash of query parameters and values to append to the request.

Allowed parameters include:
limit - Specifies the number of results displayed per page of output, from 1 - 50, default = 50.

@return [ResultSet<LibraryFile>]

# 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) click to toggle source

Retrieve the upload status for one or more MyLibrary files using the file_id path parameter; separate multiple file IDs with a comma @param [String] file_id - Specifies the files for which to retrieve upload status information @return [Array<UploadStatus>]

# 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) click to toggle source

Retrieve a specific MyLibrary folder using the folder_id path parameter @param [String] folder_id - The ID for the folder to return @return [LibraryFolder]

# 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) click to toggle source

Retrieve a list of MyLibrary folders @param [Hash] params - hash of query parameters and values to append to the request.

Allowed parameters include:
sort_by - The method to sort by, valid values are :
    CREATED_DATE - sorts by date folder was added, ascending (earliest to latest)
    CREATED_DATE_DESC - (default) sorts by date folder was added, descending (latest to earliest)
    MODIFIED_DATE - sorts by date folder was last modified, ascending (earliest to latest)
    MODIFIED_DATE_DESC - sorts by date folder was last modified, descending (latest to earliest)
    NAME - sorts alphabetically by folder name, a to z
    NAME_DESC - sorts alphabetically by folder name, z to a
limit -  Specifies the number of results displayed per page of output, from 1 - 50, default = 50.

@return [ResultSet<LibraryFolder>]

# 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_info() click to toggle source

Retrieve MyLibrary usage information @return [LibrarySummary]

# 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) click to toggle source

Retrieve all files in the Trash folder @param [Hash] params - hash of query parameters and values to append to the request.

Allowed parameters include:
type - Specifies the type of files to retrieve, valid values are : ALL, IMAGES, or DOCUMENTS
sort_by - The method to sort by, valid values are :
    ADDED_DATE - sorts by date folder was added, ascending (earliest to latest)
    ADDED_DATE_DESC - (default) sorts by date folder was added, descending (latest to earliest)
    MODIFIED_DATE - sorts by date folder was last modified, ascending (earliest to latest)
    MODIFIED_DATE_DESC - sorts by date folder was last modified, descending (latest to earliest)
    NAME - sorts alphabetically by file name, a to z
    NAME_DESC - sorts alphabetically by file name, z to a
    SIZE - sorts by file size, smallest to largest
    SIZE_DESC - sorts by file size, largest to smallest
    DIMENSION - sorts by file dimensions (hxw), smallest to largest
    DIMENSION_DESC - sorts by file dimensions (hxw), largest to smallest
limit -  Specifies the number of results displayed per page of output, from 1 - 50, default = 50.

@return [ResultSet<LibraryFile>]

# 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) click to toggle source

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. @param [String] folder_id - Specifies the destination MyLibrary folder to which the files will be moved @param [String] file_id - Specifies the files to move, in a string of comma separated file ids (e.g. 8,9) @return [Array<MoveResults>]

# 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) click to toggle source

Update information for a specific MyLibrary file @param [LibraryFile] file - Library File to be updated @return [LibraryFile]

# 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) click to toggle source

Update a specific MyLibrary folder @param [LibraryFolder] folder - MyLibrary folder to be updated @return [LibraryFolder]

# 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