rightstuff 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/rightstuff.rb +25 -22
  3. metadata +3 -3
@@ -39,4 +39,4 @@ It should be of the form:
39
39
  = TODO
40
40
 
41
41
  * Cache connections
42
- * Don't query inactive serevrs for settings
42
+
@@ -1,5 +1,3 @@
1
- #!ruby
2
-
3
1
  require 'rubygems' if RUBY_VERSION < '1.9'
4
2
  require 'yaml'
5
3
  require 'net/https'
@@ -11,7 +9,7 @@ module Rightstuff
11
9
  module VERSION #:nodoc:
12
10
  MAJOR = 0
13
11
  MINOR = 0
14
- TINY = 1
12
+ TINY = 2
15
13
 
16
14
  STRING = [ MAJOR, MINOR, TINY ].join('.')
17
15
  end
@@ -51,10 +49,10 @@ module Rightstuff
51
49
  node.class == Nokogiri::XML::Element ? node : nil
52
50
  end
53
51
  elements.compact!
54
- elements.reduce({}) do | memo, element |
52
+ elements.reduce( {} ) do | memo, element |
55
53
  name = element.name
56
54
  name.gsub!( /-/, '_' )
57
- memo[ name.intern ] = element.children[0].to_s
55
+ memo[ name.intern ] = element.children[ 0 ].to_s
58
56
  memo
59
57
  end
60
58
  end
@@ -73,7 +71,8 @@ module Rightstuff
73
71
  class Server < Base
74
72
 
75
73
  def initialize( client, item )
76
- @settings = false
74
+ @settings = nil
75
+ @inputs = nil
77
76
  super
78
77
  end
79
78
 
@@ -84,6 +83,7 @@ module Rightstuff
84
83
  def method_missing( name , *args, &block )
85
84
  result = super
86
85
  return result unless result.nil?
86
+ return nil unless @attributes[ :state ] == 'operational'
87
87
  settings unless @settings
88
88
  return @attributes[ name ]
89
89
  end
@@ -93,15 +93,17 @@ module Rightstuff
93
93
  end
94
94
 
95
95
  def inputs
96
+ return @inputs if @inputs
96
97
  # Add inputs to instance data
97
98
  # @client.get( @attributes[ 'href' ] )
98
99
  end
99
100
 
100
101
  def settings
101
- doc = @client.get_rest( 'servers/' + id + '/settings' )
102
- xml = Nokogiri::XML( doc )
103
- @attributes.merge!( Base.extract_attributes( xml.children ) )
104
- @settings = true
102
+ return @settings if @settings
103
+ doc = @client.get_rest( 'servers/' + id + '/settings' )
104
+ xml = Nokogiri::XML( doc )
105
+ @settings = Base.extract_attributes( xml.children )
106
+ @attributes.merge!( settings )
105
107
  end
106
108
 
107
109
  end
@@ -109,29 +111,29 @@ module Rightstuff
109
111
  class Client
110
112
 
111
113
  def initialize( options = {} )
112
- @base_url = 'https://my.rightscale.com/api/acct'
113
114
  @username = options[ :username ] or raise 'no username supplied'
114
115
  @password = options[ :password ] or raise 'no password supplied'
115
116
  @account = options[ :account ] or raise 'no account id supplied'
116
117
  @account = @account.to_s
118
+
119
+ @base_url = 'https://my.rightscale.com/api/acct'
120
+ url = URI.parse( @base_url )
121
+ @connection = Net::HTTP.new( url.host, url.port )
122
+ @connection.use_ssl = true
123
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
117
124
  end
118
125
 
119
126
  def get_rest( rest )
120
127
  get( account_url( rest ) )
121
128
  end
122
129
 
123
- def get( path )
124
- address = path
125
- url = URI.parse( address )
126
- con = Net::HTTP.new( url.host, url.port )
127
- con.use_ssl = true
128
- con.verify_mode = OpenSSL::SSL::VERIFY_NONE
129
-
130
- request = Net::HTTP::Get.new( url.request_uri )
130
+ def get( address )
131
+ url = URI.parse( address )
132
+ request = Net::HTTP::Get.new( url.request_uri )
131
133
  request.add_field( 'X-API-VERSION', '1.0' )
132
134
  request.basic_auth @username, @password
133
135
 
134
- response = con.request( request )
136
+ response = @connection.request( request )
135
137
 
136
138
  case response.code
137
139
  when '200'
@@ -142,8 +144,9 @@ module Rightstuff
142
144
  end
143
145
 
144
146
  def servers
145
- body = Nokogiri::XML( get_rest( 'servers' ) )
146
- Server.load_collection( self, body )
147
+ return @servers if @servers
148
+ body = Nokogiri::XML( get_rest( 'servers' ) )
149
+ @servers = Server.load_collection( self, body )
147
150
  end
148
151
 
149
152
  def account_url( rest )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightstuff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates