poweriq_client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,7 +23,7 @@ The Power IQ client comes with a interactive console. To run the console:
23
23
  -p, --password [PASSWORD] Password for authentication
24
24
  -s, --server [HOST] Host name or IP of Power IQ
25
25
 
26
- ==== Console Configuration
26
+ ==== Configuration
27
27
 
28
28
  Create a file named .poweriq_client in your home directory. The contents of the file
29
29
  should look similiar to below, adjusted to your Power IQ server:
@@ -33,13 +33,13 @@ should look similiar to below, adjusted to your Power IQ server:
33
33
  user: admin
34
34
  password: raritan
35
35
 
36
- If you do not use a configuration file, or through the command line options above, you'll
36
+ If you do not use a configuration file, or the command line options above, you'll
37
37
  need to provide the configuration manually:
38
38
 
39
39
  % poweriq_client
40
40
  >> PowerIQ::Configuration.configure("user"=>"foo","password"=>"bar","host"=>"vm150")
41
41
 
42
- ==== Console Examples
42
+ ==== Examples
43
43
 
44
44
  Retrieve all outlets:
45
45
  >> outlets_resource = PowerIQ::Resource::Outlet.new
@@ -58,6 +58,93 @@ Update an outlet:
58
58
  >> outlet['outlet']['outlet_name'] = "New Name"
59
59
  >> outlet_resource.put outlet.to_json
60
60
 
61
+ === Error Handling
62
+
63
+ When an error occurs with API calls, the Power IQ server will return an appropriate HTTP response code, and include
64
+ a json response with error details. On the client side, an exception is thrown. Either the exception or the
65
+ resource object can be used to reveal details about what went wrong:
66
+
67
+ >> outlet_resource = PowerIQ::Resource::Outlet.new('/381')
68
+ https://vm163/api/v2/outlets/381
69
+ >> outlet_json = outlet_resource.get
70
+ {
71
+ "outlet" => {
72
+ "id" => 381,
73
+ "outlet_id" => 11,
74
+ "outlet_name" => "Outlet 11",
75
+ "device_id" => nil,
76
+ "state" => "ON",
77
+ "pdu_id" => 40,
78
+ "reading" => {}
79
+ }
80
+ }
81
+ >> outlet_json['outlet']['outlet_name']="foo"
82
+ "foo"
83
+ >> outlet_resource.put outlet_json.to_json
84
+ RestClient::UnprocessableEntity: 422 Unprocessable Entity
85
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
86
+ from /Users/tba/Workspaces/local/poweriq_client/lib/poweriq_client/resource/base.rb:11:in `block in create'
87
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:228:in `call'
88
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:228:in `process_result'
89
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
90
+ from /Users/tba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:627:in `start'
91
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
92
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
93
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
94
+ from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/resource.rb:76:in `put'
95
+ from (irb):4
96
+ from bin/poweriq_client:66:in `<main>'
97
+
98
+ The resource will always hold the last response from the latest rest invocation:
99
+
100
+ >> outlet_resource.response.json
101
+ {
102
+ "error" => "Job::JobError",
103
+ "messages" => [
104
+ [0] "Job(ID:5) with 1 error(s) and status COMPLETED completed",
105
+ [1] "Confirmed existence of foo",
106
+ [2] "Confirmed existence of 192.168.45.234 for outlet foo.",
107
+ [3] "Retrieved plugin for 192.168.45.234.",
108
+ [4] "Failed to set outlet id: 381 label on PDU 192.168.45.234. PowerIQ was unable to reach 192.168.45.234."
109
+ ],
110
+ "job" => {
111
+ "description" => nil,
112
+ "end_time" => "2011/11/06 00:56:47 +0000",
113
+ "has_errors" => true,
114
+ "id" => 5,
115
+ "start_time" => "2011/11/06 00:56:28 +0000",
116
+ "status" => "COMPLETED",
117
+ "user_id" => 1
118
+ },
119
+ "trace" => "/var/oculan/home/tba/rails/src/lib/messaging/job_polling.rb:31:...."
120
+ }
121
+
122
+ You can also catch the exception, and the exception will have the response object in it:
123
+
124
+ >> exc = nil
125
+ >> begin outlet_resource.put outlet_json.to_json; rescue => exc; end
126
+ >> exc.response.json
127
+ {
128
+ "error" => "Job::JobError",
129
+ "messages" => [
130
+ [0] "Job(ID:5) with 1 error(s) and status COMPLETED completed",
131
+ [1] "Confirmed existence of foo",
132
+ [2] "Confirmed existence of 192.168.45.234 for outlet foo.",
133
+ [3] "Retrieved plugin for 192.168.45.234.",
134
+ [4] "Failed to set outlet id: 381 label on PDU 192.168.45.234. PowerIQ was unable to reach 192.168.45.234."
135
+ ],
136
+ "job" => {
137
+ "description" => nil,
138
+ "end_time" => "2011/11/06 00:56:47 +0000",
139
+ "has_errors" => true,
140
+ "id" => 5,
141
+ "start_time" => "2011/11/06 00:56:28 +0000",
142
+ "status" => "COMPLETED",
143
+ "user_id" => 1
144
+ },
145
+ "trace" => "/var/oculan/home/tba/rails/src/lib/messaging/job_polling.rb:31:...."
146
+ }
147
+
61
148
  == Development
62
149
 
63
150
  The Power IQ rest client uses the rest-client gem, with some
@@ -8,10 +8,8 @@ module PowerIQ
8
8
  Proc.new { |response,request,result,&block|
9
9
  resource.request = request
10
10
  resource.response = response
11
- body = response.return!(request, result, &block)
12
- if(body.kind_of?(String))
13
- ActiveSupport::JSON.decode(body)
14
- end
11
+ response.return!(request, result, &block)
12
+ response.json
15
13
  }
16
14
  end
17
15
  end
@@ -0,0 +1,12 @@
1
+ module RestClient
2
+ module Response
3
+
4
+ def json
5
+ if(!@json && headers[:content_type]=~%r{application/json} && !body.nil? && body.size>0)
6
+ @json = ActiveSupport::JSON.decode(body)
7
+ end
8
+ @json
9
+ end
10
+
11
+ end
12
+ end
@@ -1,9 +1,8 @@
1
1
  module PowerIQ
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
-
7
6
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
7
  end
9
8
  end
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'active_support/core_ext'
3
+ require 'poweriq_client/response'
3
4
 
4
5
  module PowerIQ
5
6
  autoload :Version, "poweriq_client/version"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{poweriq_client}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Trent Albright}]
12
- s.date = %q{2011-11-03}
12
+ s.date = %q{2011-11-06}
13
13
  s.description = %q{Power IQ Rest API client for Power IQ 3.1}
14
14
  s.email = %q{trent.albright@raritan.com}
15
15
  s.executables = [%q{poweriq_client}]
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
56
56
  "lib/poweriq_client/resource/sensor_reading.rb",
57
57
  "lib/poweriq_client/resource/sensor_readings_rollup.rb",
58
58
  "lib/poweriq_client/resource/system_info.rb",
59
+ "lib/poweriq_client/response.rb",
59
60
  "lib/poweriq_client/version.rb",
60
61
  "poweriq_client.gemspec",
61
62
  "spec/poweriq_client_spec.rb",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: poweriq_client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Trent Albright
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-03 00:00:00 Z
13
+ date: 2011-11-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -148,6 +148,7 @@ files:
148
148
  - lib/poweriq_client/resource/sensor_reading.rb
149
149
  - lib/poweriq_client/resource/sensor_readings_rollup.rb
150
150
  - lib/poweriq_client/resource/system_info.rb
151
+ - lib/poweriq_client/response.rb
151
152
  - lib/poweriq_client/version.rb
152
153
  - poweriq_client.gemspec
153
154
  - spec/poweriq_client_spec.rb
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
166
  requirements:
166
167
  - - ">="
167
168
  - !ruby/object:Gem::Version
168
- hash: -4058341116595240085
169
+ hash: -3473045824434038177
169
170
  segments:
170
171
  - 0
171
172
  version: "0"