Sha256: 295283a67adb1d7d829977c259a89a5a09075d33bfeb2017764d5f9040367da8

Contents?: true

Size: 1.29 KB

Versions: 92

Compression:

Stored size: 1.29 KB

Contents

module Onebox
  module Engine
    class PastebinOnebox
      include Engine
      include LayoutSupport

      MAX_LINES = 10

      matches_regexp(/^http?:\/\/pastebin\.com/)

      private

      def data
        @data ||= {
          title: 'pastebin.com',
          link: link,
          content: content,
          truncated?: truncated?
        }
      end

      def content
        lines.take(MAX_LINES).join("\n")
      end

      def truncated?
        lines.size > MAX_LINES
      end

      def lines
        return @lines if @lines
        response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", 1) rescue ""
        @lines = response.split("\n")
      end

      def paste_key
        if uri.path =~ /\/raw\//
          match = uri.path.match(/\/raw\/([^\/]+)/)
          return match[1] if match && match[1]
        elsif uri.path =~ /\/download\//
          match = uri.path.match(/\/download\/([^\/]+)/)
          return match[1] if match && match[1]
        elsif uri.path =~ /\/embed\//
          match = uri.path.match(/\/embed\/([^\/]+)/)
          return match[1] if match && match[1]
        else
          match = uri.path.match(/\/([^\/]+)/)
          return match[1] if match && match[1]
        end

        nil
      rescue
        return nil
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
onebox-1.8.69 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.68 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.67 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.66 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.65 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.64 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.63 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.62 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.61 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.60 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.59 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.58 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.57 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.55 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.54 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.53 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.52 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.51 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.50 lib/onebox/engine/pastebin_onebox.rb
onebox-1.8.49 lib/onebox/engine/pastebin_onebox.rb