ghuls-lib 2.2.3 → 2.3.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 +22 -26
  3. metadata +11 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e12f7fcb4e789d30a5bfcf88e663309bf40054a
4
- data.tar.gz: 4ded65d2ece25e9c646c5270be2dc73e6ff6e327
3
+ metadata.gz: e87ed2ca445019bd3415beaa5ca3e6a5a6dbbe6b
4
+ data.tar.gz: ee2763d6fab3cea86fe4a92e9e968c2b0c0b069f
5
5
  SHA512:
6
- metadata.gz: fc3126198d7798273abdaed271c30ac4c0e067adf991065e86b47f96ee5266a19fbd998feaef60cb69a504c75f425de12a62528413a5013cc5543d1baf259f65
7
- data.tar.gz: 93e79c0bbd2fa45f7e51510363189343ea36a34bc86ff94cb49906f1f6405ae329ab14320e64ad9ea29239313079271742140022a89381f4db59a3a19cf37154
6
+ metadata.gz: ec0bdfd0d0caf498cad80b2b9f1db7906ce3bc4dbef5f0515829e173b0cf42134ec37be9ced0bdb8f87e1aab406029cff830a46f2b1daab39f5b419a6ada4911
7
+ data.tar.gz: d93920a22e6c9b2cf12845206efec7066ad418dd0ac3bb4e803b8437030fec4106847023bca5151c54c1155463b3d194ba1a771c18a0fb84ee56dcb95848c68f
data/lib/ghuls/lib.rb CHANGED
@@ -5,17 +5,19 @@ require 'faraday-http-cache'
5
5
 
6
6
  module GHULS
7
7
  module Lib
8
+ module_function
9
+
8
10
  # Gets the Octokit and colors for the program.
9
11
  # @param opts [Hash] The options to use. The ones that are used by this
10
12
  # method are: :token, :pass, and :user.
11
13
  # @return [Hash] A hash containing objects formatted as
12
14
  # { git: Octokit::Client, colors: JSON }
13
- def self.configure_stuff(opts = {})
15
+ def configure_stuff(opts = {})
14
16
  token = opts[:token]
15
17
  pass = opts[:pass]
16
18
  user = opts[:user]
17
- gh = Octokit::Client.new(login: user, password: pass) if token.nil?
18
- gh = Octokit::Client.new(access_token: token) unless token.nil?
19
+ gh_options = token.nil? ? { login: user, password: pass } : { access_token: token }
20
+ gh = Octokit::Client.new(gh_options)
19
21
  stack = Faraday::RackBuilder.new do |builder|
20
22
  builder.use Faraday::HttpCache, shared_cache: false, serializer: Marshal
21
23
  builder.use Octokit::Response::RaiseError
@@ -30,20 +32,12 @@ module GHULS
30
32
  end
31
33
  end
32
34
 
33
- # Gets the next value in an array.
34
- # @param single [Any] The current value.
35
- # @param full [Array] The main array to parse.
36
- # @return [Any] The next value in the array.
37
- def self.get_next(single, full)
38
- full[full.index(single) + 1]
39
- end
40
-
41
35
  # Gets the user and checks if it exists in the process.
42
36
  # @param user [Any] The user ID or name.
43
37
  # @param github [Octokit::Client] The instance of Octokit::Client.
44
38
  # @return [Hash] Their username and avatar URL.
45
39
  # @return [Boolean] False if it does not exist.
46
- def self.get_user_and_check(user, github)
40
+ def get_user_and_check(user, github)
47
41
  user_full = github.user(user)
48
42
  {
49
43
  username: user_full[:login],
@@ -59,7 +53,7 @@ module GHULS
59
53
  # @param github [Octokit::Client] See #get_user_and_check
60
54
  # @return [Array] All the repository full names that the user has
61
55
  # contributed to.
62
- def self.get_org_repos(username, github)
56
+ def get_org_repos(username, github)
63
57
  orgs = github.organizations(username)
64
58
  repos = []
65
59
  orgs.each do |o|
@@ -87,7 +81,7 @@ module GHULS
87
81
  # @param username [String] See #get_user_and_check
88
82
  # @param github [Octokit::Client] See #get_user_and_check
89
83
  # @return [Hash] All the repositories under the user's account.
90
- def self.get_user_repos(username, github)
84
+ def get_user_repos(username, github)
91
85
  get_organized_repos(github.repositories(username))
92
86
  end
93
87
 
@@ -95,7 +89,7 @@ module GHULS
95
89
  # @param repository [String] The full repository name.
96
90
  # @param github [Octkit::Client] See #get_user_and_check
97
91
  # @return [Hash] The forks, stars, and watcher count.
98
- def self.get_forks_stars_watchers(repository, github)
92
+ def get_forks_stars_watchers(repository, github)
99
93
  {
100
94
  forks: github.forks(repository).length,
101
95
  stars: github.stargazers(repository).length,
@@ -107,7 +101,7 @@ module GHULS
107
101
  # @param username [String] See #get_user_and_check
108
102
  # @param github [Octokit::Client] See #get_user_and_check
109
103
  # @return [Hash] The number of following and followed users.
110
- def self.get_followers_following(username, github)
104
+ def get_followers_following(username, github)
111
105
  {
112
106
  following: github.following(username).length,
113
107
  followers: github.followers(username).length
@@ -119,7 +113,7 @@ module GHULS
119
113
  # @param repository [String] See #get_forks_stars_watchers
120
114
  # @param github [Octokit::Client] See #get_user_and_check
121
115
  # @return [Hash] The number of issues and pulls.
122
- def self.get_issues_pulls(repository, github)
116
+ def get_issues_pulls(repository, github)
123
117
  issues = github.list_issues(repository, state: 'all')
124
118
  pulls = github.pull_requests(repository, state: 'all')
125
119
  issues_open = 0
@@ -157,7 +151,7 @@ module GHULS
157
151
  # @param github [Octokit::Client] See #get_user_and_check
158
152
  # @return [Hash] The languages and their bytes, as formatted as
159
153
  # { :Ruby => 129890, :CoffeeScript => 5970 }
160
- def self.get_user_langs(username, github)
154
+ def get_user_langs(username, github)
161
155
  repos = get_user_repos(username, github)
162
156
  langs = {}
163
157
  repos[:public].each do |r|
@@ -178,7 +172,7 @@ module GHULS
178
172
  # @param username [String] See #get_user_and_check
179
173
  # @param github [Octokit::Client] See #get_user_and_check
180
174
  # @return [Hash] See #get_user_langs
181
- def self.get_org_langs(username, github)
175
+ def get_org_langs(username, github)
182
176
  org_repos = get_org_repos(username, github)
183
177
  langs = {}
184
178
  org_repos[:public].each do |r|
@@ -199,7 +193,7 @@ module GHULS
199
193
  # @param part [Fixnum] The partial value.
200
194
  # @param whole [Fixnum] The whole value.
201
195
  # @return [Fixnum] The percentage that part is of whole.
202
- def self.calculate_percent(part, whole)
196
+ def calculate_percent(part, whole)
203
197
  (part / whole) * 100
204
198
  end
205
199
 
@@ -208,7 +202,7 @@ module GHULS
208
202
  # @param colors [Hash] The hash of colors and languages.
209
203
  # @return [String] The 6 digit hexidecimal color.
210
204
  # @return [Nil] If there is no defined color for the language.
211
- def self.get_color_for_language(lang, colors)
205
+ def get_color_for_language(lang, colors)
212
206
  color_lang = colors[lang]
213
207
  color = color_lang['color']
214
208
  if color_lang.nil? || color.nil?
@@ -222,7 +216,7 @@ module GHULS
222
216
  # @param langs [Hash] The language hash obtained by the get_langs methods.
223
217
  # @return [Hash] The language percentages formatted as
224
218
  # { Ruby: 50%, CoffeeScript: 50% }
225
- def self.get_language_percentages(langs)
219
+ def get_language_percentages(langs)
226
220
  total = 0
227
221
  langs.each { |_, b| total += b }
228
222
  lang_percents = {}
@@ -234,6 +228,7 @@ module GHULS
234
228
  end
235
229
 
236
230
  using StringUtility
231
+
237
232
  # Gets a random GitHub user that actually has data to analyze.
238
233
  # Must always get a user that exists and has repositories, so it will
239
234
  # go through a loop infinitely until it gets one. Uses the GitHub Search
@@ -242,15 +237,16 @@ module GHULS
242
237
  # total number of GitHub users.
243
238
  # @param github [Octokit::Client] See #get_user_and_check
244
239
  # @return [Hash] See #get_user_and_check.
245
- def self.get_random_user(github)
246
- source = open('https://github.com/search?utf8=%E2%9C%93&q=repos%3A%3E-1' \
240
+ def get_random_user(github)
241
+ source = open('https://github.com/search?utf8=%E2%9C%93&q=repos%3A%3E0' \
247
242
  '&type=Users&ref=searchresults').read
248
243
  continue = false
249
- while continue == false
244
+ until continue
250
245
  userid = rand(source[/Showing (.*?) available users/, 1].to_i_separated)
251
246
  user = get_user_and_check(userid, github)
252
247
  continue = true if user != false && !get_user_langs(user, github).empty?
253
248
  end
249
+ # noinspection RubyScope
254
250
  user
255
251
  end
256
252
 
@@ -261,7 +257,7 @@ module GHULS
261
257
  # @param repos [Hash] The repository hash given by Octokit
262
258
  # @return [Hash] An organizeed hash divided into public, forked, mirrored,
263
259
  # and private repos.
264
- def self.get_organized_repos(repos)
260
+ def get_organized_repos(repos)
265
261
  forks = []
266
262
  publics = []
267
263
  mirrors = []
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: 2.2.3
4
+ version: 2.3.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-20 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.1
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.1
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: string-utility
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.6.0
33
+ version: 2.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.6.0
40
+ version: 2.6.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: net-http-persistent
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2.9.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2.9.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: faraday-http-cache
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.2.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.2.2
69
69
  description: The library used for and by the GHULS applications.
70
70
  email: elifosterwy@gmail.com
71
71
  executables: []
@@ -92,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.4.5.1
95
+ rubygems_version: 2.5.1
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: The library used for and by the GHULS applications.
99
99
  test_files: []
100
- has_rdoc: