Sha256: 5457dadbf0227896abccbb47479bcb37a9802f641894770c42f86156ae80bf67

Contents?: true

Size: 740 Bytes

Versions: 4

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

module Peddler
  class JSONFeedDocument
    CONTENT_TYPE = "application/json; charset=UTF-8"

    def upload(content)
      # While HTTPrb already sets the content-type, Amazon server seems to fail if we don't explicitly set it again
      # here. A bit of a mystery; maybe it's the order of the headers that's screwing things up on their end?
      HTTP.headers("Content-Type" => CONTENT_TYPE).put(url, json: content)
    end

    def initialize(api)
      @api = api
    end

    def id
      metadata.fetch("id")
    end

    def url
      metadata.fetch("url")
    end

    private

    def metadata
      @metadata ||= @api.create_feed_document({ "contentType" => CONTENT_TYPE }).parse
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
peddler-4.1.1 lib/peddler/json_feed_document.rb
peddler-4.1.0 lib/peddler/json_feed_document.rb
peddler-4.0.1 lib/peddler/json_feed_document.rb
peddler-4.0.0 lib/peddler/json_feed_document.rb