Class: GatherContent::Api::Projects

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gather_content/api/projects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#fetch, #get, #post, #post_json, #reset

Constructor Details

#initialize(account_id) ⇒ Projects

Returns a new instance of Projects.

Raises:

  • (ArgumentError)


7
8
9
10
# File 'lib/gather_content/api/projects.rb', line 7

def initialize()
  raise ArgumentError, "account_id is required!" if .nil?
  @account_id = 
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



4
5
6
# File 'lib/gather_content/api/projects.rb', line 4

def 
  @account_id
end

Instance Method Details

#create(data) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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(&block) ⇒ Object



12
13
14
15
16
# 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