Sha256: 1b4729e7dce7735bf4a756b4606a14a84a8c286e62c879f25a92473eea323435
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
# encoding: utf-8 require 'filepreviews/version' require 'filepreviews/utils' require 'filepreviews/http' require 'filepreviews/response' require 'ostruct' # @author Jonah Ruiz <jonah@pixelhipsters.com> # Main module for FilePreviews.io library module Filepreviews # Facade method to call API response # @param url [String] image url to convert # @param options [Hash<Symbol>] :metada and :image options # @return [Filepreviews::Response] api response object def self.generate(url, options = {}) request_hash = prepare_options(url, options) Filepreviews::HTTP.fetch(request_hash) end protected # Prepares url and parameters for request # it calls defaults if nothing is provided # @param url [String] url # @param params [Hash<symbol>] options # @return [OpenStruct] all options as methods def self.prepare_options(url, params) params = merge_options(params.fetch(:options) { default_options }) params.merge!(url: url) OpenStruct.new(params) end # Default options to be used in API request # @return [Hash<symbol>] default options def self.default_options { debug: true, metadata: ['all'] } end # Merges metadata options with supported formats # @param options [Hash<symbol>] metadata and optional size def self.merge_options(options) metadata = (options.fetch(:metadata) & metadata_formats) options.store(:metadata, metadata) default_options.merge(options) end # Supported (image) formats in metadata # @return [Array] image file extensions def self.metadata_formats %w(all exif ocr psd) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
filepreviews-1.0.0 | lib/filepreviews.rb |