Module: Blend::Client

Defined in:
lib/blend/client.rb,
lib/blend/client/juice_client.rb,
lib/blend/client/github_client.rb,
lib/blend/client/heroku_client.rb,
lib/blend/client/hipchat_client.rb

Defined Under Namespace

Classes: GithubClient, HerokuClient, HipchatClient, JuiceClient

Class Method Summary collapse

Class Method Details

.get_token(type) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/blend/client.rb', line 35

def get_token( type )
  token = case type

  #when :juice
    # Don't use this. This is already handled together with the login
    # stuff in JuiceClient. It could be refactored to fit in with this
    # method a little better, but what'd be the point? It works and
    # it's straightforward.
  when :hipchat
    ENV['HIPCHAT_API_TOKEN'] || juice_client.hipchat_api
  when :github
    ENV['GITHUB_API_TOKEN'] || juice_client.auth( "github" )
  when :heroku
    # Opt for the organization-wide heroku api token:
    ENV['HEROKU_API_TOKEN'] || juice_client.heroku_api
    # Instead of per-user heroku auth:
    #ENV['HEROKU_API_TOKEN'] || juice_client.auth( "heroku" )
  else
    throw "Unknown token type #{type}".red
  end

  
  throw "Token not found for #{type}" if token.nil? || token == ""

  token
end

.github_clientObject



13
14
15
# File 'lib/blend/client.rb', line 13

def github_client
  @github_client ||= Blend::Client::GithubClient.new( Github.new( oauth_token: get_token( :github ) ) )
end

.heroku_clientObject



31
32
33
# File 'lib/blend/client.rb', line 31

def heroku_client
  @heroku_client ||= Blend::Client::HerokuClient.new( Heroku::API.new( api_key: get_token( :heroku ) ) )
end

.hipchat_clientObject



9
10
11
# File 'lib/blend/client.rb', line 9

def hipchat_client
  @hipchat_client ||= Blend::Client::HipchatClient.new( HipChat::API.new( get_token( :hipchat ) ) )
end

.juice_client(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/blend/client.rb', line 17

def juice_client( options = {} )
  if( options[:auth_token] )
    if( @juice_client && @juice_client.auth_token != options[:auth_token] )
      @juice_client = nil
      @hipchat_client = nil
      @github_client = nil
    end

    @juice_client ||= Blend::Client::JuiceClient.new options
  end
  
  @juice_client ||= Blend::Client::JuiceClient.new
end