Class: BackchatClient::User
- Inherits:
-
Object
- Object
- BackchatClient::User
- Includes:
- BackchatLogger, HttpClient
- Defined in:
- lib/backchat_client/user.rb
Overview
A Backchat User is a developer that has an api_key and can create applications using Backchat API
Constant Summary collapse
- URI_PATH =
no suffix for user path
nil
Instance Method Summary collapse
-
#destroy ⇒ Object
Delete user account.
-
#find ⇒ Object
this method return the user profile in case that the token provided is valid.
-
#initialize(api_key, endpoint) ⇒ User
constructor
A new instance of User.
Methods included from BackchatLogger
#debug, #error, included, #logger
Methods included from HttpClient
#delete, #get, #post, #put, #response_handler
Constructor Details
#initialize(api_key, endpoint) ⇒ User
Returns a new instance of User.
20 21 22 23 |
# File 'lib/backchat_client/user.rb', line 20 def initialize(api_key, endpoint) @api_key = api_key @endpoint = endpoint end |
Instance Method Details
#destroy ⇒ Object
Delete user account
28 29 30 |
# File 'lib/backchat_client/user.rb', line 28 def destroy delete("") end |
#find ⇒ Object
this method return the user profile in case that the token provided is valid
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/backchat_client/user.rb', line 35 def find begin debug("Fetching user profile") data = get("index.json") if data.is_a?(String) data = ActiveSupport::JSON.decode(data) if data.has_key?("data") data["data"] else nil end end rescue BackchatClient::Error::ClientError => ex error "Invalid api_key #{@api_key}" nil # Invalid token rescue Exception => ex logger.error " Unexpected error" logger.error ex.inspect nil # Unexpected error end end |