Class: Saaspose::Utils
- Inherits:
-
Object
- Object
- Saaspose::Utils
- Defined in:
- lib/saaspose/utils.rb
Constant Summary collapse
- DIGEST =
OpenSSL::Digest::Digest.new('sha1')
Class Method Summary collapse
- .call(uri, options = nil) ⇒ Object
- .call_and_parse(uri, options = nil) ⇒ Object
- .call_and_save(uri, options, file) ⇒ Object
- .log(severity, message) ⇒ Object
- .save_file(response_stream, local_file) ⇒ Object
- .sign(uri, options = nil) ⇒ Object
Class Method Details
.call(uri, options = nil) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/saaspose/utils.rb', line 26 def call(uri, =nil) signed_url = Utils.sign(uri, ) log(:debug, "calling: #{signed_url}") RestClient.get(signed_url, :accept => 'application/json') rescue log(:error, "error: #{$!.inspect}") raise end |
.call_and_parse(uri, options = nil) ⇒ Object
35 36 37 38 |
# File 'lib/saaspose/utils.rb', line 35 def call_and_parse(uri, =nil) response = call(uri, ) JSON.parse(response.body) end |
.call_and_save(uri, options, file) ⇒ Object
40 41 42 43 |
# File 'lib/saaspose/utils.rb', line 40 def call_and_save(uri, , file) response = response = call(uri, ) Utils.save_file(response, file) end |
.log(severity, message) ⇒ Object
49 50 51 |
# File 'lib/saaspose/utils.rb', line 49 def log(severity, ) Configuration.logger.send(severity, ) if Configuration.logger end |
.save_file(response_stream, local_file) ⇒ Object
45 46 47 |
# File 'lib/saaspose/utils.rb', line 45 def save_file(response_stream, local_file) File.open(local_file, "wb") { |file| file.write(response_stream.body) } end |
.sign(uri, options = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/saaspose/utils.rb', line 12 def sign(uri, =nil) = ? .dup : {} .merge!(:appSID => Configuration.app_sid) url = "#{Configuration.product_uri}#{uri}" url << "?" << .map{|key, value| "#{key}=#{CGI::escape(value.to_s)}"}.join("&") signature = OpenSSL::HMAC.digest(DIGEST, Configuration.app_key, url) signature = Base64.strict_encode64(signature).chop signature = URI::escape(signature, /[^A-z0-9]/) "#{url}&signature=#{signature}" end |