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-0.9.1 lib/localeapp/key_checker.rb
localeapp-0.9.0 lib/localeapp/key_checker.rb
localeapp-0.8.1 lib/localeapp/key_checker.rb
localeapp-0.8.0 lib/localeapp/key_checker.rb
localeapp-0.7.2 lib/localeapp/key_checker.rb
localeapp-0.7.1 lib/localeapp/key_checker.rb
localeapp-0.7.0 lib/localeapp/key_checker.rb
localeapp-0.6.14 lib/localeapp/key_checker.rb
localeapp-0.6.13 lib/localeapp/key_checker.rb
localeapp-0.6.12 lib/localeapp/key_checker.rb
localeapp-0.6.10 lib/localeapp/key_checker.rb
localeapp-0.6.9 lib/localeapp/key_checker.rb
localeapp-0.6.8 lib/localeapp/key_checker.rb
localeapp-0.6.7 lib/localeapp/key_checker.rb
localeapp-0.6.6 lib/localeapp/key_checker.rb
localeapp-0.6.5 lib/localeapp/key_checker.rb
localeapp-0.6.4 lib/localeapp/key_checker.rb
localeapp-0.6.3 lib/localeapp/key_checker.rb
localeapp-0.6.2 lib/localeapp/key_checker.rb
localeapp-0.6.1 lib/localeapp/key_checker.rb