Sha256: 750a953bde85ef7c8b2684d3ddd21a2b0b241c063904441eb8fab668dfca0a83

Contents?: true

Size: 969 Bytes

Versions: 57

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

57 entries across 57 versions & 1 rubygems

Version Path
localeapp-3.3.0 lib/localeapp/key_checker.rb
localeapp-3.2.0 lib/localeapp/key_checker.rb
localeapp-3.1.3 lib/localeapp/key_checker.rb
localeapp-3.1.2 lib/localeapp/key_checker.rb
localeapp-3.1.1 lib/localeapp/key_checker.rb
localeapp-3.1.0 lib/localeapp/key_checker.rb
localeapp-3.0.1 lib/localeapp/key_checker.rb
localeapp-3.0.0 lib/localeapp/key_checker.rb
localeapp-2.5.0 lib/localeapp/key_checker.rb
localeapp-2.4.0 lib/localeapp/key_checker.rb
localeapp-2.3.0 lib/localeapp/key_checker.rb
localeapp-2.2.0 lib/localeapp/key_checker.rb
localeapp-2.1.1 lib/localeapp/key_checker.rb
localeapp-2.1.0 lib/localeapp/key_checker.rb
localeapp-2.0.0 lib/localeapp/key_checker.rb
localeapp-1.0.2 lib/localeapp/key_checker.rb
localeapp-1.0.1 lib/localeapp/key_checker.rb
localeapp-1.0.0 lib/localeapp/key_checker.rb
localeapp-0.9.3 lib/localeapp/key_checker.rb
localeapp-0.9.2 lib/localeapp/key_checker.rb