Sha256: 90078ab55808fa4743cce9e787cb38b649533ea06061d7fc8db34a37e0cca1db

Contents?: true

Size: 1.02 KB

Versions: 30

Compression:

Stored size: 1.02 KB

Contents

require_relative 'resource'

module Contentful
  module Management
    # Resource Class for Links
    # https://www.contentful.com/developers/documentation/content-delivery-api/#links
    class Link
      include Contentful::Management::Resource
      include Contentful::Management::Resource::SystemProperties

      # Queries contentful for the Resource the Link is referring to
      # @param [String] space_id
      # @param [String] environment_id
      def resolve(space_id = nil, environment_id = nil)
        return client.spaces.find(id) if link_type == 'Space'

        method = Contentful::Management::Support.base_path_for(link_type).to_sym

        if space_id && environment_id.nil?
          return client.public_send(
            method,
            space_id
          ).find(id)
        elsif space_id && environment_id
          return client.public_send(
            method,
            space_id,
            environment_id
          ).find(id)
        end

        client.public_send(method).find(id)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/link.rb
contentful-management-3.7.0 lib/contentful/management/link.rb
contentful-management-3.6.0 lib/contentful/management/link.rb
contentful-management-3.5.0 lib/contentful/management/link.rb
contentful-management-3.4.0 lib/contentful/management/link.rb
contentful-management-3.3.0 lib/contentful/management/link.rb
contentful-management-3.2.0 lib/contentful/management/link.rb
contentful-management-3.1.0 lib/contentful/management/link.rb
contentful-management-3.0.0 lib/contentful/management/link.rb
contentful-management-2.13.1 lib/contentful/management/link.rb
contentful-management-2.13.0 lib/contentful/management/link.rb
contentful-management-2.12.1 lib/contentful/management/link.rb
contentful-management-2.12.0 lib/contentful/management/link.rb
contentful-management-2.11.0 lib/contentful/management/link.rb
contentful-management-2.10.0 lib/contentful/management/link.rb
contentful-management-2.9.1 lib/contentful/management/link.rb
contentful-management-2.9.0 lib/contentful/management/link.rb
contentful-management-2.8.2 lib/contentful/management/link.rb
contentful-management-2.8.1 lib/contentful/management/link.rb
contentful-management-2.8.0 lib/contentful/management/link.rb