BigW Consortium Gitlab

api.js.coffee 1.18 KB
Newer Older
1
@Api =
2 3
  groups_path: "/api/:version/groups.json"
  group_path: "/api/:version/groups/:id.json"
4
  namespaces_path: "/api/:version/namespaces.json"
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  group: (group_id, callback) ->
    url = Api.buildUrl(Api.group_path)
    url = url.replace(':id', group_id)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
      dataType: "json"
    ).done (group) ->
      callback(group)

  # Return groups list. Filtered by query
  # Only active groups retrieved
  groups: (query, skip_ldap, callback) ->
    url = Api.buildUrl(Api.groups_path)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
        per_page: 20
      dataType: "json"
    ).done (groups) ->
      callback(groups)

33 34 35 36 37 38 39 40 41 42 43 44 45 46
  # Return namespaces list. Filtered by query
  namespaces: (query, callback) ->
    url = Api.buildUrl(Api.namespaces_path)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
        per_page: 20
      dataType: "json"
    ).done (namespaces) ->
      callback(namespaces)

47
  buildUrl: (url) ->
Jim committed
48
    url = gon.relative_url_root + url if gon.relative_url_root?
49
    return url.replace(':version', gon.api_version)