Class: Imgix::Client
- Inherits:
-
Object
- Object
- Imgix::Client
- Defined in:
- lib/imgix/client.rb
Constant Summary collapse
- DEFAULTS =
{ use_https: true }.freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #path(path) ⇒ Object
- #prefix ⇒ 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 24 |
# File 'lib/imgix/client.rb', line 12 def initialize( = {}) = DEFAULTS.merge() @domain = [:domain] validate_domain! @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
26 27 28 29 30 |
# File 'lib/imgix/client.rb', line 26 def path(path) p = Path.new(prefix, @secure_url_token, path) p.ixlib("#{@library}-#{@version}") if @include_library_param p end |
#prefix ⇒ Object
48 49 50 |
# File 'lib/imgix/client.rb', line 48 def prefix "#{@use_https ? 'https' : 'http'}://#{@domain}" end |
#purge(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/imgix/client.rb', line 32 def purge(path) api_key_error = "A valid API key is required to send purge requests" raise api_key_error if @api_key.nil? endpoint = URI.parse("https://api.imgix.com/api/v1/purge") # Ensure the path has been prefixed with '/'. path = path.start_with?("/") ? path : "/#{path}" url = prefix + path req = create_request(endpoint, url, :json_data_from) sock = Net::HTTP.new(endpoint.host, endpoint.port) sock.use_ssl = true sock.start { |http| http.request(req) } end |