Class: GithubControl::Console
- Inherits:
-
Object
- Object
- GithubControl::Console
- Defined in:
- lib/github-control/console.rb
Instance Method Summary collapse
- #current_user ⇒ Object
-
#initialize(user_config) ⇒ Console
constructor
A new instance of Console.
- #inspect ⇒ Object
- #post(path, params = {}) ⇒ Object
- #url_for(path) ⇒ Object
- #user_for(name) ⇒ Object
- #user_name ⇒ Object
- #user_password ⇒ Object
- #user_token ⇒ Object
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_user ⇒ Object
8 9 10 |
# File 'lib/github-control/console.rb', line 8 def current_user @current_user ||= user_for(user_name) end |
#inspect ⇒ Object
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_name ⇒ Object
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_password ⇒ Object
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_token ⇒ Object
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 |