Class: AdobeCRX::Client
- Inherits:
-
Object
- Object
- AdobeCRX::Client
- Defined in:
- lib/adobe_crx/client.rb
Instance Method Summary collapse
- #export_package(package, dest_file = nil) ⇒ Object
-
#get_child_resources(path) ⇒ Object
content methods.
- #get_node_structure(path, parent = nil) ⇒ Object
- #import_package(package_file) ⇒ Object
-
#initialize(host, port, username, password) ⇒ Client
constructor
A new instance of Client.
- #install_package(path) ⇒ Object
-
#list_packages ⇒ Object
package management methods.
- #remove_package(path) ⇒ Object
- #upload_package(package_file) ⇒ Object
Constructor Details
#initialize(host, port, username, password) ⇒ Client
Returns a new instance of Client.
43 44 45 46 47 48 |
# File 'lib/adobe_crx/client.rb', line 43 def initialize(host, port, username, password) @host = host @port = port @username = username @password = password end |
Instance Method Details
#export_package(package, dest_file = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/adobe_crx/client.rb', line 106 def export_package(package, dest_file = nil) #create the package req = Net::HTTP::Post.new('/crx/packmgr/service/.json/etc/packages/my_packages?cmd=create') req.basic_auth(@username, @password) params = Hash.new params['packageName'] = package.name params['groupName'] = 'automated-exports' req.set_form_data(params) create_result = nil Net::HTTP.start(@host, @port) do |http| response = http.request(req) create_result = JSON.parse(response.body) if !create_result['success'] raise AdobeCRX::CRXException, create_result['msg'] end end #add the filters req = Net::HTTP::Post::Multipart.new( '/crx/packmgr/update.jsp', '_charset_' => 'utf-8', 'path' => create_result['path'], 'packageName' => package.name, 'description' => '', 'groupName' => 'automated-exports', 'filter' => package.filters.to_json ) req.basic_auth(@username, @password) Net::HTTP.start(@host, @port) do |http| response = http.request(req) result = JSON.parse(response.body) if !result['success'] raise AdobeCRX::CRXException, create_result['msg'] end end #build the package req = Net::HTTP::Post.new("/crx/packmgr/service/.json#{create_result['path']}?cmd=build") req.basic_auth(@username, @password) Net::HTTP.start(@host, @port) do |http| http.read_timeout = 1800 response = http.request(req) result = JSON.parse(response.body) if !result['success'] raise AdobeCRX::CRXException, create_result['msg'] end end #download the package file_path = dest_file ? dest_file : "#{Dir.tmpdir}/#{package.name}" req = Net::HTTP::Get.new(create_result['path']) req.basic_auth(@username, @password) Net::HTTP.start(@host, @port) do |http| f = File.open(file_path, 'w') begin http.request(req) do |resp| resp.read_body do |segment| f.write(segment) end end ensure f.close() end end #delete the package remove_package(create_result['path']) file_path end |
#get_child_resources(path) ⇒ Object
content methods
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/adobe_crx/client.rb', line 195 def get_child_resources(path) if !@dav @dav = Net::DAV.new("http://#{@host}:#{@port}", :curl => false) @dav.credentials(@username, @password) end resources = Array.new @dav.find(path,:recursive=>false,:suppress_errors=>true) do | item | resources << item.uri.path.sub(/\/$/, '') end resources end |
#get_node_structure(path, parent = nil) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/adobe_crx/client.rb', line 208 def get_node_structure(path, parent = nil) if !@dav @dav = Net::DAV.new("http://#{@host}:#{@port}", :curl => false) @dav.credentials(@username, @password) end node = AdobeCRX::Node.new path if parent parent.children << node end begin node.size = @dav.propfind_size("#{path}/jcr:content") rescue Exception #nothing end @dav.find(path,:recursive=>false,:suppress_errors=>true) do | item | if path != item.uri.path get_node_structure(item.uri.path.sub(/\/$/, ''), node) end end node end |
#import_package(package_file) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/adobe_crx/client.rb', line 177 def import_package(package_file) upload_result = upload_package(package_file) if !upload_result['success'] || upload_result['path'] == nil raise AdobeCRX::CRXException, "Error uploading package: #{upload_result['msg']}" end install_result = install_package(upload_result['path']) if !install_result['success'] raise AdobeCRX::CRXException, "Error installing package: #{install_result['msg']}" end remove_package(upload_result['path']) result = "successfully deployed package at #{package_file}:" upload_result.each do |key, value| result << "\n #{key}: #{value}" end result end |
#install_package(path) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/adobe_crx/client.rb', line 83 def install_package(path) req = Net::HTTP::Post.new("/crx/packmgr/service/.json#{path}?cmd=install") req.basic_auth(@username, @password) result = Hash.new Net::HTTP.start(@host, @port) do |http| http.read_timeout = 500 response = http.request(req) result.merge! JSON.parse(response.body) end result end |
#list_packages ⇒ Object
package management methods
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/adobe_crx/client.rb', line 51 def list_packages xml_data = Net::HTTP.get_response(URI.parse("http://#{@username}:#{@password}@#{@host}:#{@port}/crx/packmgr/service.jsp?cmd=ls")).body doc = REXML::Document.new(xml_data) packages = Array.new doc.elements.each("//response/data/packages/package") do |ele| package = Hash.new packages << package ele.elements.each do |child| package[child.name] = child.text end end return packages end |
#remove_package(path) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/adobe_crx/client.rb', line 95 def remove_package(path) req = Net::HTTP::Post.new("/crx/packmgr/service/.json#{path}?cmd=delete") req.basic_auth(@username, @password) result = Hash.new Net::HTTP.start(@host, @port) do |http| response = http.request(req) result.merge! JSON.parse(response.body) end result end |
#upload_package(package_file) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/adobe_crx/client.rb', line 66 def upload_package(package_file) results = AdobeCRX::PackageUtils.get_package_properties(package_file) File.open(package_file) do |package| req = Net::HTTP::Post::Multipart.new( '/crx/packmgr/service/.json/?cmd=upload', 'force' => 'true', 'package' => UploadIO.new(package, 'application/zip', File.basename(package_file)) ) req.basic_auth(@username, @password) Net::HTTP.start(@host, @port) do |http| response = http.request(req) results.merge! JSON.parse(response.body) end end results end |