Module: Crowi::ApiMethods

Included in:
Client
Defined in:
lib/crowi/api_methods.rb

Instance Method Summary collapse

Instance Method Details

#add_attachment(page_id, filename, content_type) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/crowi/api_methods.rb', line 32

def add_attachment(page_id, filename, content_type)
  # To use multipart/form-data use faraday directly
  connection = Faraday.new(faraday_options) do |connection|
    connection.request :multipart
    connection.request :url_encoded
    connection.adapter :net_http
  end

  params = { page_id: page_id, file: Faraday::UploadIO.new(filename, content_type), access_token: @access_token }
  Crowi::Response.new(connection.send(:post, '/_api/attachments.add', params))
end

#add_comment(page_id, comment, revision_id) ⇒ Object



24
25
26
# File 'lib/crowi/api_methods.rb', line 24

def add_comment(page_id, comment, revision_id)
  post('/_api/comments.add', { commentForm: {  page_id: page_id, comment: comment, revision_id: revision_id } })
end

#attachments(page_id) ⇒ Object



28
29
30
# File 'lib/crowi/api_methods.rb', line 28

def attachments(page_id)
  get('/_api/attachments.list', { page_id: page_id })
end

#comments(page_id) ⇒ Object



20
21
22
# File 'lib/crowi/api_methods.rb', line 20

def comments(page_id)
  get('/_api/comments.get', { page_id: page_id })
end

#create_page(path, body) ⇒ Object



12
13
14
# File 'lib/crowi/api_methods.rb', line 12

def create_page(path, body)
  post('/_api/pages.create', { path: path, body: body })
end

#page(path) ⇒ Object



3
4
5
# File 'lib/crowi/api_methods.rb', line 3

def page(path)
  get('/_api/pages.get', { path: path })
end

#pages(path = nil, user = nil, offset = 0) ⇒ Object



7
8
9
10
# File 'lib/crowi/api_methods.rb', line 7

def pages(path = nil, user = nil, offset = 0)
  raise 'path or user is required' unless path || user
  get('/_api/pages.list', { path: path, user: user, offset: offset })
end

#update_page(page_id, body) ⇒ Object



16
17
18
# File 'lib/crowi/api_methods.rb', line 16

def update_page(page_id, body)
  post('/_api/pages.update', { page_id: page_id, body: body })
end