Sha256: 2452e802298df28762fdff98ffa4af71881210e3724cc61db37729ac81ab071f

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

module Datapimp::Sources
  class Pivotal < Datapimp::Sources::Base
    def initialize(args, options)
      @project_id = args.shift
      @story_id   = args.shift
      @options    = options.to_mash

      require 'pivotal-tracker' unless defined?(PivotalTracker)
      PivotalTracker::Client.token = Datapimp.config.pivotal_access_token
    end

    def all
      %w(user_activity project_activity project_stories).each_with_object({}) do |slice, memo|
        memo[slice] = send(slice)
      end
    end

    def to_s
      all
    end

    def user_activity
      @_user_activity ||= PivotalTracker::Activity.all(nil, limit_params).map {|a| jsonify(a) }
    end

    def project_activity
      project.activities.all(limit_params).map {|a| jsonify(a) }
    end

    def project_stories
      stories = project.stories.all(limit_params)

      # add notes for each story and convert the objects to hashes
      stories.map do |story|
        story_hash = jsonify(story)
        story_hash[:notes] = story.notes.all(limit_params).map {|a| jsonify(a) }
        story_hash
      end
    end

    def project_story_notes
      notes = project.stories.find(@story_id).notes.all(limit_params)
      notes.map {|a| jsonify(a) }
    end

    private

    def project
      @_project ||= PivotalTracker::Project.find(@project_id)
    end

    def limit_params
      Hash.new.tap do |h|
        h[:limit]   = @options.limit  if @options.limit
        h[:offset]  = @options.offset if @options.offset
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
datapimp-1.2.11 lib/datapimp/sources/pivotal.rb
datapimp-1.2.10 lib/datapimp/sources/pivotal.rb
datapimp-1.2.9 lib/datapimp/sources/pivotal.rb
datapimp-1.2.8 lib/datapimp/sources/pivotal.rb
datapimp-1.2.7 lib/datapimp/sources/pivotal.rb
datapimp-1.2.6 lib/datapimp/sources/pivotal.rb
datapimp-1.2.5 lib/datapimp/sources/pivotal.rb
datapimp-1.2.4 lib/datapimp/sources/pivotal.rb
datapimp-1.2.3 lib/datapimp/sources/pivotal.rb