Class: Youtrack::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, token:) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/youtrack/client.rb', line 9

def initialize(base_url:, token:)
  @base_url = normalize_base_url(base_url)
  @token = token
  RestClient.log = $stdout if ENV["DEBUG"]
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



7
8
9
# File 'lib/youtrack/client.rb', line 7

def base_url
  @base_url
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/youtrack/client.rb', line 7

def token
  @token
end

Instance Method Details

#delete(path, options = {}) ⇒ Object



35
36
37
# File 'lib/youtrack/client.rb', line 35

def delete(path, options = {})
  execute(:delete, path, options)
end

#execute(method, path, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/youtrack/client.rb', line 39

def execute(method, path, options = {})
  RestClient::Request.execute(
    method: method,
    url: request_url(path),
    headers: default_headers
               .merge(options.delete(:headers) || {})
               .merge(params: options.delete(:params) || {}),
    **options
  )
rescue RestClient::Exception => e
  if e.http_body.present?
    e.message = e.http_body
  end
  raise e
end

#get(path, options = {}) ⇒ Object



27
28
29
# File 'lib/youtrack/client.rb', line 27

def get(path, options = {})
  execute(:get, path, options)
end

#issuesObject



19
20
21
# File 'lib/youtrack/client.rb', line 19

def issues
  @issues ||= Resources::Issues.new(client: self)
end

#post(path, payload, options = {}) ⇒ Object



31
32
33
# File 'lib/youtrack/client.rb', line 31

def post(path, payload, options = {})
  execute(:post, path, options.merge(payload: payload))
end

#projectsObject



23
24
25
# File 'lib/youtrack/client.rb', line 23

def projects
  @projects ||= Resources::Projects.new(client: self)
end

#usersObject



15
16
17
# File 'lib/youtrack/client.rb', line 15

def users
  @users ||= Resources::Users.new(client: self)
end