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::Posts, API::PrivateMessages, API::SSO, API::Search, API::Tags, API::Topics, 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.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #connection_options ⇒ Object
- #delete(path, params = {}) ⇒ 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::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
Methods included from API::Badges
#badges, #create_badge, #grant_user_badge, #user_badges
Methods included from API::Notifications
Methods included from API::PrivateMessages
Methods included from API::Invite
#disposable_tokens, #invite_user, #invite_user_to_topic
Methods included from API::Groups
#create_group, #delete_group, #group_add, #group_remove, #groups
Methods included from API::Users
#activate, #by_external_id, #create_user, #grant_admin, #invite_admin, #list_users, #log_out, #revoke_admin, #update_avatar, #update_email, #update_trust_level, #update_user, #update_username, #user, #user_sso
Methods included from API::Posts
#create_post, #edit_post, #get_post, #wikify_post
Methods included from API::Topics
#create_topic, #delete_topic, #latest_topics, #new_topics, #recategorize_topic, #rename_topic, #topic, #topic_posts, #topics_by
Methods included from API::Tags
Methods included from API::SSO
Methods included from API::Search
Methods included from API::Categories
#categories, #category, #category_latest_topics, #category_new_topics, #category_top_topics, #create_category
Constructor Details
#initialize(host, api_key = nil, api_username = nil) ⇒ Client
Returns a new instance of Client.
44 45 46 47 48 49 |
# File 'lib/discourse_api/client.rb', line 44 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_key ⇒ Object
Returns the value of attribute api_key.
24 25 26 |
# File 'lib/discourse_api/client.rb', line 24 def api_key @api_key end |
#api_username ⇒ Object
Returns the value of attribute api_username.
24 25 26 |
# File 'lib/discourse_api/client.rb', line 24 def api_username @api_username end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/discourse_api/client.rb', line 25 def host @host end |
Instance Method Details
#connection_options ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/discourse_api/client.rb', line 51 def ||= { url: @host, headers: { accept: 'application/json', user_agent: user_agent, } } end |
#delete(path, params = {}) ⇒ Object
65 66 67 |
# File 'lib/discourse_api/client.rb', line 65 def delete(path, params={}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
69 70 71 |
# File 'lib/discourse_api/client.rb', line 69 def get(path, params={}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
87 88 89 |
# File 'lib/discourse_api/client.rb', line 87 def patch(path, params={}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/discourse_api/client.rb', line 73 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
83 84 85 |
# File 'lib/discourse_api/client.rb', line 83 def put(path, params={}) request(:put, path, params) end |
#ssl(options) ⇒ Object
61 62 63 |
# File 'lib/discourse_api/client.rb', line 61 def ssl() [:ssl] = end |
#user_agent ⇒ Object
91 92 93 |
# File 'lib/discourse_api/client.rb', line 91 def user_agent @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}" end |