Class: SPDocgen::Protocol
- Inherits:
-
Object
- Object
- SPDocgen::Protocol
- Defined in:
- lib/spdocgen/protocol.rb
Class Method Summary collapse
Instance Method Summary collapse
- #download(parsed_uri) ⇒ Object
-
#initialize(config) ⇒ Protocol
constructor
A new instance of Protocol.
- #poll(uri) ⇒ Object
- #submit(xml) ⇒ Object
Constructor Details
#initialize(config) ⇒ Protocol
Returns a new instance of Protocol.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spdocgen/protocol.rb', line 10 def initialize(config) @base_url = config['base_url'] @render_path = config['render_path'] @username = config['username'] @password = config['password'] url = URI.parse @base_url @http = Net::HTTP.new url.host, url.port @http.use_ssl = (url.scheme =~ /https/i) @downloaders = {} end |
Class Method Details
.instance ⇒ Object
6 7 8 |
# File 'lib/spdocgen/protocol.rb', line 6 def self.instance @instance ||= self.new Configuration.current end |
Instance Method Details
#download(parsed_uri) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spdocgen/protocol.rb', line 23 def download(parsed_uri) with_downloader_for(parsed_uri) do |http| req = Net::HTTP::Get.new parsed_uri.request_uri req['Accept'] = '*/*' req.basic_auth @username, @password response = http.request(req) raise "Unable to download: #{parsed_uri.to_s} .. Response was #{response.code} #{response.message} : #{response.body ? response.body : ''} - request is #{req.to_s}" unless response.is_a? Net::HTTPOK SPDocgen::DownloadResponse.new response.body, response.content_type, response['content-encoding'], response['content-disposition'] end end |
#poll(uri) ⇒ Object
45 46 47 48 |
# File 'lib/spdocgen/protocol.rb', line 45 def poll(uri) request = Net::HTTP::Get.new uri SPDocgen::StatusResponse.new do_request(request).body end |
#submit(xml) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/spdocgen/protocol.rb', line 37 def submit(xml) request = Net::HTTP::Post.new render_url request.body = xml request['Content-Type'] = 'application/xml' SPDocgen::RenderResponse.new do_request(request).body end |