Sha256: 56fa0b69d0ee1eebd9e377383077882ce38bfb704013dba778a0258378b21862

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module TeamcityRuby
  class Project
    extend TeamcityRuby::Resource

    attr_reader :teamcity_id, :name, :parent_id

    def self.all
      client.get("/projects")["project"].map do |p|
        new(p)
      end
    end

    def self.find(options = {})
      response = client.get("/projects/#{locator(options)}")
      return nil if ( response.body =~ /No project found/  )
      new(response)
    end

    def self.create(name, options = {})
      payload = { "name" => name }
      payload["parentProject"] = { "id" => options[:parent_id] } if options[:parent_id]

      if options[:source_id]
        payload["sourceProject"] = { "id" => options[:source_id] }
        payload["copyAllAssociatedSettings"] = 'true'
      end

      response = client.post("/projects", :body => payload.to_json)
      new(response)
    end

    def initialize(options = {})
      @teamcity_id = options["id"]
      @name = options["name"]
      @parent_id = options["parentProjectId"]
    end

    def destroy!
      client.delete("/projects/id:#{teamcity_id}")
    end

    def description=(value)
      headers = { "Accept" => "text/plain", "Content-Type" => "text/plain" }
      client.put("/projects/id:#{teamcity_id}/description", :body => value, :headers => headers)
    end

    def description
      headers = { "Accept" => "text/plain", "Content-Type" => "text/plain" }
      client.get("/projects/id:#{teamcity_id}/description", :headers => headers, :format => :text).parsed_response
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teamcity_ruby-0.0.1 lib/teamcity_ruby/project.rb