Sha256: 36f587a1d773aab375932a107f962827c5510fed758dab3ba523e6dd3d5a91fc

Contents?: true

Size: 1014 Bytes

Versions: 4

Compression:

Stored size: 1014 Bytes

Contents

module PivotalTracker
  class Client

    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={})
        @connection ||= 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
topprospect-pivotal-tracker-0.1.1 lib/pivotal-tracker/client.rb
topprospect-pivotal-tracker-0.0.1 lib/pivotal-tracker/client.rb
pivotal-tracker-0.3.1 lib/pivotal-tracker/client.rb
pivotal-tracker-0.3.0 lib/pivotal-tracker/client.rb