Class: ConnectorsSdk::Confluence::CustomClient

Inherits:
Atlassian::CustomClient show all
Defined in:
lib/connectors_sdk/confluence/custom_client.rb

Constant Summary collapse

SEARCH_ENDPOINT =
'rest/api/search'
CONTENT_SEARCH_ENDPOINT =
'rest/api/content/search'
CONTENT_EXPAND_FIELDS =
%w(body.export_view history.lastUpdated ancestors space children.comment.body.export_view container).freeze

Constants inherited from Atlassian::CustomClient

Atlassian::CustomClient::MEDIA_API_BASE_URL

Constants inherited from Base::CustomClient

Base::CustomClient::MAX_RETRIES

Instance Attribute Summary

Attributes inherited from Atlassian::CustomClient

#access_token, #base_url, #basic_auth_token

Attributes inherited from Base::CustomClient

#base_url, #ensure_fresh_auth, #middleware

Instance Method Summary collapse

Methods inherited from Atlassian::CustomClient

#additional_middleware, #default_middleware, #download, #initialize, #update_auth_data!

Methods inherited from Base::CustomClient

#additional_middleware, #default_middleware, #http_client, #http_client!, #initialize, #middleware!, #retry_config

Constructor Details

This class inherits a constructor from ConnectorsSdk::Atlassian::CustomClient

Instance Method Details

#content(space:, types: [], start_at: 0, order_field_and_direction: 'created asc', updated_after: nil, next_value: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 23

def content(space:, types: [], start_at: 0, order_field_and_direction: 'created asc', updated_after: nil, next_value: nil)
  search_helper(
    :endpoint => CONTENT_SEARCH_ENDPOINT,
    :space => space,
    :types => types,
    :start_at => start_at,
    :order_field_and_direction => order_field_and_direction,
    :updated_after => updated_after,
    :next_value => next_value
  )
end

#content_by_id(content_id, include_permissions: false, expand_fields: CONTENT_EXPAND_FIELDS) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 35

def content_by_id(content_id, include_permissions: false, expand_fields: CONTENT_EXPAND_FIELDS)
  endpoint = "rest/api/content/#{Faraday::Utils.escape(content_id)}"
  if include_permissions
    expand_fields = expand_fields.dup
    expand_fields << 'restrictions.read.restrictions.user'
    expand_fields << 'restrictions.read.restrictions.group'
  end
  response = begin
    parse_and_raise_if_necessary!(get(endpoint, :status => 'any', :expand => expand_fields.join(',')))
  rescue ContentConvertibleError
    # Confluence has a bug when trying to expand `container` for certain items:
    # https://jira.atlassian.com/browse/CONFSERVER-40475
    Connectors::Stats.increment('custom_client.confluence.error.content_convertible')
    parse_and_raise_if_necessary!(get(endpoint, :status => 'any', :expand => (expand_fields - ['container']).join(',')))
  end
  Hashie::Mash.new(response)
end

#content_search(cql, expand: [], limit: 25) ⇒ Object



85
86
87
88
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 85

def content_search(cql, expand: [], limit: 25)
  response = get(CONTENT_SEARCH_ENDPOINT, :cql => cql, :expand => expand.join(','), :limit => limit)
  Hashie::Mash.new(parse_and_raise_if_necessary!(response))
end

#meObject



90
91
92
93
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 90

def me
  response = get('rest/api/user/current')
  Hashie::Mash.new(parse_and_raise_if_necessary!(response))
end

#search(space: nil, start_at: 0, limit: 50, types: [], expand_fields: [], order_field_and_direction: 'created asc', updated_after: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 64

def search(
  space: nil,
  start_at: 0,
  limit: 50,
  types: [],
  expand_fields: [],
  order_field_and_direction: 'created asc',
  updated_after: nil
)
  search_helper(
    :endpoint => SEARCH_ENDPOINT,
    :space => space,
    :start_at => start_at,
    :limit => limit,
    :types => types,
    :expand_fields => expand_fields,
    :order_field_and_direction => order_field_and_direction,
    :updated_after => updated_after
  )
end

#spaces(start_at: 0, limit: 50, space_keys: nil, include_permissions: false) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/connectors_sdk/confluence/custom_client.rb', line 53

def spaces(start_at: 0, limit: 50, space_keys: nil, include_permissions: false)
  params = {
    :start => start_at,
    :limit => limit
  }
  params[:spaceKey] = space_keys if space_keys.present?
  params[:expand] = 'permissions' if include_permissions
  response = get('rest/api/space', params)
  Hashie::Mash.new(parse_and_raise_if_necessary!(response))
end