Class: DiscourseApi::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#api, #generate_master_key, #generate_user_api_key, #regenerate_api_key, #revoke_api_key, #revoke_user_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_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, #groups, #update_group

Methods included from API::Users

#activate, #by_external_id, #create_user, #grant_admin, #invite_admin, #list_users, #log_out, #revoke_admin, #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, #wikify_post

Methods included from API::Topics

#change_topic_status, #create_topic, #create_topic_action, #delete_topic, #edit_topic_timestamp, #latest_topics, #new_topics, #recategorize_topic, #rename_topic, #topic, #topic_posts, #topics_by

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, #category, #category_latest_topics, #category_new_topics, #category_top_topics, #create_category, #update_category

Constructor Details

#initialize(host, api_key = nil, api_username = nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


46
47
48
49
50
51
# File 'lib/discourse_api/client.rb', line 46

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
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



25
26
27
# File 'lib/discourse_api/client.rb', line 25

def api_key
  @api_key
end

#api_usernameObject

Returns the value of attribute api_username.



25
26
27
# File 'lib/discourse_api/client.rb', line 25

def api_username
  @api_username
end

#hostObject (readonly)

Returns the value of attribute host.



26
27
28
# File 'lib/discourse_api/client.rb', line 26

def host
  @host
end

Instance Method Details

#connection_optionsObject



53
54
55
56
57
58
59
60
61
# File 'lib/discourse_api/client.rb', line 53

def connection_options
  @connection_options ||= {
    url: @host,
    headers: {
      accept: 'application/json',
      user_agent: user_agent,
    }
  }
end

#delete(path, params = {}) ⇒ Object



67
68
69
# File 'lib/discourse_api/client.rb', line 67

def delete(path, params={})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Object



71
72
73
# File 'lib/discourse_api/client.rb', line 71

def get(path, params={})
  request(:get, path, params)
end

#patch(path, params = {}) ⇒ Object



89
90
91
# File 'lib/discourse_api/client.rb', line 89

def patch(path, params={})
  request(:patch, path, params)
end

#post(path, params = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/discourse_api/client.rb', line 75

def post(path, params={})
  response = request(:post, path, params)
  case response.status
  when 200
    response.body
  else
    raise DiscourseApi::Error, response.body
  end
end

#put(path, params = {}) ⇒ Object



85
86
87
# File 'lib/discourse_api/client.rb', line 85

def put(path, params={})
  request(:put, path, params)
end

#ssl(options) ⇒ Object



63
64
65
# File 'lib/discourse_api/client.rb', line 63

def ssl(options)
  connection_options[:ssl] = options
end

#user_agentObject



93
94
95
# File 'lib/discourse_api/client.rb', line 93

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