Class: Imgix::Client
- Inherits:
-
Object
- Object
- Imgix::Client
- Defined in:
- lib/imgix/client.rb
Constant Summary collapse
- DEFAULTS =
{ use_https: true }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #path(path) ⇒ Object
- #prefix(path) ⇒ Object
- #purge(path) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/imgix/client.rb', line 12 def initialize( = {}) = DEFAULTS.merge() @host = [:host] validate_host! @secure_url_token = [:secure_url_token] @api_key = [:api_key] @use_https = [:use_https] @include_library_param = .fetch(:include_library_param, true) @library = .fetch(:library_param, "rb") @version = .fetch(:library_version, Imgix::VERSION) end |
Instance Method Details
#path(path) ⇒ Object
25 26 27 28 29 |
# File 'lib/imgix/client.rb', line 25 def path(path) p = Path.new(prefix(path), @secure_url_token, path) p.ixlib("#{@library}-#{@version}") if @include_library_param p end |
#prefix(path) ⇒ Object
44 45 46 |
# File 'lib/imgix/client.rb', line 44 def prefix(path) "#{@use_https ? 'https' : 'http'}://#{@host}" end |
#purge(path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/imgix/client.rb', line 31 def purge(path) raise "Authentication token required" unless !!(@api_key) url = prefix(path)+path uri = URI.parse('https://api.imgix.com/v2/image/purger') req = Net::HTTP::Post.new(uri.path, {"User-Agent" => "imgix #{@library}-#{@version}"}) req.basic_auth @api_key, '' req.set_form_data({'url' => url}) sock = Net::HTTP.new(uri.host, uri.port) sock.use_ssl = true res = sock.start {|http| http.request(req) } res end |