ghuls-lib 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ghuls/lib.rb +20 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66fe2c59dbfe6e9bf324abceeb1d32eaf7daac5f
4
- data.tar.gz: ae13f00717de31600da2be126b4ea7707386d03a
3
+ metadata.gz: 91d1a894139f17e933e802fd1d27f59e1a0b82a4
4
+ data.tar.gz: c56fc6748fe1d35005202c4491d5dd176ed19381
5
5
  SHA512:
6
- metadata.gz: da4a4f104136d2de84ad1af06a13b062b6b93b8e37688bd966aabc97f03958c3dd8f17a8d49d427bf3700d388dad29db886dd2097b3b6ed73d43fc536abb9c68
7
- data.tar.gz: d08f33c6133e10f197a5b295998a1d49e4311047a5727e60513786a6a8e88c7ad79d26b1f897e917dd5be491cd9d7328834d08fde9d4e4dd36cf21a4ee7f097e
6
+ metadata.gz: bd4a495f647029cc917e9e22728730a573a4e8b2ecc7e20753bca93db80d08678a2cd67336f6be5d6b2efdfc5fd56f12d175a6991d671151ed86a7bebe7a8f8e
7
+ data.tar.gz: 44f297bff0cacaf26e4ff4ddbbfd4bea4a34f525b089d3a93a38e4f5a9251cc5538bf8d7867c2ae0cdcae1d0b110d6245101c6ce04ace05cf261c106bd460234
data/lib/ghuls/lib.rb CHANGED
@@ -32,37 +32,24 @@ module GHULS
32
32
  full.at(full.index(single) + 1)
33
33
  end
34
34
 
35
- # Gets whether or not the user exists.
36
- # @param username [String] The user to check
37
- # @param github [Octokit::Client] The instance of Octokit to use.
38
- # @return [Boolean] True if it does, false if it doesn't.
39
- def self.user_exists?(username, github)
40
- begin
41
- github.user(username)
42
- rescue Octokit::NotFound
43
- return false
44
- end
45
- true
46
- end
47
-
48
35
  # Gets the username and checks if it exists in the process.
49
- # @param userid [Fixnum] The user ID.
50
- # @param github [Octokit::Client] See #user_exists?
51
- # @return [String] The username
36
+ # @param user [Any] The user ID or name.
37
+ # @param github [Octokit::Client] The instance of Octokit::Client.
38
+ # @return [Hash] Data formatted as { username: username, avatar: url }
52
39
  # @return [Boolean] False if it does not exist.
53
- def self.get_user_and_check(userid, github)
40
+ def self.get_user_and_check(user, github)
54
41
  begin
55
- username = github.user(userid)
42
+ user_full = github.user(user)
56
43
  rescue Octokit::NotFound
57
44
  return false
58
45
  end
59
- username[:login]
46
+ { username: user_full[:login], avatar: user_full[:avatar_url] }
60
47
  end
61
48
 
62
49
  # Returns the repos in the user's organizations that they have actually
63
50
  # contributed to.
64
- # @param username [String] See #user_exists?
65
- # @param github [Octokit::Client] See #user_exists?
51
+ # @param username [String] See #get_user_and_check
52
+ # @param github [Octokit::Client] See #get_user_and_check
66
53
  # @return [Array] All the repository full names that the user has
67
54
  # contributed to.
68
55
  def self.get_org_repos(username, github)
@@ -90,8 +77,8 @@ module GHULS
90
77
  end
91
78
 
92
79
  # Gets the langauges and their bytes for the user.
93
- # @param username [String] See #user_exists?
94
- # @param github [Octokit::Client] See #user_exists?
80
+ # @param username [String] See #get_user_and_check
81
+ # @param github [Octokit::Client] See #get_user_and_check
95
82
  # @return [Hash] The languages and their bytes, as formatted as
96
83
  # { :Ruby => 129890, :CoffeeScript => 5970 }
97
84
  def self.get_user_langs(username, github)
@@ -113,8 +100,8 @@ module GHULS
113
100
  end
114
101
 
115
102
  # Gets the languages and their bytes for the user's organizations.
116
- # @param username [String] See #user_exists?
117
- # @param github [Octokit::Client] See #user_exists?
103
+ # @param username [String] See #get_user_and_check
104
+ # @param github [Octokit::Client] See #get_user_and_check
118
105
  # @return [Hash] See #get_user_langs
119
106
  def self.get_org_langs(username, github)
120
107
  org_repos = get_org_repos(username, github)
@@ -170,12 +157,12 @@ module GHULS
170
157
  end
171
158
 
172
159
  # Performs the main analysis of the user's organizations.
173
- # @param username [String] See #user_exists?
174
- # @param github [Octokit::Client] See #user_exists?
160
+ # @param username [String] See #get_user_and_check
161
+ # @param github [Octokit::Client] See #get_user_and_check
175
162
  # @return [Hash] See #get_language_percentages
176
- # @return [Boolean] False if user_exists? returns false.
163
+ # @return [Boolean] False if get_user_and_check returns false.
177
164
  def self.analyze_orgs(username, github)
178
- if user_exists?(username, github)
165
+ if get_user_and_check(username, github) != false
179
166
  langs = get_org_langs(username, github)
180
167
  return false if langs.empty?
181
168
  get_language_percentages(langs)
@@ -185,12 +172,12 @@ module GHULS
185
172
  end
186
173
 
187
174
  # Performs the main analysis of the user.
188
- # @param username [String] See #user_exists?
189
- # @param github [Octokit::Client] See #user_exists?
175
+ # @param username [String] See #get_user_and_check
176
+ # @param github [Octokit::Client] See #get_user_and_check
190
177
  # @return [Hash] See #analyze_orgs
191
178
  # @return [Boolean] See #analyze_orgs
192
179
  def self.analyze_user(username, github)
193
- if user_exists?(username, github)
180
+ if get_user_and_check(username, github) != false
194
181
  langs = get_user_langs(username, github)
195
182
  return false if langs.empty?
196
183
  get_language_percentages(langs)
@@ -206,7 +193,7 @@ module GHULS
206
193
  # to find the maximum number of users, which may not be the best way to do
207
194
  # it. However, none of the documented GitHub APIs show that we can get the
208
195
  # total number of GitHub users.
209
- # @param github [Octokit::Client] See #user_exists?
196
+ # @param github [Octokit::Client] See #get_user_and_check
210
197
  # @return [String] A random username.
211
198
  def self.get_random_user(github)
212
199
  source = open('https://github.com/search?utf8=%E2%9C%93&q=repos%3A%3E-1' \
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghuls-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit