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/v1/public/'

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.



10
11
12
13
14
15
16
17
18
19
# File 'lib/nexboard_api.rb', line 10

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.



8
9
10
# File 'lib/nexboard_api.rb', line 8

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



8
9
10
# File 'lib/nexboard_api.rb', line 8

def base_url
  @base_url
end

#template_project_idObject (readonly)

Returns the value of attribute template_project_id.



8
9
10
# File 'lib/nexboard_api.rb', line 8

def template_project_id
  @template_project_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



8
9
10
# File 'lib/nexboard_api.rb', line 8

def user_id
  @user_id
end

Instance Method Details

#boards_for_project(project_id:) ⇒ Object



40
41
42
43
44
# File 'lib/nexboard_api.rb', line 40

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

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



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/nexboard_api.rb', line 55

def create_board(project_id:, title:, description: nil, template_id: nil)
  data = {
    projectId: project_id,
    userId: user_id,
    title: title,
  }
  data[:description] = description if description
  data[:template_id] = template_id unless template_id.nil?

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

#create_project(title:, description: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nexboard_api.rb', line 28

def create_project(title:, description: nil)
  data = {
    title: title,
    userId: user_id,
  }
  data[:description] = description if description

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

#project_idsObject



21
22
23
24
25
26
# File 'lib/nexboard_api.rb', line 21

def project_ids
  projects = Restify.new(URI.join(base_url, 'projects'))
    .get(userId: user_id, token: api_key)
    .value!
  projects.data.map(&:id)
end

#template_boardsObject



46
47
48
49
50
51
52
53
# File 'lib/nexboard_api.rb', line 46

def template_boards
  return [] if template_project_id.nil?

  template_boards = boards_for_project(project_id: template_project_id)
  template_boards
    .data
    .map {|board| {board_id: board['id'], title: board['title']} }
end

#upload_image_to_board(board_id:, uploaded_io:) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/nexboard_api.rb', line 69

def upload_image_to_board(board_id:, uploaded_io:)
  uri = URI.join(
    base_url,
    "boards/images/#{board_id}",
    "?token=#{api_key}",
  )

  multipart_request uri, uploaded_io
end