Class: GatherContent::Api::Projects
- Includes:
- Enumerable
- Defined in:
- lib/gather_content/api/projects.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
Instance Method Summary collapse
- #create(data) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(account_id) ⇒ Projects
constructor
A new instance of Projects.
Methods inherited from Base
#fetch, #get, #post, #post_json, #reset
Constructor Details
#initialize(account_id) ⇒ Projects
Returns a new instance of Projects.
7 8 9 10 |
# 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 |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
4 5 6 |
# File 'lib/gather_content/api/projects.rb', line 4 def account_id @account_id end |
Instance Method Details
#create(data) ⇒ Object
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 |