poweriq_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +47 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/bin/poweriq_client +21 -0
- data/lib/poweriq_client/configuration.rb +32 -0
- data/lib/poweriq_client/resource/base.rb +86 -0
- data/lib/poweriq_client/resource/outlet.rb +6 -0
- data/lib/poweriq_client/resource/system_info.rb +7 -0
- data/lib/poweriq_client/resource.rb +7 -0
- data/lib/poweriq_client/version.rb +9 -0
- data/lib/poweriq_client.rb +9 -0
- data/spec/poweriq_client_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +151 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p180@poweriq_client"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]] ; then
|
45
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
46
|
+
# fi
|
47
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.9)
|
5
|
+
awesome_print (0.4.0)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.6.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
mime-types (1.17.2)
|
13
|
+
rake (0.9.2.2)
|
14
|
+
rcov (0.9.11)
|
15
|
+
rest-client (1.6.7)
|
16
|
+
mime-types (>= 1.16)
|
17
|
+
rspec (2.3.0)
|
18
|
+
rspec-core (~> 2.3.0)
|
19
|
+
rspec-expectations (~> 2.3.0)
|
20
|
+
rspec-mocks (~> 2.3.0)
|
21
|
+
rspec-core (2.3.1)
|
22
|
+
rspec-expectations (2.3.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.3.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
activesupport (= 3.0.9)
|
31
|
+
awesome_print
|
32
|
+
bundler (~> 1.0.0)
|
33
|
+
jeweler (~> 1.6.4)
|
34
|
+
rcov
|
35
|
+
rest-client
|
36
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Raritan, INC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= poweriq_client
|
2
|
+
|
3
|
+
Power IQ Rest API client for Power IQ 3.1
|
4
|
+
|
5
|
+
== Contributing to poweriq_client
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Ratian, INC. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'poweriq_client'
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "poweriq_client"
|
19
|
+
gem.homepage = "http://github.com/talbright/poweriq_client"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Power IQ Rest API client for Power IQ 3.1}
|
22
|
+
gem.description = %Q{Power IQ Rest API client for Power IQ 3.1}
|
23
|
+
gem.email = "trent.albright@raritan.com"
|
24
|
+
gem.authors = ["Trent Albright"]
|
25
|
+
gem.version = PowerIQ::Version::STRING
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "poweriq_client #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/bin/poweriq_client
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'poweriq_client'
|
7
|
+
require 'irb'
|
8
|
+
require 'irb/completion'
|
9
|
+
|
10
|
+
if File.exists? ".irbrc"
|
11
|
+
ENV['IRBRC'] = ".irbrc"
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
PowerIQ::Configuration.load_configuration("default")
|
15
|
+
rescue
|
16
|
+
end
|
17
|
+
|
18
|
+
ARGV.clear
|
19
|
+
IRB.start
|
20
|
+
|
21
|
+
exit!
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PowerIQ
|
2
|
+
module Configuration
|
3
|
+
DEFAULT_YAML_CONFIG = File.join(ENV['HOME'],".poweriq_client")
|
4
|
+
class << self
|
5
|
+
def load_configuration(key,file=DEFAULT_YAML_CONFIG)
|
6
|
+
config = YAML.load(File.read(file))
|
7
|
+
if(config && config.has_key?(key))
|
8
|
+
PowerIQ::Configuration.configure(config[key])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def configure(options=nil,&block)
|
12
|
+
unless(options.nil?)
|
13
|
+
self.user = options["user"]
|
14
|
+
self.password = options["password"]
|
15
|
+
self.host = options["host"]
|
16
|
+
end
|
17
|
+
if(block_given?)
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def user=(user)
|
22
|
+
PowerIQ::Resource::Base.user = user
|
23
|
+
end
|
24
|
+
def password=(password)
|
25
|
+
PowerIQ::Resource::Base.password = password
|
26
|
+
end
|
27
|
+
def host=(host)
|
28
|
+
PowerIQ::Resource::Base.host = host
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module PowerIQ
|
4
|
+
module Resource
|
5
|
+
|
6
|
+
module ResponseHandler
|
7
|
+
def self.create(resource)
|
8
|
+
Proc.new { |response,request,result,&block|
|
9
|
+
resource.request = request
|
10
|
+
resource.response = response
|
11
|
+
body = response.return!(request, result, &block)
|
12
|
+
if(body.kind_of?(String))
|
13
|
+
ActiveSupport::JSON.decode(body)
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Base < RestClient::Resource
|
20
|
+
|
21
|
+
attr_accessor :request,:response
|
22
|
+
|
23
|
+
def initialize(url=nil,options={}, backwards_compatibility=nil, &block)
|
24
|
+
base_headers = { :content_type => 'application/json', :accept=>'application/json' }
|
25
|
+
if(options.has_key?(:headers))
|
26
|
+
options[:headers].merge!(base_headers)
|
27
|
+
else
|
28
|
+
options[:headers] = base_headers
|
29
|
+
end
|
30
|
+
options[:user] = self.class.user unless(options.has_key?(:user))
|
31
|
+
options[:password] = self.class.password unless(options.has_key?(:password))
|
32
|
+
unless(block_given?)
|
33
|
+
block = ResponseHandler.create(self)
|
34
|
+
end
|
35
|
+
modified_url = if(url.nil?)
|
36
|
+
self.class.resource_url
|
37
|
+
elsif(url=~%r{^https://})
|
38
|
+
url
|
39
|
+
else
|
40
|
+
self.class.resource_url + url
|
41
|
+
end
|
42
|
+
super(modified_url,options,backwards_compatibility,&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_writer :host,:singular,:user,:password
|
47
|
+
def host
|
48
|
+
if(self == Base)
|
49
|
+
@host
|
50
|
+
else
|
51
|
+
@host || Base.host
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def user
|
55
|
+
if(self == Base)
|
56
|
+
@user
|
57
|
+
else
|
58
|
+
@user || Base.user
|
59
|
+
end
|
60
|
+
end
|
61
|
+
def password
|
62
|
+
if(self == Base)
|
63
|
+
@password
|
64
|
+
else
|
65
|
+
@password || Base.password
|
66
|
+
end
|
67
|
+
end
|
68
|
+
def resource_name(pluralize=false)
|
69
|
+
base = self.name.demodulize
|
70
|
+
if(pluralize)
|
71
|
+
base = base.pluralize
|
72
|
+
end
|
73
|
+
base.underscore
|
74
|
+
end
|
75
|
+
def resource_url
|
76
|
+
"https://#{self.host}/api/v2/#{self.resource_name(!self.singular?)}"
|
77
|
+
end
|
78
|
+
def singular?
|
79
|
+
@singular
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'poweriq_client'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poweriq_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trent Albright
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-02 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: awesome_print
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 3.0.9
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.4
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rcov
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
description: Power IQ Rest API client for Power IQ 3.1
|
93
|
+
email: trent.albright@raritan.com
|
94
|
+
executables:
|
95
|
+
- poweriq_client
|
96
|
+
extensions: []
|
97
|
+
|
98
|
+
extra_rdoc_files:
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .rspec
|
104
|
+
- .rvmrc
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.rdoc
|
109
|
+
- Rakefile
|
110
|
+
- bin/poweriq_client
|
111
|
+
- lib/poweriq_client.rb
|
112
|
+
- lib/poweriq_client/configuration.rb
|
113
|
+
- lib/poweriq_client/resource.rb
|
114
|
+
- lib/poweriq_client/resource/base.rb
|
115
|
+
- lib/poweriq_client/resource/outlet.rb
|
116
|
+
- lib/poweriq_client/resource/system_info.rb
|
117
|
+
- lib/poweriq_client/version.rb
|
118
|
+
- spec/poweriq_client_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: http://github.com/talbright/poweriq_client
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 4101020090088911256
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.8
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Power IQ Rest API client for Power IQ 3.1
|
150
|
+
test_files: []
|
151
|
+
|