class Confluence::Api::Client

Constants

VERSION

Attributes

conn[RW]
multiconn[RW]
pass[RW]
url[RW]
user[RW]

Public Class Methods

new(user, pass, url) click to toggle source
# File lib/confluence/api/client.rb, line 10
def initialize(user, pass, url)
  self.user = user
  self.pass = pass
  self.url = url
  self.conn = Faraday.new(url: url ) do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    # faraday.response :logger                  # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    faraday.basic_auth(self.user, self.pass)
  end
  self.multiconn = Faraday.new(url: url ) do |faraday|
    faraday.request  :multipart             # form-encode POST params
    # faraday.response :logger                  # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    faraday.basic_auth(self.user, self.pass)
  end


end

Public Instance Methods

create(params) click to toggle source
# File lib/confluence/api/client.rb, line 63
def create(params)
  response = conn.post do |req|
    req.url '/wiki/rest/api/content'
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end
  JSON.parse(response.body)
end
get(params) click to toggle source
# File lib/confluence/api/client.rb, line 30
def get(params)
  response = conn.get('/wiki/rest/api/content', params)
  JSON.parse(response.body)['results']
end
get_attachments_by_name(page_id,attachment_name) click to toggle source
# File lib/confluence/api/client.rb, line 49
def get_attachments_by_name(page_id,attachment_name)
  response = conn.get('/wiki/rest/api/content/' + page_id + '/child/attachment?filename='+attachment_name)
  JSON.parse(response.body)
end
get_by_id(id) click to toggle source
# File lib/confluence/api/client.rb, line 35
def get_by_id(id)
  response = conn.get('/wiki/rest/api/content/' + id)
  JSON.parse(response.body)
end
update(id, params) click to toggle source
# File lib/confluence/api/client.rb, line 72
def update(id, params)
  response = conn.put do |req|
    req.url "/wiki/rest/api/content/#{id}"
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end
  JSON.parse(response.body)
end
update_file(page_id,attachment_id,file_path) click to toggle source
# File lib/confluence/api/client.rb, line 54
def update_file(page_id,attachment_id,file_path)
  response = multiconn.post do |req|
    req.url '/wiki/rest/api/content/'+page_id+'/child/attachment/' + attachment_id + '/data'
    req.headers['X-Atlassian-Token']= 'nocheck'
    req.body= {file: Faraday::UploadIO.new(File.open(file_path), MimeMagic.by_magic(File.open(file_path))) }
  end
  JSON.parse(response.body)
end
upload_file(page_id,file_path) click to toggle source
# File lib/confluence/api/client.rb, line 40
def upload_file(page_id,file_path)
  response = multiconn.post do |req|
    req.url '/wiki/rest/api/content/'+page_id+'/child/attachment'
    req.headers['X-Atlassian-Token']= 'nocheck'
    req.body= {file: Faraday::UploadIO.new(File.open(file_path), MimeMagic.by_magic(File.open(file_path))) }
  end
  JSON.parse(response.body)
end