Class: DiscourseApi::Client

Constant Summary collapse

DEFAULT_TIMEOUT =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::SiteSettings

#site_setting_update

Methods included from API::UserActions

#user_replies, #user_topics_and_replies

Methods included from API::Uploads

#upload_file

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

#email_settings, #list_email

Methods included from API::Badges

#badges, #create_badge, #grant_user_badge, #user_badges

Methods included from API::Notifications

#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

#show_tag

Methods included from API::SSO

#sync_sso

Methods included from API::Search

#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.

Raises:

  • (ArgumentError)


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_keyObject

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_usernameObject

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_authObject

Returns the value of attribute basic_auth.



32
33
34
# File 'lib/discourse_api/client.rb', line 32

def basic_auth
  @basic_auth
end

#hostObject (readonly)

Returns the value of attribute host.



33
34
35
# File 'lib/discourse_api/client.rb', line 33

def host
  @host
end

#timeoutObject

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_optionsObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/discourse_api/client.rb', line 76

def connection_options
  @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(options)
  connection_options[:ssl] = options
end

#user_agentObject



119
120
121
# File 'lib/discourse_api/client.rb', line 119

def user_agent
  @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}"
end