Sha256: cb2538d5792de3947e24db567a18ae615d1bceadc367c63e06f401a360d81d80

Contents?: true

Size: 705 Bytes

Versions: 7

Compression:

Stored size: 705 Bytes

Contents

module 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

7 entries across 7 versions & 1 rubygems

Version Path
zemanta_client-0.0.9 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.8 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.7 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.6 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.5 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.4 lib/zemanta/fetcher/web.rb
zemanta_client-0.0.3 lib/zemanta/fetcher/web.rb