Class: Rackspace::Scaling::Authentication
- Inherits:
-
Object
- Object
- Rackspace::Scaling::Authentication
- Defined in:
- lib/rackspace-scaling/authentication.rb
Constant Summary collapse
- ENDPOINT =
'https://identity.api.rackspacecloud.com/v2.0/tokens'
Instance Attribute Summary collapse
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #endpoints ⇒ Object
-
#initialize(username, api_key) ⇒ Authentication
constructor
A new instance of Authentication.
- #token ⇒ Object
Constructor Details
#initialize(username, api_key) ⇒ Authentication
Returns a new instance of Authentication.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rackspace-scaling/authentication.rb', line 10 def initialize(username, api_key) @user_name = username @payload = { :auth => { "RAX-KSKEY:apiKeyCredentials" => { 'username' => username, 'apiKey' => api_key } } } end |
Instance Attribute Details
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
6 7 8 |
# File 'lib/rackspace-scaling/authentication.rb', line 6 def user_name @user_name end |
Instance Method Details
#authenticate ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rackspace-scaling/authentication.rb', line 22 def authenticate @authenticated ||= begin resp = Typhoeus::Request.post(ENDPOINT, :body => @payload.to_json, :headers => {'Content-Type' => 'application/json'}) parsed_response = JSON.parse(resp.body) @token = parsed_response['access']['token']['id'] @service_catalog = {} parsed_response['access']['serviceCatalog'].each do |entry| @service_catalog[entry['name']] = { 'type' => entry['type'], 'endpoints' => {} } entry['endpoints'].each do |endpoint| @service_catalog[entry['name']]['endpoints'][endpoint['region']] = endpoint end end true end end |
#endpoints ⇒ Object
44 45 46 47 |
# File 'lib/rackspace-scaling/authentication.rb', line 44 def endpoints authenticate @service_catalog end |
#token ⇒ Object
49 50 51 52 |
# File 'lib/rackspace-scaling/authentication.rb', line 49 def token authenticate @token end |