Sha256: d3a02e1dc1b554e1a79a93d6934ace25aa4388a11a960741284c4aa3f8ce507e

Contents?: true

Size: 704 Bytes

Versions: 2

Compression:

Stored size: 704 Bytes

Contents

class Zemanta
  class Fetcher
    class Web
      def initialize(opts = {})
        @opts = opts
      end

      def fetch
        if http_fetch == zemanta_error_response
          raise_api_key_exception!
        else
          http_fetch
        end
      end

      private

      def http_fetch
        @response ||= Typhoeus.post(url, params: @opts).response_body
      end

      def zemanta_error_response
        '<h1>403 Developer Inactive</h1>'
      end

      def raise_api_key_exception!
        raise "Zemanta returned '#{zemanta_error_response}' exception. Quite possibly you passed incorrect api_key."
      end

      def url
        Zemanta.config.end_point
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zemanta_client-0.0.2 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.1 lib/zemanta/fetcher/web.rb