Sha256: c3bd50a7d131ef0928b02472ea150c98948662e17f74a72364b81af586baa237

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require 'rubygems'
require 'active_support'
require 'active_resource'

module PivotalAPI
  class Error < StandardError; end
  class << self
    # Sets up basic authentication credentials for all the resources.
    def authenticate(user, password)
      Token.user = user
      Token.password = password
      self.token = Token.get(:active)['guid']
      Token.user = nil
      Token.password = nil
    end

    # Sets the API token for all the resources.
    def token=(value)
      resources.each do |klass|
        klass.headers['X-TrackerToken'] = value
      end
      @token = value
    end

    def resources
      @resources ||= []
    end
  end

  class Base < ActiveResource::Base
    self.site = 'https://www.pivotaltracker.com/services/v3/'
    def self.inherited(base)
      PivotalAPI.resources << base
      super
    end
  end

  class Project < Base
    def stories(options = {})
      Story.find(:all, :params => options.merge!(:project_id => self.id))
    end
  end
  
  class Token < Base
  end
  
  class Activity < Base
    self.site += 'projects/:project_id/'
  end
  
  class Membership < Base
    self.site += 'projects/:project_id/'
  end
  
  class Iteration < Base
    self.site += 'projects/:project_id/'
  end
  
  class Story < Base
    self.site += 'projects/:project_id/'
  end
  
  class Note < Base
    self.site += 'projects/:project_id/stories/:story_id/'
  end
  
  class Task < Base
    self.site += 'projects/:project_id/stories/:story_id/'
  end
  
  class AllActivity < Base
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ticketmaster-pivotal-0.4.9 lib/pivotal/pivotal-api.rb
ticketmaster-pivotal-0.3.9 lib/pivotal/pivotal-api.rb
ticketmaster-pivotal-0.3.8 lib/pivotal/pivotal-api.rb
ticketmaster-pivotal-0.3.7 lib/pivotal/pivotal-api.rb
ticketmaster-pivotal-0.3.6 lib/pivotal/pivotal-api.rb
ticketmaster-pivotal-0.3.5 lib/pivotal/pivotal-api.rb