Class: OTX::Users

Inherits:
Base
  • Object
show all
Defined in:
lib/otx_ruby/users.rb

Overview

Search for, subscribe to, unsubscribe from, follow and unfollow users

Instance Method Summary collapse

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

Parameters:

  • useranme (String)

    Username of the User you wish to perform an action on

  • action (String)

    Action you wish to perform on the 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

Parameters:

  • useranme (String)

    Username of the User you wish to follow



72
73
74
# File 'lib/otx_ruby/users.rb', line 72

def follow(username)
  action(username, 'follow')
end

#meOTX::User

Validate your API Key configuration. If valid, some basic information about the user account corresponding to the API Key supplied will be returned.

Returns:



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

Parameters:

  • query (String)

    Full or partial username to search

  • limit (Integer) (defaults to: 10)

    Limit results per page to this number

  • page (Integer) (defaults to: 1)

    Return results for this page

  • sort (Symbol) (defaults to: :username)

    Sort results by username or pulse_count

Returns:



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

Parameters:

  • useranme (String)

    Username of the User you wish to subscribe to



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

Parameters:

  • useranme (String)

    Username of the User you wish to unfollow



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

Parameters:

  • useranme (String)

    Username of the User you wish to unsubscribe from



63
64
65
# File 'lib/otx_ruby/users.rb', line 63

def unsubscribe_from(username)
  action(username, 'unsubscribe')
end