ghuls-lib 2.1.2 → 2.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 +27 -28
  3. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 854c231a6588d4e5c56be67a62dd3cce4e033daf
4
- data.tar.gz: 47dc5e611a68cc4a64ca332194929986ffafecc9
3
+ metadata.gz: b4e2040544766256c602ec373c8009ab23cc84d2
4
+ data.tar.gz: 889301d654b0f5bc7d24f237c7c887a821e578f5
5
5
  SHA512:
6
- metadata.gz: 387fd02a78926e93f1e4a1c2796d727d3f8ef971b044a1d3e6de6ae5cb88e25e05750ce6f989fa9c3035fffd882fd5ad79d8a360f07c3a2ddf92b93eccd5de8a
7
- data.tar.gz: ce8a91b7760ffc57fef2a40e81a79bb9c7a2036a40247fad3670d47a0a66d1db266348deda00da1390126e0cc98f21b51c5bf48b2a2dc0e96bd5bd2db7031fc0
6
+ metadata.gz: 83007bb0b206a49e418a21b714813e4778c8bff5f3b265a1c4a2624c83b6ea7f880d5e3f38a17d8bf2c6172303c1d009dcb4429d7ec69e4b1a6dddf83aa0f1fa
7
+ data.tar.gz: dc6ea9e9b2d07a7f5beccd73868ca99c85324257da745d5b27445d961833559e52ee91d030f67f7f5c305265cc08f816886b94a85e674c11fe8d20210544aa6e
data/lib/ghuls/lib.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'octokit'
2
2
  require 'string-utility'
3
3
  require 'open-uri'
4
+ require 'faraday-http-cache'
4
5
 
5
6
  module GHULS
6
7
  module Lib
@@ -15,13 +16,18 @@ module GHULS
15
16
  user = opts[:user]
16
17
  gh = Octokit::Client.new(login: user, password: pass) if token.nil?
17
18
  gh = Octokit::Client.new(access_token: token) unless token.nil?
19
+ stack = Faraday::RackBuilder.new do |builder|
20
+ builder.use Faraday::HttpCache, shared_cache: false
21
+ builder.use Octokit::Response::RaiseError
22
+ builder.adapter :net_http_persistent
23
+ end
24
+ gh.middleware = stack
18
25
  begin
19
26
  encode = gh.contents('ozh/github-colors', path: 'colors.json')[:content]
20
- colors = JSON.parse(Base64.decode64(encode))
27
+ { git: gh, colors: JSON.parse(Base64.decode64(encode)) }
21
28
  rescue Octokit::Unauthorized
22
29
  return false
23
30
  end
24
- { git: gh, colors: colors }
25
31
  end
26
32
 
27
33
  # Gets the next value in an array.
@@ -29,7 +35,7 @@ module GHULS
29
35
  # @param full [Array] The main array to parse.
30
36
  # @return [Any] The next value in the array.
31
37
  def self.get_next(single, full)
32
- full.at(full.index(single) + 1)
38
+ full[full.index(single) + 1]
33
39
  end
34
40
 
35
41
  # Gets the user and checks if it exists in the process.
@@ -38,15 +44,13 @@ module GHULS
38
44
  # @return [Hash] Their username and avatar URL.
39
45
  # @return [Boolean] False if it does not exist.
40
46
  def self.get_user_and_check(user, github)
41
- begin
42
- user_full = github.user(user)
43
- rescue Octokit::NotFound
44
- return false
45
- end
47
+ user_full = github.user(user)
46
48
  {
47
49
  username: user_full[:login],
48
50
  avatar: user_full[:avatar_url]
49
51
  }
52
+ rescue Octokit::NotFound
53
+ return false
50
54
  end
51
55
 
52
56
  # Returns the repos in the user's organizations that they have actually
@@ -92,14 +96,10 @@ module GHULS
92
96
  # @param github [Octkit::Client] See #get_user_and_check
93
97
  # @return [Hash] The forks, stars, and watcher count.
94
98
  def self.get_forks_stars_watchers(repository, github)
95
- stargazers = github.stargazers(repository).length
96
- forks = github.forks(repository).length
97
- watchers = github.subscribers(repository).length
98
-
99
99
  {
100
- forks: forks,
101
- stars: stargazers,
102
- watchers: watchers
100
+ forks: github.forks(repository).length,
101
+ stars: github.stargazers(repository).length,
102
+ watchers: github.subscribers(repository).length
103
103
  }
104
104
  end
105
105
 
@@ -108,12 +108,9 @@ module GHULS
108
108
  # @param github [Octokit::Client] See #get_user_and_check
109
109
  # @return [Hash] The number of following and followed users.
110
110
  def self.get_followers_following(username, github)
111
- following = github.following(username)
112
- followers = github.followers(username)
113
-
114
111
  {
115
- following: following.length,
116
- followers: followers.length
112
+ following: github.following(username).length,
113
+ followers: github.followers(username).length
117
114
  }
118
115
  end
119
116
 
@@ -191,8 +188,7 @@ module GHULS
191
188
  if langs[l].nil?
192
189
  langs[l] = b
193
190
  else
194
- existing = langs[l]
195
- langs[l] = existing + b
191
+ langs[l] += b
196
192
  end
197
193
  end
198
194
  end
@@ -213,10 +209,12 @@ module GHULS
213
209
  # @return [String] The 6 digit hexidecimal color.
214
210
  # @return [Nil] If there is no defined color for the language.
215
211
  def self.get_color_for_language(lang, colors)
216
- if colors[lang].nil? || colors[lang]['color'].nil?
212
+ color_lang = colors[lang]
213
+ color = color_lang['color']
214
+ if colors_lang.nil? || color.nil?
217
215
  return StringUtility.random_color_six
218
216
  else
219
- return colors[lang]['color']
217
+ return color
220
218
  end
221
219
  end
222
220
 
@@ -269,15 +267,16 @@ module GHULS
269
267
  mirrors = []
270
268
  privates = []
271
269
  repos.each do |r|
272
- forks.push(r[:full_name]) if r[:fork]
270
+ repo_name = r[:full_name]
271
+ forks.push(repo_name) if r[:fork]
273
272
 
274
273
  if r[:private]
275
- privates.push(r[:full_name])
274
+ privates.push(repo_name)
276
275
  else
277
- publics.push(r[:full_name])
276
+ publics.push(repo_name)
278
277
  end
279
278
 
280
- mirrors.push(r[:full_name]) unless r[:mirror_url].nil?
279
+ mirrors.push(repo_name) unless r[:mirror_url].nil?
281
280
  end
282
281
 
283
282
  {
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.1.2
4
+ version: 2.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-17 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.5.0
33
+ version: 2.6.0
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.5.0
40
+ version: 2.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-http-persistent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: The library used for and by the GHULS applications.
42
56
  email: elifosterwy@gmail.com
43
57
  executables: []