Class: NexboardApi

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

Constant Summary collapse

DEFAULT_BASE_URL =
'https://nexboard.nexenio.com/portal/api/public/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, user_id:, template_project_id: nil, base_url: nil) ⇒ NexboardApi

Returns a new instance of NexboardApi.



6
7
8
9
10
11
12
13
14
15
# File 'lib/nexboard_api.rb', line 6

def initialize(api_key:, user_id:, template_project_id: nil, base_url: nil)
  @api_key             = api_key
  @user_id             = user_id
  @template_project_id = template_project_id unless template_project_id.nil?
  @base_url            = if base_url.nil?
                           DEFAULT_BASE_URL
                         else
                           base_url
                         end    
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



4
5
6
# File 'lib/nexboard_api.rb', line 4

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



4
5
6
# File 'lib/nexboard_api.rb', line 4

def base_url
  @base_url
end

#template_project_idObject (readonly)

Returns the value of attribute template_project_id.



4
5
6
# File 'lib/nexboard_api.rb', line 4

def template_project_id
  @template_project_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



4
5
6
# File 'lib/nexboard_api.rb', line 4

def user_id
  @user_id
end

Instance Method Details

#create_board_for_project(project_id:, title:, description:, template_id: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/nexboard_api.rb', line 49

def create_board_for_project(project_id:, title:, description:, template_id: nil)
  data = {
      project_id: project_id,
      title: title,
      description: description,
      user_id: @user_id
  }
  data.merge!(template_id: template_id) unless template_id.nil?

  Restify.new(@base_url + 'boards')
      .post(data, token: @api_key)
      .value!
end

#create_project(title:, description:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nexboard_api.rb', line 25

def create_project(title:, description:)
  data = {
      title: title,
      description: description,
      user_id: @user_id
  }

  Restify.new(@base_url + 'projects')
      .post(data, token: @api_key)
      .value!
end

#get_boards_for_project(project_id:) ⇒ Object



37
38
39
40
41
# File 'lib/nexboard_api.rb', line 37

def get_boards_for_project(project_id:)
  Restify.new(@base_url + "projects/#{project_id}/boards")
      .get(token: @api_key, userId: @user_id)
      .value!
end

#get_project_idsObject



17
18
19
20
21
22
23
# File 'lib/nexboard_api.rb', line 17

def get_project_ids
  projects = Restify.new(@base_url + 'projects')
                 .get(userId: @user_id, token: @api_key)
                 .value!

  projects.data.map{|project| project['project_id']}
end

#get_template_boardsObject



43
44
45
46
47
# File 'lib/nexboard_api.rb', line 43

def get_template_boards
  return [] if @template_project_id.nil?
  template_boards = get_boards_for_project(project_id: @template_project_id)
  template_boards.data.map{ |board| {board_id: board['boardId'], title: board['title'] } }
end