Class: GithubControl::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/github-control/console.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_config) ⇒ Console

Returns a new instance of Console.



3
4
5
6
# File 'lib/github-control/console.rb', line 3

def initialize(user_config)
  @user_config = user_config
  @users = {}
end

Instance Method Details

#current_userObject



8
9
10
# File 'lib/github-control/console.rb', line 8

def current_user
  @current_user ||= user_for(user_name)
end

#inspectObject



45
46
47
# File 'lib/github-control/console.rb', line 45

def inspect
  "#<#{self.class} logged in as #{current_user.name.inspect}>"
end

#post(path, params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/github-control/console.rb', line 16

def post(path, params={})
  params.merge!(:login => user_name, :token => user_token)
  data = JSON.parse(Rack::Client.post(url_for(path), params).body)
  if error = data["error"]
    raise APIError, error.inspect
  else
    data
  end
end

#url_for(path) ⇒ Object



26
27
28
# File 'lib/github-control/console.rb', line 26

def url_for(path)
  "http://github.com/api/v2/json#{path}"
end

#user_for(name) ⇒ Object



12
13
14
# File 'lib/github-control/console.rb', line 12

def user_for(name)
  @users[name] ||= User.new(self, name)
end

#user_nameObject



30
31
32
33
# File 'lib/github-control/console.rb', line 30

def user_name
  @user_config["name"] ||
    raise(ProblemWithOptions, "You need to provide the user name in the YAML file")
end

#user_passwordObject



40
41
42
43
# File 'lib/github-control/console.rb', line 40

def user_password
  @user_config["password"] ||
    raise(ProblemWithOptions, "You need to provide the user password in the YAML file")
end

#user_tokenObject



35
36
37
38
# File 'lib/github-control/console.rb', line 35

def user_token
  @user_config["token"] ||
    raise(ProblemWithOptions, "You need to provide the user token in the YAML file")
end