Class: ConvertApi::ResultFile
- Inherits:
-
Object
- Object
- ConvertApi::ResultFile
- Defined in:
- lib/convert_api/result_file.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Instance Method Summary collapse
- #contents ⇒ Object
- #filename ⇒ Object
- #http(params = {}) ⇒ Object
-
#initialize(info) ⇒ ResultFile
constructor
A new instance of ResultFile.
- #save(path) ⇒ Object
- #size ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(info) ⇒ ResultFile
Returns a new instance of ResultFile.
8 9 10 |
# File 'lib/convert_api/result_file.rb', line 8 def initialize(info) @info = info end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/convert_api/result_file.rb', line 6 def info @info end |
Instance Method Details
#contents ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/convert_api/result_file.rb', line 34 def contents request = Net::HTTP::Get.new(url, Client::DEFAULT_HEADERS) response = http({}).request(request) status = response.code.to_i if status != 200 headers = { } response.each_header{|key,value| headers[key] = value } raise( ClientError, :status => status, :body => response.body, :headers => headers ) end response.body end |
#filename ⇒ Object
16 17 18 |
# File 'lib/convert_api/result_file.rb', line 16 def filename info['FileName'] end |
#http(params = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/convert_api/result_file.rb', line 24 def http(params = {}) http = Net::HTTP.new(base_uri.host, base_uri.port) http.open_timeout = config.connect_timeout http.read_timeout = params[:read_timeout] || config.read_timeout http.use_ssl = base_uri.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl && RUBY_VERSION == '1.8.7' # http.set_debug_output $stderr http end |
#save(path) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/convert_api/result_file.rb', line 54 def save(path) path = File.join(path, filename) if File.directory?(path) File.open(path, 'w') do |f| f.write contents end path end |
#size ⇒ Object
20 21 22 |
# File 'lib/convert_api/result_file.rb', line 20 def size info['FileSize'] end |
#url ⇒ Object
12 13 14 |
# File 'lib/convert_api/result_file.rb', line 12 def url info['Url'] end |