Sha256: 073918ab107e6ed06781f08bc5cc5db23e0a8bf596999f2b873b58c1b8d38aec

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require 'active_support'
require 'hosted_solr/api/errors'
require 'hosted_solr/api/has_configuration'
require 'hosted_solr/api/solr_core'
require 'hosted_solr/api/solr_cores_api_client'

module HostedSolr
  module API
    class Client
      include HostedSolr::API::HasConfiguration

      def initialize
        fail APITokenMissingError if configuration.api_token.nil?
        fail SecretTokenMissingError if configuration.secret_token.nil?
        @api_client = SolrCoresAPIClient.new
      end

      def all_solr_cores
        @api_client.all.map do |response_entry|
          SolrCore.from_hash response_entry.to_hash
        end
      end

      def create_solr_core(solr_core)
        fail ArgumentError, 'Error: SolrCore expected!' unless solr_core.is_a? SolrCore
        return false unless solr_core.valid?
        @api_client.name = solr_core.name
        @api_client.solr_version = solr_core.solr_version
        @api_client.schema = solr_core.schema
        @api_client.system = solr_core.system
        @api_client.create
      end

      def destroy_solr_core(solr_core)
        case solr_core
        when Integer, String
          id = solr_core
        when SolrCore
          id = solr_core.id
        else
          fail ArgumentError, 'Error: SolrCore or SolrCore id expected!'
        end
        @api_client.destroy String(id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hosted_solr-api-0.6.0 lib/hosted_solr/api/client.rb