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
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
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.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
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_pm, #create_private_message, #private_messages, #sent_private_messages
Methods included from API::Invite
#destroy_all_expired_invites, #destroy_invite, #disposable_tokens, #invite_to_topic, #invite_user, #invite_user_to_topic, #resend_all_invites, #resend_invite, #retrieve_invite, #update_invite
Methods included from API::Groups
#create_group, #delete_group, #group, #group_add, #group_add_owners, #group_members, #group_remove, #group_remove_owners, #group_set_user_notification_level, #groups, #update_group
Methods included from API::Users
#activate, #anonymize, #by_external_id, #check_username, #create_user, #deactivate, #delete_user, #grant_admin, #grant_moderation, #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
#bookmark_topic, #change_owner, #change_topic_status, #create_topic, #create_topic_action, #delete_topic, #edit_topic_timestamp, #latest_topics, #new_topics, #recategorize_topic, #remove_topic_bookmark, #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, #reorder_categories, #update_category
Constructor Details
#initialize(host, api_key = nil, api_username = nil) ⇒ Client
Returns a new instance of Client.
58 59 60 61 62 63 64 |
# File 'lib/discourse_api/client.rb', line 58 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.
31 32 33 |
# File 'lib/discourse_api/client.rb', line 31 def api_key @api_key end |
#api_username ⇒ Object
Returns the value of attribute api_username.
33 34 35 |
# File 'lib/discourse_api/client.rb', line 33 def api_username @api_username end |
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
32 33 34 |
# File 'lib/discourse_api/client.rb', line 32 def basic_auth @basic_auth end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
33 34 35 |
# File 'lib/discourse_api/client.rb', line 33 def host @host end |
#timeout ⇒ Object
Returns the value of attribute timeout.
33 34 35 |
# File 'lib/discourse_api/client.rb', line 33 def timeout @timeout end |
Instance Method Details
#connection_options ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/discourse_api/client.rb', line 76 def @connection_options ||= { url: @host, request: { timeout: @timeout || DEFAULT_TIMEOUT, }, headers: { accept: "application/json", user_agent: user_agent, }, } end |
#delete(path, params = {}) ⇒ Object
93 94 95 |
# File 'lib/discourse_api/client.rb', line 93 def delete(path, params = {}) request(:delete, path, params) end |
#deprecated(old, new) ⇒ Object
123 124 125 |
# File 'lib/discourse_api/client.rb', line 123 def deprecated(old, new) warn "[DEPRECATED]: `#{old}` is deprecated. Please use `#{new}` instead." end |
#get(path, params = {}) ⇒ Object
97 98 99 |
# File 'lib/discourse_api/client.rb', line 97 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
115 116 117 |
# File 'lib/discourse_api/client.rb', line 115 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/discourse_api/client.rb', line 101 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
111 112 113 |
# File 'lib/discourse_api/client.rb', line 111 def put(path, params = {}) request(:put, path, params) end |
#ssl(options) ⇒ Object
89 90 91 |
# File 'lib/discourse_api/client.rb', line 89 def ssl() [:ssl] = end |
#user_agent ⇒ Object
119 120 121 |
# File 'lib/discourse_api/client.rb', line 119 def user_agent @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}" end |