Class: GithubCLI::API

Inherits:
Object
  • Object
show all
Defined in:
lib/github_cli/api.rb

Overview

The API class is the main entry point for creating GithubCLI APIs.

Defined Under Namespace

Classes: All

Constant Summary collapse

@@api =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/github_cli/api.rb', line 12

def config
  @config
end

Class Method Details

.configure_apiObject

this could become a command such as configure that gets class options



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/github_cli/api.rb', line 24

def configure_api
  @@api = Github.new
  config = GithubCLI.config.data

  if config['user.token']
    @@api.oauth_token = config['user.token']
  end
  if config['user.login'] && config['user.password']
    @@api.basic_auth = "#{config['user.login']}:#{config['user.password']}"
  end
  @@api.endpoint = GithubCLI.config['core.endpoint'] || @@api.endpoint
  if ENV['TEST_HOST']
    @@api.endpoint = 'http://' + ENV['TEST_HOST']
  end
  @@api
end

.github_apiObject



14
15
16
17
18
# File 'lib/github_cli/api.rb', line 14

def github_api
  @@api ||= begin
    @@api = configure_api
  end
end

.output(format = :table, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/github_cli/api.rb', line 41

def output(format=:table, &block)
  GithubCLI.on_error do
    response  = block.call
    if response.respond_to?(:body)
      formatter = Formatter.new response, :format => format
      formatter.render_output
    else
      response
    end
  end
end