Class: PivotalAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-tracker-api/client.rb

Defined Under Namespace

Classes: NoToken

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



8
9
10
# File 'lib/pivotal-tracker-api/client.rb', line 8

def password=(value)
  @password = value
end

.token=(val) ⇒ Object (writeonly)

Sets the attribute token

Parameters:

  • value

    the value to set the attribute token to.



8
9
10
# File 'lib/pivotal-tracker-api/client.rb', line 8

def token=(value)
  @token = value
end

.username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



8
9
10
# File 'lib/pivotal-tracker-api/client.rb', line 8

def username=(value)
  @username = value
end

Class Method Details

.api_hostObject



68
69
70
# File 'lib/pivotal-tracker-api/client.rb', line 68

def api_host
  @api_host ||= 'https://www.pivotaltracker.com'
end

.api_ssl_hostObject



64
65
66
# File 'lib/pivotal-tracker-api/client.rb', line 64

def api_ssl_host
  "https://#{@username}:#{CGI.escape(@password)}@www.pivotaltracker.com"
end

.clear_connectionsObject



60
61
62
# File 'lib/pivotal-tracker-api/client.rb', line 60

def clear_connections
  @connections = nil
end

.connectionObject

Raises:



48
49
50
51
52
# File 'lib/pivotal-tracker-api/client.rb', line 48

def connection
  raise NoToken if @token.to_s.empty?
  @connections ||= {}
  cached_connection? ? cached_connection : new_connection
end

.get(path) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/pivotal-tracker-api/client.rb', line 10

def get(path)
  begin
    set_response_headers(connection["#{api_version}#{path}"].get)
  rescue
    puts "Encountered Error in get: #{$!}"
    clear_connections
    set_response_headers(connection["#{api_version}#{path}"].get)
  end
end

.get_with_caching(path) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/pivotal-tracker-api/client.rb', line 34

def get_with_caching(path)
  begin
    connection["#{api_version}#{path}"].get
  rescue
    puts "Encountered Error in get_with_caching: #{$!}"
    clear_connections
    connection["#{api_version}#{path}"].get
  end
end

.put(path, updates = {}) ⇒ Object



44
45
46
# File 'lib/pivotal-tracker-api/client.rb', line 44

def put(path, updates={})
  set_response_headers(connection["#{api_version}#{path}"].put(updates))
end

.ssl_connectionObject

Raises:



54
55
56
57
58
# File 'lib/pivotal-tracker-api/client.rb', line 54

def ssl_connection
  raise NoToken if @username.to_s.empty?
  @connections ||= {}
  cached_ssl_connection? ? cached_ssl_connection : new_ssl_connection
end

.ssl_get(path) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pivotal-tracker-api/client.rb', line 20

def ssl_get(path)
  raise ArgumentError.new("missing required fields :username and :password. " \
                          "Set these using PivotalAPI::Client.username = USERNAME " \
                          "and PivotalAPI::Client.password = PASSWORD.") unless @username && @password
  begin
    puts "ssl_connection: #{ssl_connection}"
    set_response_headers(ssl_connection["#{api_version}#{path}"].get)
  rescue
    puts "Encountered Error in ssl_get: #{$!}"
    clear_connections
    set_response_headers(ssl_connection["#{api_version}#{path}"].get)
  end
end