<commit_before>module Gyazo

  class Client

    attr_accessor :id, :user_id, :user_agent, :host

    def initialize(user_id=nil)
      @user_id = user_id
      @user = ENV['USER']
      @idfile = "#{ENV['HOME']}/Library/Gyazo/id"
      @id = nil
      @id = File.read(@idfile).strip if File.exist? @idfile
      @user_agent = "GyazoRubyGem/#{Gyazo::VERSION}"
      @host = 'http://gyazo.com'
    end

    def info(image_id)
      res = HTTParty.get "#{@host}/api/image/get", {
        :query => {
          :image_id => image_id
        },
        :header => {
          'User-Agent' => @user_agent
        }
      }

      raise Gyazz::Error, res.body unless res.code == 200
      JSON.parse(res.body)
    end

    def list(page=1, count=100)
      url = "#{@host}/api/image/list"
      query = {:page => page, :count => count}
      if @user_id
        query[:user_id] = @user_id
      else
        query[:device_id] = @id
      end

      res = HTTParty.get "#{@host}/api/image/list", {
        :query => query,
        :header => {
          'User-Agent' => @user_agent
        }
      }

      raise Gyazz::Error, res.body unless res.code == 200
      JSON.parse(res.body)['images']
    end

    DEFAULT_UPLOAD_OPTS = {:time => nil, :raw => false}
    def upload(imagefile, opts={})
      DEFAULT_UPLOAD_OPTS.each do |k,v|
        opts[k] = v unless opts.include? k
      end

      unless opts[:raw]
        tmpfile = "/tmp/gyazo_upload_#{Time.now.to_i}_#{Time.now.usec}.png"
        if File.exist? imagefile
          system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\" > /dev/null"
        end<commit_msg>Mac以外ではsipsコマンドを呼び出さない #9<commit_after>module Gyazo

  class Client

    attr_accessor :id, :user_id, :user_agent, :host

    def initialize(user_id=nil)
      @user_id = user_id
      @user = ENV['USER']
      @idfile = "#{ENV['HOME']}/Library/Gyazo/id"
      @id = nil
      @id = File.read(@idfile).strip if File.exist? @idfile
      @user_agent = "GyazoRubyGem/#{Gyazo::VERSION}"
      @host = 'http://gyazo.com'
    end

    def info(image_id)
      res = HTTParty.get "#{@host}/api/image/get", {
        :query => {
          :image_id => image_id
        },
        :header => {
          'User-Agent' => @user_agent
        }
      }

      raise Gyazz::Error, res.body unless res.code == 200
      JSON.parse(res.body)
    end

    def list(page=1, count=100)
      url = "#{@host}/api/image/list"
      query = {:page => page, :count => count}
      if @user_id
        query[:user_id] = @user_id
      else
        query[:device_id] = @id
      end

      res = HTTParty.get "#{@host}/api/image/list", {
        :query => query,
        :header => {
          'User-Agent' => @user_agent
        }
      }

      raise Gyazz::Error, res.body unless res.code == 200
      JSON.parse(res.body)['images']
    end

    DEFAULT_UPLOAD_OPTS = {:time => nil, :raw => false}
    def upload(imagefile, opts={})
      DEFAULT_UPLOAD_OPTS.each do |k,v|
        opts[k] = v unless opts.include? k
      end

      unless opts[:raw]
        tmpfile = "/tmp/gyazo_upload_#{Time.now.to_i}_#{Time.now.usec}.png"
        if File.exist? imagefile and RUBY_PLATFORM =~ /darwin/
          system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\" > /dev/null"
        end
{'fraction_non_alphanumeric': 0.15928398058252427, 'fraction_numerical': 0.006371359223300971, 'mean_word_length': 2.0584415584415585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6231383', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1173, 'n_words': 235}