Sha256: 4e1d7e9c71e5fecb4c5df9aceaf2fd3b95a503c1c81cf3ec18ec42533119c7ea

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

require 'uri'

class Fastly
  # Encapsulates behavior of objects requiring both service and version
  class BelongsToServiceAndVersion < Base
    attr_writer :version

    # Return the Service object this belongs to
    def service
      @service ||= fetcher.get(Service, service_id)
    end

    # Get the Version object this belongs to
    def version
      @version_obj ||= fetcher.get(Fastly::Version, service_id, version_number)
    end

    # Get the number of the Version this belongs to
    def version_number
      @version ||= nil
    end

    # :nodoc:
    def as_hash
      super.delete_if { |var| %w(service_id version).include?(var) }
    end

    # URI escape (including spaces) the path and return it
    def self.path_escape(path)
      @uri_parser ||= URI::Parser.new
      # the leading space in the escape character set is intentional
      @uri_parser.escape(path, ' !*\'();:@&=+$,/?#[]')
    end

    def self.get_path(service, version, name, _opts = {})
      "/service/#{service}/version/#{version}/#{path}/#{path_escape(name)}"
    end

    def self.post_path(opts)
      "/service/#{opts[:service_id]}/version/#{opts[:version]}/#{path}"
    end

    def self.put_path(obj)
      get_path(obj.service_id, obj.version_number, obj.name)
    end

    def self.delete_path(obj)
      put_path(obj)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fastly-3.0.2 lib/fastly/belongs_to_service_and_version.rb
fastly-3.0.1 lib/fastly/belongs_to_service_and_version.rb
fastly-3.0.0 lib/fastly/belongs_to_service_and_version.rb
fastly-2.5.3 lib/fastly/belongs_to_service_and_version.rb