Class: Github::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/github/client.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  access_token: nil,
  user: {}
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

stores user access_token to make authenticated requests



14
15
16
17
# File 'lib/github/client.rb', line 14

def initialize(options={})
  store_options(options)
  check_token
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/github/client.rb', line 11

def options
  @options
end

Instance Method Details

#access_tokenObject

returns user access_token



20
21
22
# File 'lib/github/client.rb', line 20

def access_token
  @options[:access_token]
end

#email(options = {}) ⇒ Object

getter for email



57
58
59
60
61
62
63
# File 'lib/github/client.rb', line 57

def email(options={})
  if options.empty?
    user["email"]
  else
    user(options)["email"]
  end
end

#html_url(options = {}) ⇒ Object

getter for user page url



66
67
68
69
70
71
72
# File 'lib/github/client.rb', line 66

def html_url(options={})
  if options.empty?
    user["html_url"]
  else
    user(options)["html_url"]
  end
end

#login(options = {}) ⇒ Object

getter for login



48
49
50
51
52
53
54
# File 'lib/github/client.rb', line 48

def (options={})
  if options.empty?
    user["login"]
  else
    options[:login]
  end
end

#name(options = {}) ⇒ Object

getter for name



39
40
41
42
43
44
45
# File 'lib/github/client.rb', line 39

def name(options={})
  if options.empty? 
    user["name"]
  else
    user(options)["name"]
  end
end

#repos(options = {}) ⇒ Object

fetches user’s repositories and wraps them in RepoResponseWrapper



84
85
86
# File 'lib/github/client.rb', line 84

def repos(options={})
  Github::ReposResponseWrapper.new(request(repos_url(options), access_token), access_token)
end

#repos_url(options = {}) ⇒ Object

getter for url to get repositories from API



75
76
77
78
79
80
81
# File 'lib/github/client.rb', line 75

def repos_url(options={})
  if options.empty?
    user['repos_url']
  else
    user(options)['repos_url']
  end
end

#user(options = {}) ⇒ Object

fetches user information from github API using access_token to identify user



26
27
28
29
30
31
32
# File 'lib/github/client.rb', line 26

def user(options={})
  if options.empty?
    get_user('user') if options.empty?
  else
    get_user("users/#{options[:login]}") 
  end
end