Sha256: 03c7b65904ebbda72b07ccdf20adfe63da3110dbbfa6d6f564efc5c97ce9b564

Contents?: true

Size: 811 Bytes

Versions: 6

Compression:

Stored size: 811 Bytes

Contents

module Workarea
  module Blog
    module Import
      module Wordpress
        class Attachment
          def initialize(url)
            @attachment_path = url
          end

          def save
            attributes = {
              name: file_name,
              tag_list: 'Wordpress',
              file: image_file
            }

            asset = Workarea::Content::Asset.create!(attributes)
            puts "Created Asset: #{asset.name}"
            asset
          end

          private

          def image_file
            Net::HTTP.get(uri)
          end

          def uri
            URI.parse(@attachment_path)
          end

          def file_name
            path = uri.path
            path.rpartition('.').first.split('/').join('-')
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-blog-3.5.2 lib/workarea/blog/import/wordpress/attachment.rb
workarea-blog-3.5.1 lib/workarea/blog/import/wordpress/attachment.rb
workarea-blog-3.5.0 lib/workarea/blog/import/wordpress/attachment.rb
workarea-blog-3.4.9 lib/workarea/blog/import/wordpress/attachment.rb
workarea-blog-3.4.8 lib/workarea/blog/import/wordpress/attachment.rb
workarea-blog-3.4.7 lib/workarea/blog/import/wordpress/attachment.rb