Class: DiscourseApi::Client

Inherits:
Object
  • Object
show all
Includes:
API::Categories, API::Invite, API::Notifications, API::PrivateMessages, API::SSO, API::Search, API::Topics, API::Users
Defined in:
lib/discourse_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::Notifications

#notifications

Methods included from API::PrivateMessages

#private_messages

Methods included from API::Invite

#disposable_tokens, #invite_user, #invite_user_to_topic

Methods included from API::Users

#activate, #create_user, #update_avatar, #update_email, #update_user, #update_username, #user

Methods included from API::Topics

#create_topic, #delete_topic, #latest_topics, #new_topics, #recategorize_topic, #rename_topic, #topic, #topics_by

Methods included from API::SSO

#sync_sso

Methods included from API::Search

#search

Methods included from API::Categories

#categories, #category_latest_topics

Constructor Details

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

Returns a new instance of Client.



28
29
30
31
32
# File 'lib/discourse_api/client.rb', line 28

def initialize(host, api_key=nil, api_username=nil)
  @host         = host
  @api_key      = api_key
  @api_username = api_username
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



16
17
18
# File 'lib/discourse_api/client.rb', line 16

def api_key
  @api_key
end

#api_usernameObject

Returns the value of attribute api_username.



16
17
18
# File 'lib/discourse_api/client.rb', line 16

def api_username
  @api_username
end

#hostObject (readonly)

Returns the value of attribute host.



17
18
19
# File 'lib/discourse_api/client.rb', line 17

def host
  @host
end

Instance Method Details

#connection_optionsObject



34
35
36
37
38
39
40
41
42
# File 'lib/discourse_api/client.rb', line 34

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

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



44
45
46
# File 'lib/discourse_api/client.rb', line 44

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

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



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

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

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



52
53
54
# File 'lib/discourse_api/client.rb', line 52

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

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



56
57
58
# File 'lib/discourse_api/client.rb', line 56

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

#user_agentObject



60
61
62
# File 'lib/discourse_api/client.rb', line 60

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