Sha256: 974ec8b1fef7f72855baac5ef6a03daf5eb34c5d6d197bad05e955a708f2d3a1

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

require 'bijo/image'

require 'json'
require 'open-uri'
require 'tempfile'

module Bijo
  module Client
    class Base
      def initialize(query)
        @query = query
        @image = Image.new(choose_image)
      end

      def get
        content = @image.content

        file = Tempfile.new(['bijo', @image.extension])
        file.print content
        file.close
        file
      end

      private

      def raw_search_results
        open(search_uri).read
      end

      def json_parsed_search_results
        JSON.parse(raw_search_results)
      end

      # return image url
      # Ex) http://example.com/hoge.jpg
      def choose_image
        search_results[rand(search_results.size)]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bijo-0.0.1 lib/bijo/client/base.rb