Sha256: c80950b0116ddcfe4d483082c308e706e9434d745d1fb0e6b1d10a05f9483999

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 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 = url
        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 url
      @config_options[:url] || @config_options["url"]
    end

    def defaults
      {
          logger: NullLogger.instance,
          url: "https://govuk.zendesk.com/api/v2/"
      }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gds_zendesk-3.1.0 lib/gds_zendesk/client.rb
gds_zendesk-3.0.0 lib/gds_zendesk/client.rb
gds_zendesk-2.4.0 lib/gds_zendesk/client.rb
gds_zendesk-2.3.1 lib/gds_zendesk/client.rb
gds_zendesk-2.3.0 lib/gds_zendesk/client.rb
gds_zendesk-2.2.0 lib/gds_zendesk/client.rb