Class: ConnectorsSdk::SharePoint::HttpCallWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/connectors_sdk/share_point/http_call_wrapper.rb

Instance Method Summary collapse

Instance Method Details

#access_token(params) ⇒ Object



84
85
86
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 84

def access_token(params)
  ConnectorsSdk::SharePoint::Authorization.access_token(params)
end

#authorization_uri(body) ⇒ Object



80
81
82
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 80

def authorization_uri(body)
  ConnectorsSdk::SharePoint::Authorization.authorization_uri(body)
end

#deleted(params) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 62

def deleted(params)
  results = []
  extractor(params).yield_deleted_ids(params[:ids]) do |id|
    results << id
  end
  results
rescue ConnectorsSdk::Office365::CustomClient::ClientError => e
  raise e.status_code == 401 ? ConnectorsShared::InvalidTokenError : e
end

#document_batch(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 34

def document_batch(params)
  results = []

  extractor = extractor(params)

  extractor.yield_document_changes(:break_after_page => true, :modified_since => extractor.config.cursors['modified_since']) do |action, doc, download_args_and_proc|
    download_obj = nil
    if download_args_and_proc
      download_obj = {
        id: download_args_and_proc[0],
        name: download_args_and_proc[1],
        size: download_args_and_proc[2],
        download_args: download_args_and_proc[3]
      }
    end

    results << {
      :action => action,
      :document => doc,
      :download => download_obj
    }
  end

  [results, extractor.config.cursors, extractor.completed]
rescue ConnectorsSdk::Office365::CustomClient::ClientError => e
  raise e.status_code == 401 ? ConnectorsShared::InvalidTokenError : e
end

#download(params) ⇒ Object



92
93
94
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 92

def download(params)
  extractor(params).download(params[:meta])
end

#extractor(params) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 19

def extractor(params)
  cursors = params.fetch(:cursors, {}) || {}
  features = params.fetch(:features, {}) || {}

  # XXX can we cache that class across calls?
  ConnectorsSdk::SharePoint::Extractor.new(
    content_source_id: BSON::ObjectId.new,
    service_type: SERVICE_TYPE,
    authorization_data_proc: proc { { access_token: params[:access_token] } },
    client_proc: proc { ConnectorsSdk::Office365::CustomClient.new(:access_token => params[:access_token], :cursors => cursors) },
    config: ConnectorsSdk::Office365::Config.new(:cursors => cursors, :drive_ids => 'all', :index_permissions => params[:index_permissions] || false),
    features: features
  )
end

#nameObject



96
97
98
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 96

def name
  'SharePoint'
end

#permissions(params) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 72

def permissions(params)
  extractor(params).yield_permissions(params[:user_id]) do |permissions|
    return permissions
  end
rescue ConnectorsSdk::Office365::CustomClient::ClientError => e
  raise e.status_code == 401 ? ConnectorsShared::InvalidTokenError : e
end

#refresh(params) ⇒ Object



88
89
90
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 88

def refresh(params)
  ConnectorsSdk::SharePoint::Authorization.refresh(params)
end

#source_status(params) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/connectors_sdk/share_point/http_call_wrapper.rb', line 100

def source_status(params)
  client = ConnectorsSdk::Office365::CustomClient.new(:access_token => params[:access_token])
  client.me
  { :status => 'OK', :statusCode => 200, :message => 'Connected to SharePoint' }
rescue StandardError => e
  { :status => 'FAILURE', :statusCode => e.is_a?(ConnectorsSdk::Office365::CustomClient::ClientError) ? e.status_code : 500, :message => e.message }
end