class GatherContent::Api::Projects

Attributes

account_id[RW]

Public Class Methods

new(account_id) click to toggle source
# File lib/gather_content/api/projects.rb, line 7
def initialize(account_id)
  raise ArgumentError, "account_id is required!" if account_id.nil?
  @account_id = account_id
end

Public Instance Methods

create(data) click to toggle source
# File lib/gather_content/api/projects.rb, line 18
def create(data)
  data.delete("type") if data["type"].nil? || data["type"].empty?

  raise ArgumentError, "name is required!" if data["name"].nil? || data["name"].empty?
  raise ArgumentError, "type is invalid!" unless valid_type?(data["type"])

  result = post_json(data.merge({ 'account_id' => @account_id }))

  if result.status == 202
    project_id = result.headers['location'].split('/').last
    GatherContent::Api::Project.new(project_id)
  else
    raise GatherContent::Error::RequestError.new(result)
  end
end
each() { |project| ... } click to toggle source
# File lib/gather_content/api/projects.rb, line 12
def each(&block)
  fetch.each do |project|
    yield GatherContent::Api::Project.new(project['id'], project)
  end
end

Private Instance Methods

params() click to toggle source
# File lib/gather_content/api/projects.rb, line 36
def params
  { account_id: @account_id }
end
path() click to toggle source
# File lib/gather_content/api/projects.rb, line 40
def path
  @path ||= '/projects'
end
valid_type?(type) click to toggle source
# File lib/gather_content/api/projects.rb, line 44
def valid_type?(type)
  return type = "other" if type.nil? || type.empty?
  types = %w{website-build ongoing-website-content marketing-editorial-content email-marketing-content other}
  types.include?(type)
end