favourite-language 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Andrew White
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Favourite Language
2
+ ==================
3
+
4
+ This gem provides an command line tool for returning a user's favourite
5
+ programming language. You can either return their favourite programming
6
+ language by number of repositories or by repository size.
7
+
8
+ Usage
9
+ -----
10
+
11
+ ``` sh
12
+ $ favourite-language by_repo pixeltrix
13
+ The favourite language of pixeltrix by number of repositories is Ruby
14
+
15
+ $ favourite-language by_size pixeltrix
16
+ The favourite language of pixeltrix by repository size is PHP
17
+ ```
18
+
19
+ Copyright (c) 2013 Andrew White, released under the MIT license
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ require "thor"
3
+ require "octokit"
4
+
5
+ Octokit.auto_paginate = true
6
+
7
+ class FavouriteLanguage < Thor
8
+ package_name "Favourite Language"
9
+
10
+ desc "by_repo USER", "Get the favourite programming language by the number of repositories"
11
+ def by_repo(user)
12
+ message = "The favourite language of %s by number of repositories is %s"
13
+ language = favorite_language(:by_num_repos, user)
14
+ puts message % [user, language] if language
15
+ end
16
+
17
+ desc "by_size USER", "Get the favourite programming labguage by repository size"
18
+ def by_size(user)
19
+ message = "The favourite language of %s by repository size is %s"
20
+ language = favorite_language(:by_size, user)
21
+ puts message % [user, language] if language
22
+ end
23
+
24
+ private
25
+
26
+ def favorite_language(method, user)
27
+ begin
28
+ send(:"languages_#{method}", user).max_by{ |l, n| n }.first
29
+ rescue Octokit::NotFound
30
+ puts "Sorry, #{user} doesn't exist"
31
+ rescue Octokit::TooManyRequests
32
+ puts "Sorry, your API limit has been reached"
33
+ rescue Octokit::ClientError => e
34
+ puts "Sorry, unexpected client error: {e.message}"
35
+ rescue Octokit::ServerError => e
36
+ puts "Sorry, unexpected server error: {e.message}"
37
+ end
38
+ end
39
+
40
+ def languages_by_num_repos(user)
41
+ repositories(user).inject({}) do |languages, repository|
42
+ language = repository.language
43
+ languages[language] = languages.fetch(language, 0) + 1
44
+ languages
45
+ end
46
+ end
47
+
48
+ def languages_by_size(user)
49
+ repositories(user).inject({}) do |languages, repository|
50
+ language = repository.language
51
+ languages[language] = languages.fetch(language, 0) + repository.size
52
+ languages
53
+ end
54
+ end
55
+
56
+ def repositories(user)
57
+ Octokit.repositories(user)
58
+ end
59
+ end
60
+
61
+ FavouriteLanguage.start
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'favourite-language'
3
+ s.version = '0.1.0'
4
+ s.author = 'Andrew White'
5
+ s.email = 'andyw@pixeltrix.co.uk'
6
+ s.summary = <<-EOS
7
+ Provides a command line tool for getting a user's favourite
8
+ programming language from their GitHub public repositories.
9
+ EOS
10
+
11
+ s.add_dependency 'thor', '~> 0.18'
12
+ s.add_dependency 'octokit', '~> 2.0'
13
+
14
+ s.files = %w[bin/favourite-language favourite-language.gemspec LICENSE.md README.md]
15
+ s.executables = %w[favourite-language]
16
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: favourite-language
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew White
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.18'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.18'
30
+ - !ruby/object:Gem::Dependency
31
+ name: octokit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ description:
47
+ email: andyw@pixeltrix.co.uk
48
+ executables:
49
+ - favourite-language
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - bin/favourite-language
54
+ - favourite-language.gemspec
55
+ - LICENSE.md
56
+ - README.md
57
+ homepage:
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.25
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Provides a command line tool for getting a user's favourite programming language
81
+ from their GitHub public repositories.
82
+ test_files: []