Class: DiscourseApi::Client
- Inherits:
-
Object
- Object
- DiscourseApi::Client
- Includes:
- API::ApiKey, API::Backups, API::Badges, API::Categories, API::Dashboard, API::Email, API::Groups, API::Invite, API::Notifications, API::Polls, API::Posts, API::PrivateMessages, API::SSO, API::Search, API::SiteSettings, API::Tags, API::Topics, API::Uploads, API::UserActions, API::Users
- Defined in:
- lib/discourse_api/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_username ⇒ Object
Returns the value of attribute api_username.
-
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #connection_options ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #deprecated(old, new) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(host, api_key = nil, api_username = nil) ⇒ Client
constructor
A new instance of Client.
- #patch(path, params = {}) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #ssl(options) ⇒ Object
- #user_agent ⇒ Object
Methods included from API::SiteSettings
Methods included from API::UserActions
#user_replies, #user_topics_and_replies
Methods included from API::Uploads
Methods included from API::Dashboard
#get_dashboard_stats, #get_dashboard_stats_totals
Methods included from API::Backups
#backups, #create_backup, #download_backup, #restore_backup
Methods included from API::ApiKey
#create_api_key, #delete_api_key, #list_api_keys, #revoke_api_key, #undo_revoke_api_key
Methods included from API::Email
Methods included from API::Badges
#badges, #create_badge, #grant_user_badge, #user_badges
Methods included from API::Notifications
Methods included from API::PrivateMessages
#create_private_message, #private_messages, #sent_private_messages
Methods included from API::Invite
#disposable_tokens, #invite_user, #invite_user_to_topic
Methods included from API::Groups
#create_group, #delete_group, #group, #group_add, #group_members, #group_remove, #group_set_user_notification_level, #groups, #update_group
Methods included from API::Users
#activate, #by_external_id, #check_username, #create_user, #deactivate, #delete_user, #grant_admin, #grant_moderation, #invite_admin, #list_users, #log_out, #revoke_admin, #revoke_moderation, #suspend, #unsuspend, #update_avatar, #update_email, #update_trust_level, #update_user, #update_username, #user, #user_sso
Methods included from API::Posts
#create_post, #create_post_action, #delete_post, #destroy_post_action, #edit_post, #get_post, #post_action_users, #posts, #wikify_post
Methods included from API::Polls
#poll_vote, #poll_voters, #toggle_poll_status
Methods included from API::Topics
#change_owner, #change_topic_status, #create_topic, #create_topic_action, #delete_topic, #edit_topic_timestamp, #latest_topics, #new_topics, #recategorize_topic, #rename_topic, #top_topics, #topic, #topic_posts, #topic_set_user_notification_level, #topics_by, #update_topic_status
Methods included from API::Tags
Methods included from API::SSO
Methods included from API::Search
Methods included from API::Categories
#categories, #categories_full, #category, #category_latest_topics, #category_latest_topics_full, #category_new_topics, #category_new_topics_full, #category_set_user_notification, #category_set_user_notification_level, #category_top_topics, #category_top_topics_full, #create_category, #delete_category, #update_category
Constructor Details
#initialize(host, api_key = nil, api_username = nil) ⇒ Client
Returns a new instance of Client.
55 56 57 58 59 60 61 |
# File 'lib/discourse_api/client.rb', line 55 def initialize(host, api_key = nil, api_username = nil) raise ArgumentError, 'host needs to be defined' if host.nil? || host.empty? @host = host @api_key = api_key @api_username = api_username @use_relative = check_subdirectory(host) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
30 31 32 |
# File 'lib/discourse_api/client.rb', line 30 def api_key @api_key end |
#api_username ⇒ Object
Returns the value of attribute api_username.
32 33 34 |
# File 'lib/discourse_api/client.rb', line 32 def api_username @api_username end |
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
31 32 33 |
# File 'lib/discourse_api/client.rb', line 31 def basic_auth @basic_auth end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
32 33 34 |
# File 'lib/discourse_api/client.rb', line 32 def host @host end |
Instance Method Details
#connection_options ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/discourse_api/client.rb', line 68 def @connection_options ||= { url: @host, headers: { accept: 'application/json', user_agent: user_agent, } } end |
#delete(path, params = {}) ⇒ Object
82 83 84 |
# File 'lib/discourse_api/client.rb', line 82 def delete(path, params = {}) request(:delete, path, params) end |
#deprecated(old, new) ⇒ Object
112 113 114 |
# File 'lib/discourse_api/client.rb', line 112 def deprecated(old, new) warn "[DEPRECATED]: `#{old}` is deprecated. Please use `#{new}` instead." end |
#get(path, params = {}) ⇒ Object
86 87 88 |
# File 'lib/discourse_api/client.rb', line 86 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
104 105 106 |
# File 'lib/discourse_api/client.rb', line 104 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/discourse_api/client.rb', line 90 def post(path, params = {}) response = request(:post, path, params) case response.status when 200, 201, 204 response.body else raise DiscourseApi::Error, response.body end end |
#put(path, params = {}) ⇒ Object
100 101 102 |
# File 'lib/discourse_api/client.rb', line 100 def put(path, params = {}) request(:put, path, params) end |
#ssl(options) ⇒ Object
78 79 80 |
# File 'lib/discourse_api/client.rb', line 78 def ssl() [:ssl] = end |
#user_agent ⇒ Object
108 109 110 |
# File 'lib/discourse_api/client.rb', line 108 def user_agent @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}" end |