Sha256: 9df79bb734b7d505c7ee8aada30279f136e7df247208b7000a4998e72f639fe5

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

require 'forwardable'
require 'null_logger'
require 'zendesk_api'

require 'gds_zendesk/users'

module GDSZendesk
  class Client
    extend Forwardable
    def_delegators :@zendesk_client, :ticket

    attr_accessor :config_options

    def initialize(config_options)
      @config_options = defaults.merge(config_options)
      @zendesk_client = build
    end

    def users
      Users.new(@zendesk_client)
    end

    def build
      check_that_username_and_password_are_provided

      ZendeskAPI::Client.new { |config|
        config.url = "https://govuk.zendesk.com/api/v2/"
        config.username = username
        config.password = password
        config.logger = logger
      }
    end

    protected
    def logger
      @config_options[:logger] || @config_options["logger"]
    end

    def check_that_username_and_password_are_provided
      raise ArgumentError, "Zendesk username not provided" if username.nil?
      raise ArgumentError, "Zendesk password not provided" if password.nil?
    end

    def username
      @config_options[:username] || @config_options["username"]
    end

    def password
      @config_options[:password] || @config_options["password"]
    end

    def defaults
      { logger: NullLogger.instance }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gds_zendesk-2.1.0 lib/gds_zendesk/client.rb
gds_zendesk-2.0.0 lib/gds_zendesk/client.rb
gds_zendesk-1.0.5 lib/gds_zendesk/client.rb
gds_zendesk-1.0.4 lib/gds_zendesk/client.rb
gds_zendesk-1.0.3 lib/gds_zendesk/client.rb
gds_zendesk-1.0.2 lib/gds_zendesk/client.rb