Class: Wikiwiki::API
- Inherits:
-
Object
- Object
- Wikiwiki::API
- Defined in:
- lib/wikiwiki/api.rb
Overview
Handles HTTP communication with the Wikiwiki REST API
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#delete_attachment(encoded_page_name:, encoded_attachment_name:) ⇒ void
Delete an attachment from a page.
-
#get_attachment(encoded_page_name:, encoded_attachment_name:, rev: nil) ⇒ Hash
Get a specific attachment.
-
#get_attachments(encoded_page_name:) ⇒ Hash
Get list of attachments on a page.
-
#get_page(encoded_page_name:) ⇒ Hash
Get a specific page.
-
#get_pages ⇒ Hash
Get list of all pages.
-
#initialize(wiki_id:, auth:, logger:, rate_limiter: RateLimiter.default) ⇒ API
constructor
Initialize a new API client and authenticate.
-
#put_attachment(encoded_page_name:, attachment_name:, encoded_content:) ⇒ void
Upload an attachment to a page.
-
#put_page(encoded_page_name:, source:) ⇒ void
Update a page.
Constructor Details
#initialize(wiki_id:, auth:, logger:, rate_limiter: RateLimiter.default) ⇒ API
Initialize a new API client and authenticate
29 30 31 32 33 34 |
# File 'lib/wikiwiki/api.rb', line 29 def initialize(wiki_id:, auth:, logger:, rate_limiter: RateLimiter.default) @wiki_id = wiki_id @rate_limiter = rate_limiter @logger = logger @token = authenticate(auth) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/wikiwiki/api.rb', line 16 def logger @logger end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
17 18 19 |
# File 'lib/wikiwiki/api.rb', line 17 def token @token end |
Instance Method Details
#delete_attachment(encoded_page_name:, encoded_attachment_name:) ⇒ void
This method returns an undefined value.
Delete an attachment from a page
120 121 122 123 124 125 |
# File 'lib/wikiwiki/api.rb', line 120 def (encoded_page_name:, encoded_attachment_name:) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}/attachment/#{encoded_attachment_name}" response = request(:delete, uri) parse_json_response(response) end |
#get_attachment(encoded_page_name:, encoded_attachment_name:, rev: nil) ⇒ Hash
Get a specific attachment
92 93 94 95 96 97 98 |
# File 'lib/wikiwiki/api.rb', line 92 def (encoded_page_name:, encoded_attachment_name:, rev: nil) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}/attachment/#{encoded_attachment_name}" uri.query = "rev=#{rev}" if rev response = request(:get, uri) parse_json_response(response) end |
#get_attachments(encoded_page_name:) ⇒ Hash
Get list of attachments on a page
78 79 80 81 82 83 |
# File 'lib/wikiwiki/api.rb', line 78 def (encoded_page_name:) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}/attachments" response = request(:get, uri) parse_json_response(response) end |
#get_page(encoded_page_name:) ⇒ Hash
Get a specific page
52 53 54 55 56 57 |
# File 'lib/wikiwiki/api.rb', line 52 def get_page(encoded_page_name:) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}" response = request(:get, uri) parse_json_response(response) end |
#get_pages ⇒ Hash
Get list of all pages
40 41 42 43 44 45 |
# File 'lib/wikiwiki/api.rb', line 40 def get_pages uri = BASE_URL + "/#{wiki_id}/pages" response = request(:get, uri) parse_json_response(response) end |
#put_attachment(encoded_page_name:, attachment_name:, encoded_content:) ⇒ void
This method returns an undefined value.
Upload an attachment to a page
107 108 109 110 111 112 |
# File 'lib/wikiwiki/api.rb', line 107 def (encoded_page_name:, attachment_name:, encoded_content:) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}/attachment" response = request(:put, uri, body: {"filename" => , "data" => encoded_content}) parse_json_response(response) end |
#put_page(encoded_page_name:, source:) ⇒ void
Passing an empty string as source will delete the page
This method returns an undefined value.
Update a page
66 67 68 69 70 71 |
# File 'lib/wikiwiki/api.rb', line 66 def put_page(encoded_page_name:, source:) uri = BASE_URL + "/#{wiki_id}/page/#{encoded_page_name}" response = request(:put, uri, body: {"source" => source}) parse_json_response(response) end |