Module: Octokit::Client::Users

Included in:
Octokit::Client
Defined in:
lib/octokit/client/users.rb

Constant Summary collapse

EMAIL_RE =
/[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/

Instance Method Summary collapse

Instance Method Details

#add_email(email, options = {}) ⇒ Object



94
95
96
# File 'lib/octokit/client/users.rb', line 94

def add_email(email, options={})
  post("/user/emails", options.merge({:email => email}), 3)
end

#add_key(title, key, options = {}) ⇒ Object



82
83
84
# File 'lib/octokit/client/users.rb', line 82

def add_key(title, key, options={})
  post("/user/keys", options.merge({:title => title, :key => key}), 3)
end

#emails(options = {}) ⇒ Object



90
91
92
# File 'lib/octokit/client/users.rb', line 90

def emails(options={})
  get("/user/emails", options, 3)
end

#follow(user, options = {}) ⇒ Object



64
65
66
# File 'lib/octokit/client/users.rb', line 64

def follow(user, options={})
  put("/user/following/#{user}", options, 3, true, raw=true).status == 204
end

#followers(user = login, options = {}) ⇒ Object



46
47
48
# File 'lib/octokit/client/users.rb', line 46

def followers(user=, options={})
  get("/users/#{user}/followers", options, 3)
end

#following(user = login, options = {}) ⇒ Object



50
51
52
# File 'lib/octokit/client/users.rb', line 50

def following(user=, options={})
  get("/users/#{user}/following", options, 3)
end

#follows?(*args) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
# File 'lib/octokit/client/users.rb', line 54

def follows?(*args)
  target = args.pop
  user = args.first
  user ||= 
  return if user.nil?
  get("/user/following/#{target}", {}, 3, true, raw=true).status == 204
rescue Octokit::NotFound
  false
end

#keys(options = {}) ⇒ Object

Not yet supported: get a single key, update an existing key



78
79
80
# File 'lib/octokit/client/users.rb', line 78

def keys(options={})
  get("/user/keys", options, 3)
end

#remove_email(email, options = {}) ⇒ Object



98
99
100
# File 'lib/octokit/client/users.rb', line 98

def remove_email(email, options={})
  delete("/user/emails", options.merge({:email => email}), 3, true, raw=true).status == 204
end

#remove_key(id, options = {}) ⇒ Object



86
87
88
# File 'lib/octokit/client/users.rb', line 86

def remove_key(id, options={})
  delete("/user/keys/#{id}", options, 3, true, raw=true)
end

#search_users(search, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/octokit/client/users.rb', line 6

def search_users(search, options={})
  if search.match(EMAIL_RE)
    warn 'DEPRECATED: V3 of the API does not allow searching users by email'
    get("/api/v2/json/user/email/#{search}", options, 2)['user']
  else
    get("/legacy/user/search/#{search}", options, 3)['users']
  end
end

#unfollow(user, options = {}) ⇒ Object



68
69
70
# File 'lib/octokit/client/users.rb', line 68

def unfollow(user, options={})
  delete("/user/following/#{user}", options, 3, true, raw=true).status == 204
end

#update_user(options) ⇒ Hashie::Mash

Update the authenticated user

Examples:

Octokit.user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)

Parameters:

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :name (String)
  • :email (String)

    Publically visible email address.

  • :blog (String)
  • :company (String)
  • :location (String)
  • :hireable (Boolean)
  • :bio (String)

Returns:

  • (Hashie::Mash)


42
43
44
# File 'lib/octokit/client/users.rb', line 42

def update_user(options)
  patch("/user", options, 3)
end

#user(user = nil) ⇒ Hashie::Mash

Get a single user

Examples:

Octokit.user("sferik")

Parameters:

  • user (String) (defaults to: nil)

    A GitHub user name.

Returns:

  • (Hashie::Mash)


21
22
23
24
25
26
27
# File 'lib/octokit/client/users.rb', line 21

def user(user=nil)
  if user
    get("/users/#{user}", {}, 3)
  else
    get("/user", {}, 3)
  end
end

#watched(user = login, options = {}) ⇒ Object



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

def watched(user=, options={})
  get("/users/#{user}/watched", options, 3)
end