Class: AgileNotifier::Github

Inherits:
SCM
  • Object
show all
Extended by:
ResponseHelper
Defined in:
lib/agile_notifier/github.rb

Defined Under Namespace

Classes: Repository

Constant Summary collapse

ENTERPRISE_API =
'/api/v3'
USERAGENT =
'AgileNotifier'
@@headers =
{:headers => {'User-Agent' => USERAGENT}}
@@auth =
nil

Instance Attribute Summary

Attributes inherited from SCM

#args, #repositories, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResponseHelper

get_value_of_key

Methods inherited from SCM

#repository

Constructor Details

#initialize(url, args = {}) ⇒ Github

Returns a new instance of Github.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agile_notifier/github.rb', line 16

def initialize(url, args = {})
  super
  basic_auth = args.fetch(:basic_auth, nil)
  access_token = args.fetch(:Authorization, nil)
  if basic_auth
    @@auth = {:basic_auth => basic_auth}
  elsif access_token
    @@headers[@@headers.keys.first] = @@headers.values.first.merge({'Authorization' => access_token})
  end
  if url.include?(ENTERPRISE_API)
    status_url = url + '/zen'
    begin
      args = [status_url]
      args.push(@@auth && @@auth.has_key?(:basic_auth) ? @@headers.merge(@@auth) : @@headers)
      status = HTTParty.get(*args).code
      availability = ( status == 200 )
    rescue => e
      puts e.message
      availability = false
    end
  else
    @url.gsub!(/github\./, 'api.github.')
    status_url = url.gsub(/:\/\/api\./, '://status.') + '/api/status.json'
    status = self.class.get_value('status', status_url)
    availability = ( status == 'good' )
  end
  raise('Github is not available.') unless availability
end

Class Method Details

.get_value(key, url) ⇒ Object



50
51
52
53
54
# File 'lib/agile_notifier/github.rb', line 50

def get_value(key, url)
  args = @@headers
  args.merge!(@@auth) if @@auth && @@auth.has_key?(:basic_auth)
  get_value_of_key(key, url, args)
end

.new_enterprise_version(url, args = {}) ⇒ Object



46
47
48
# File 'lib/agile_notifier/github.rb', line 46

def new_enterprise_version(url, args = {})
  new(url + ENTERPRISE_API, args)
end

Instance Method Details

#add_repository(args) ⇒ Object



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

def add_repository(args)
  user = args[:user]
  repo = args[:repo]
  repository = Repository.new(user: user, repo: repo, url: @url)
  @repositories.push(repository)
end