Sha256: e020e99e1326d96fb97cd0d6085507d69ad767b5d5043a05596b45c35593d814

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module PivotalTracker
  class Client

    class NoToken < StandardError; end

    class << self
      attr_writer :use_ssl, :token

      def use_ssl
        @use_ssl || false
      end

      def token(username, password, method='post')
        return @token if @token
        response = if method == 'post'
          RestClient.post 'https://www.pivotaltracker.com/services/v3/tokens/active', :username => username, :password => password
        else
          RestClient.get "https://#{username}:#{password}@www.pivotaltracker.com/services/v3/tokens/active"
        end
        @token= Nokogiri::XML(response.body).search('guid').inner_html
      end

      # this is your connection for the entire module
      def connection(options={})
        raise NoToken if @token.to_s.empty?

        @connections ||= {}

        @connections[@token] ||= RestClient::Resource.new("#{protocol}://www.pivotaltracker.com/services/v3", :headers => {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'})
      end

      protected

        def protocol
          use_ssl ? 'https' : 'http'
        end

    end

  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
pivotal-tracker-0.4.1 lib/pivotal-tracker/client.rb
pivotal-tracker-0.4.0 lib/pivotal-tracker/client.rb
tsenart-pivotal-tracker-0.5.0 lib/pivotal-tracker/client.rb
tsenart-pivotal-tracker-0.4.0 lib/pivotal-tracker/client.rb