Sha256: 04bd397dfff4ee3ff1b3095f3d74cdde443fdde8743e98c5e48150d769779bd4

Contents?: true

Size: 1.16 KB

Versions: 35

Compression:

Stored size: 1.16 KB

Contents

module SparkApi
  module Models
    class SharedLink < Base
      extend Finders

      attr_accessor :sort_id
      attr_writer :name

      self.element_name = "sharedlinks"

      def self.create(data)
        SharedLink.new SparkApi.client.post("#{path}/#{resource_type(data)}", data).first
      rescue SparkApi::BadResourceRequest
        false
      end

      def name
        if @name
          @name
        elsif respond_to?(:ListingCart) && self.ListingCart.respond_to?(:Name)
          self.ListingCart.Name
        elsif respond_to?(:SavedSearch) && self.SavedSearch.respond_to?(:Name)
          self.SavedSearch.Name
        end
      end

      def template
        if respond_to?(:SavedSearch) && self.SavedSearch.respond_to?(:template)
          self.SavedSearch.template
        end
      end

      def filter
        "SharedLink Eq '#{id}'"
      end

      def listing_search_role
        self.Mode.downcase.to_sym
      end

      private

      def self.resource_type(data)
        case data.keys[0].to_sym
          when :ListingIds; "listings"
          when :SearchId;   "search"
          when :CartId;     "cart"
        end
      end

    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
spark_api-1.4.24 lib/spark_api/models/shared_link.rb
spark_api-1.4.23 lib/spark_api/models/shared_link.rb
spark_api-1.4.22 lib/spark_api/models/shared_link.rb
spark_api-1.4.21 lib/spark_api/models/shared_link.rb
spark_api-1.4.20 lib/spark_api/models/shared_link.rb
spark_api-1.4.19 lib/spark_api/models/shared_link.rb
spark_api-1.4.18 lib/spark_api/models/shared_link.rb
spark_api-1.4.17 lib/spark_api/models/shared_link.rb
spark_api-1.4.16 lib/spark_api/models/shared_link.rb
spark_api-1.4.15 lib/spark_api/models/shared_link.rb
spark_api-1.4.14 lib/spark_api/models/shared_link.rb
spark_api-1.4.13 lib/spark_api/models/shared_link.rb
spark_api-1.4.12 lib/spark_api/models/shared_link.rb
spark_api-1.4.11 lib/spark_api/models/shared_link.rb
spark_api-1.4.10 lib/spark_api/models/shared_link.rb