Class: Confluence::Api::Client
- Inherits:
-
Object
- Object
- Confluence::Api::Client
- Defined in:
- lib/confluence/api/client.rb,
lib/confluence/api/client/version.rb
Constant Summary collapse
- VERSION =
"0.1.5"
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#multiconn ⇒ Object
Returns the value of attribute multiconn.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #create(params) ⇒ Object
- #get(params) ⇒ Object
- #get_attachments_by_name(page_id, attachment_name) ⇒ Object
- #get_by_id(id) ⇒ Object
-
#initialize(user, pass, url) ⇒ Client
constructor
A new instance of Client.
- #update(id, params) ⇒ Object
- #update_file(page_id, attachment_id, file_path) ⇒ Object
- #upload_file(page_id, file_path) ⇒ Object
Constructor Details
#initialize(user, pass, url) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
9 10 11 |
# File 'lib/confluence/api/client.rb', line 9 def conn @conn end |
#multiconn ⇒ Object
Returns the value of attribute multiconn.
9 10 11 |
# File 'lib/confluence/api/client.rb', line 9 def multiconn @multiconn end |
#pass ⇒ Object
Returns the value of attribute pass.
9 10 11 |
# File 'lib/confluence/api/client.rb', line 9 def pass @pass end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/confluence/api/client.rb', line 9 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/confluence/api/client.rb', line 9 def user @user end |
Instance Method Details
#create(params) ⇒ Object
63 64 65 66 67 68 69 70 |
# 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) ⇒ Object
30 31 32 33 |
# 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) ⇒ Object
49 50 51 52 |
# File 'lib/confluence/api/client.rb', line 49 def (page_id,) response = conn.get('/wiki/rest/api/content/' + page_id + '/child/attachment?filename='+) JSON.parse(response.body) end |
#get_by_id(id) ⇒ Object
35 36 37 38 |
# 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) ⇒ Object
72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/confluence/api/client.rb', line 54 def update_file(page_id,,file_path) response = multiconn.post do |req| req.url '/wiki/rest/api/content/'+page_id+'/child/attachment/' + + '/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) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 |