Class: Localwiki::Client
- Inherits:
-
Object
- Object
- Localwiki::Client
- Defined in:
- lib/localwiki/client.rb
Overview
A client that wraps the localwiki api for a given server instance
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hostname ⇒ Object
hostname of the server we’d like to point at.
-
#language_code ⇒ Object
readonly
site resource - language code of the server, e.g.
-
#site_name ⇒ Object
readonly
site resource - display name of wiki.
-
#time_zone ⇒ Object
readonly
site resource - time zone of server, e.g.
Instance Method Summary collapse
-
#count(resource) ⇒ Object
Request total count of given resource.
-
#create(resource, json) ⇒ Object
create a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag”.
-
#delete(resource, identifier) ⇒ Object
delete a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc.
-
#fetch(resource, identifier, params = {}) ⇒ Object
fetch a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc.
-
#initialize(hostname, user = nil, apikey = nil) ⇒ Client
constructor
Create a LocalWikiClient instance.
-
#list(resource, limit = 0, params = {}) ⇒ Object
list of a specific type of resource.
-
#page_by_name(name) ⇒ Object
fetch a page by name (“The Page Name” or “The_Page_Name” or “the page name”).
-
#update(resource, identifier, json) ⇒ Object
update a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc.
Constructor Details
#initialize(hostname, user = nil, apikey = nil) ⇒ Client
Create a LocalWikiClient instance
@example LocalwikiClient.new 'seattlewiki.net'
21 22 23 24 25 26 27 |
# File 'lib/localwiki/client.rb', line 21 def initialize hostname, user=nil, apikey=nil @hostname = hostname @user = user @apikey = apikey create_connection collect_site_details end |
Instance Attribute Details
#hostname ⇒ Object
hostname of the server we’d like to point at
11 12 13 |
# File 'lib/localwiki/client.rb', line 11 def hostname @hostname end |
#language_code ⇒ Object (readonly)
site resource - language code of the server, e.g. ‘en-us’
14 15 16 |
# File 'lib/localwiki/client.rb', line 14 def language_code @language_code end |
#site_name ⇒ Object (readonly)
site resource - display name of wiki
12 13 14 |
# File 'lib/localwiki/client.rb', line 12 def site_name @site_name end |
#time_zone ⇒ Object (readonly)
site resource - time zone of server, e.g. ‘America/Chicago’
13 14 15 |
# File 'lib/localwiki/client.rb', line 13 def time_zone @time_zone end |
Instance Method Details
#count(resource) ⇒ Object
Request total count of given resource
32 33 34 |
# File 'lib/localwiki/client.rb', line 32 def count(resource) list(resource.to_s,1)["meta"]["total_count"] end |
#create(resource, json) ⇒ Object
create a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag”
67 68 69 70 |
# File 'lib/localwiki/client.rb', line 67 def create(resource, json) uri = '/api/' + resource.to_s + '/' http_post(uri, json) end |
#delete(resource, identifier) ⇒ Object
delete a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc.
85 86 87 88 |
# File 'lib/localwiki/client.rb', line 85 def delete(resource,identifier) uri = '/api/' + resource.to_s + '/' + identifier http_delete(uri) end |
#fetch(resource, identifier, params = {}) ⇒ Object
fetch a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc. params is a hash of query string params
59 60 61 62 |
# File 'lib/localwiki/client.rb', line 59 def fetch(resource,identifier,params={}) uri = '/api/' + resource.to_s + '/' + identifier http_get(uri,params) end |
#list(resource, limit = 0, params = {}) ⇒ Object
list of a specific type of resource
48 49 50 51 52 |
# File 'lib/localwiki/client.rb', line 48 def list(resource,limit=0,params={}) uri = '/api/' + resource.to_s params.merge!({limit: limit.to_s}) http_get(uri,params) end |
#page_by_name(name) ⇒ Object
fetch a page by name (“The Page Name” or “The_Page_Name” or “the page name”)
39 40 41 |
# File 'lib/localwiki/client.rb', line 39 def page_by_name(name) fetch(:page,"#{name.gsub!(/\s/, '_')}") end |
#update(resource, identifier, json) ⇒ Object
update a specific resource resources are “site”, “page”, “user”, “file”, “map”, “tag”, “page_tag” identifier is id, pagename, slug, etc.
76 77 78 79 |
# File 'lib/localwiki/client.rb', line 76 def update(resource,identifier,json) uri = '/api/' + resource.to_s + '/' + identifier http_put(uri, json) end |