Class: Hubba::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/hubba/github.rb

Defined Under Namespace

Classes: Orgs, Repos, Resource

Constant Summary collapse

BASE_URL =
'https://api.github.com'

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, user: nil, password: nil) ⇒ Github

Returns a new instance of Github.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hubba/github.rb', line 33

def initialize( token: nil,
                user:  nil,
                password: nil )
   @token    = nil
   @user     = nil
   @password = nil

   if token                         ## 1a) give preference to passed in token
     @token     = token
   elsif user && password           ## 1b)  or passed in user/password credentials
     @user      = user
     @password  = password
   elsif Hubba.config.token         ## 2a) followed by configured (or env) token
     @token     = Hubba.config.token
   elsif Hubba.config.user && Hubba.config.password   ## 2b)
     @user      = Hubba.config.user
     @password  = Hubba.config.password
   else                             ## 3)
     ## no token or credentials passed in or configured
   end
end

Instance Method Details

#org(name) ⇒ Object



80
81
82
# File 'lib/hubba/github.rb', line 80

def org( name )
  Resource.new( get "/orgs/#{name}" )
end

#org_repos(name) ⇒ Object



84
85
86
# File 'lib/hubba/github.rb', line 84

def org_repos( name )
  Repos.new( get "/orgs/#{name}/repos?per_page=100" )
end

#repo(full_name) ⇒ Object

full_name (handle) e.g. henrythemes/jekyll-starter-theme



90
91
92
# File 'lib/hubba/github.rb', line 90

def repo( full_name )   ## full_name (handle) e.g. henrythemes/jekyll-starter-theme
  Resource.new( get "/repos/#{full_name}" )
end

#repo_commits(full_name) ⇒ Object



105
106
107
# File 'lib/hubba/github.rb', line 105

def repo_commits( full_name )
  Resource.new( get "/repos/#{full_name}/commits" )
end

#repo_languages(full_name) ⇒ Object



94
95
96
# File 'lib/hubba/github.rb', line 94

def repo_languages( full_name )
  Resource.new( get "/repos/#{full_name}/languages" )
end

#repo_topics(full_name) ⇒ Object



98
99
100
101
102
# File 'lib/hubba/github.rb', line 98

def repo_topics( full_name )
  ## note: requires "api preview" accept headers (overwrites default v3+json)
  ##  e.g. application/vnd.github.mercy-preview+json
  Resource.new( get( "/repos/#{full_name}/topics", preview: 'mercy' ) )
end

#repo_traffic_clones(full_name) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/hubba/github.rb', line 110

def repo_traffic_clones( full_name )
 # Get repository clones
 # Get the total number of clones and breakdown per day or week
 #   for the last 14 days.
 # Timestamps are aligned to UTC midnight of the beginning of the day or week.
 # Week begins on Monday.
 Resource.new( get "/repos/#{full_name}/traffic/clones" )
end


129
130
131
132
133
# File 'lib/hubba/github.rb', line 129

def repo_traffic_popular_paths( full_name )
 # Get top referral paths
 # Get the top 10 popular contents over the last 14 days.
 Resource.new( get "/repos/#{full_name}/traffic/popular/paths" )
end


135
136
137
138
139
# File 'lib/hubba/github.rb', line 135

def repo_traffic_popular_referrers( full_name )
 # Get top referral sources
 # Get the top 10 referrers over the last 14 days.
 Resource.new( get "/repos/#{full_name}/traffic/popular/referrers" )
end

#repo_traffic_views(full_name) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/hubba/github.rb', line 119

def repo_traffic_views( full_name )
 # Get page views
 # Get the total number of views and breakdown per day or week
 #  for the last 14 days.
 # Timestamps are aligned to UTC midnight of the beginning of the day or week.
 # Week begins on Monday.
 Resource.new( get "/repos/#{full_name}/traffic/views" )
end

#user(name) ⇒ Object



57
58
59
# File 'lib/hubba/github.rb', line 57

def user( name )
  Resource.new( get "/users/#{name}" )
end

#user_orgs(name) ⇒ Object

note: pagination

requests that return multiple items will be paginated to 30 items by default.
 You can specify further pages with the ?page parameter.

For some resources, you can also set a custom page size up to 100

with the ?per_page=100 parameter


74
75
76
# File 'lib/hubba/github.rb', line 74

def user_orgs( name )
  Orgs.new( get "/users/#{name}/orgs?per_page=100" )
end

#user_repos(name) ⇒ Object



62
63
64
# File 'lib/hubba/github.rb', line 62

def user_repos( name )
  Repos.new( get "/users/#{name}/repos" )   ## add ?per_page=100 - why? why not?
end