Sha256: 5729c1307b5d61287655646c7f1d4e62baf20920156acd3400b8082886165b5a

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

require 'yaml'
require 'rest-client'
require 'time'

module LocaleApp
  class KeyChecker
    include ::LocaleApp::ApiCall

    def check(key)
      if LocaleApp.configuration.nil? # no config file yet
        LocaleApp.configuration = LocaleApp::Configuration.new
        LocaleApp.configuration.host = ENV['LA_TEST_HOST'] if ENV['LA_TEST_HOST']
      end
      LocaleApp.configuration.api_key = key
      api_call :project,
        :success => :handle_success,
        :failure => :handle_failure,
        :max_connection_attempts => 1

      if @checked
        [@ok, @data]
      else
        [false, "Error communicating with server"]
      end
    end

    def handle_success(response)
      @checked = true
      @ok = true
      @data = JSON.parse(response)
    end

    def handle_failure(response)
      if response.code.to_i == 404
        @checked = true
        @ok = false
        @data = {}
      else
        @checked = false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localeapp-0.0.7 lib/locale_app/key_checker.rb