Class: PivotalAPI::Client
- Inherits:
-
Object
- Object
- PivotalAPI::Client
- Defined in:
- lib/pivotal-tracker-api/client.rb
Defined Under Namespace
Classes: NoToken
Class Attribute Summary collapse
-
.password ⇒ Object
writeonly
Sets the attribute password.
-
.token ⇒ Object
writeonly
Sets the attribute token.
-
.username ⇒ Object
writeonly
Sets the attribute username.
Class Method Summary collapse
- .api_host ⇒ Object
- .api_ssl_host ⇒ Object
- .clear_connections ⇒ Object
- .connection ⇒ Object
- .get(path) ⇒ Object
- .get_with_caching(path) ⇒ Object
- .put(path, updates = {}) ⇒ Object
- .ssl_connection ⇒ Object
- .ssl_get(path) ⇒ Object
Class Attribute Details
.password=(value) ⇒ Object (writeonly)
Sets the attribute password
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
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
8 9 10 |
# File 'lib/pivotal-tracker-api/client.rb', line 8 def username=(value) @username = value end |
Class Method Details
.api_host ⇒ Object
68 69 70 |
# File 'lib/pivotal-tracker-api/client.rb', line 68 def api_host @api_host ||= 'https://www.pivotaltracker.com' end |
.api_ssl_host ⇒ Object
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_connections ⇒ Object
60 61 62 |
# File 'lib/pivotal-tracker-api/client.rb', line 60 def clear_connections @connections = nil end |
.connection ⇒ Object
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_connection ⇒ Object
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
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 |