Class: Checklister::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/checklister/client.rb

Overview

Implement a kind of Factory pattern

We create an object without exposing the creation logic and then refer to newly created object using a common interface.

Constant Summary collapse

IMPLEMENTED_BACKENDS =

The issue service backends we are currently supporting

  • [x] gitlab
  • [x] github
  • [ ] bitbucket
%w(gitlab github)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Object

Initialize all the issue service options required to be able to interact with it

Examples:

Initialize a gitlab client's options

gitlab_client = Checklister::Client.new(kind: "gitlab", endpoint: "https://gitlab.com/api/v3", private_token: "supersecret")

Parameters:

  • options (Hash) (defaults to: {})

    list of key/values to apply to the appropriately created API client

  • opts (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)

    When no or an inexistent issue service kind is set



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/checklister/client.rb', line 33

def initialize(options = {})
  @kind = options.fetch(:kind) { raise ArgumentError, "No API client can be initialized" }
  raise(NotImplementedError, "No #{@kind} API client has been implemented") unless IMPLEMENTED_BACKENDS.include?(@kind)
  @options = options.reject { |k| [:kind].include? k }
  default_options = { user_agent: "Checklister for #{@kind} #{Checklister::VERSION}" }
  @options.merge! default_options
  @options_for_kind = prepare_options_for_kind(@options, @kind)
  @project_klass = nil
  @issue_klass = nil
  define_classes_for_kind(@kind)
  @api_client = get_api_client
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



17
18
19
# File 'lib/checklister/client.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#issueObject



50
51
52
# File 'lib/checklister/client.rb', line 50

def issue
  @issue ||= @issue_klass.new(@api_client)
end

#projectObject



46
47
48
# File 'lib/checklister/client.rb', line 46

def project
  @project ||= @project_klass.new(@api_client)
end