Class: OTX::Users
Overview
Search for, subscribe to, unsubscribe from, follow and unfollow users
Instance Method Summary collapse
-
#action(username, action) ⇒ Object
Perform an action on a User.
-
#follow(username) ⇒ Object
Follow a User.
-
#me ⇒ OTX::User
Validate your API Key configuration.
-
#search(query, limit = 10, page = 1, sort = :username) ⇒ Array<OTX::User>
Search for Users by username.
-
#subscribe_to(username) ⇒ Object
Subscribe to a User.
-
#unfollow(username) ⇒ Object
Unfollow a User.
-
#unsubscribe_from(username) ⇒ Object
Unsubscribe from a User.
Methods inherited from Base
#get, #initialize, #patch, #post
Constructor Details
This class inherits a constructor from OTX::Base
Instance Method Details
#action(username, action) ⇒ Object
Perform an action on a User
91 92 93 94 95 |
# File 'lib/otx_ruby/users.rb', line 91 def action(username, action) uri = "/api/v1/users/#{username}/#{action}" post(uri) end |
#follow(username) ⇒ Object
Follow a User
72 73 74 |
# File 'lib/otx_ruby/users.rb', line 72 def follow(username) action(username, 'follow') end |
#me ⇒ OTX::User
Validate your API Key configuration. If valid, some basic information about the user account corresponding to the API Key supplied will be returned.
11 12 13 14 15 16 17 18 19 |
# File 'lib/otx_ruby/users.rb', line 11 def me uri = "/api/v1/users/me" json_data = get(uri) user = OTX::User.new(json_data) return user end |
#search(query, limit = 10, page = 1, sort = :username) ⇒ Array<OTX::User>
Search for Users by username
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/otx_ruby/users.rb', line 30 def search(query, limit = 10, page = 1, sort = :username) uri = '/api/v1/search/users' params = { q: query, limit: limit, page: page, sort: sort == :pulse_count ? 'pulse_count' : 'username' } results = [] json_data = get(uri, params) json_data['results'].each do |user| results << OTX::User.new(user) end return results end |
#subscribe_to(username) ⇒ Object
Subscribe to a User
54 55 56 |
# File 'lib/otx_ruby/users.rb', line 54 def subscribe_to(username) action(username, 'subscribe') end |
#unfollow(username) ⇒ Object
Unfollow a User
81 82 83 |
# File 'lib/otx_ruby/users.rb', line 81 def unfollow(username) action(username, 'unfollow') end |
#unsubscribe_from(username) ⇒ Object
Unsubscribe from a User
63 64 65 |
# File 'lib/otx_ruby/users.rb', line 63 def unsubscribe_from(username) action(username, 'unsubscribe') end |