qiita_scouter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa14f72af870cf04cf4c10673cfdb8f414703ce0
4
+ data.tar.gz: 8e7e19cc83f02e9924da81bd9b0523aad50e3931
5
+ SHA512:
6
+ metadata.gz: 0300734c25bcdef6446942b1943ea6f1c2412d53181ec7e4a45f285de7cf19e2d6a032802318beb73188420f0c29d76c6f33ee707bd4c4b200fde0165034ef83
7
+ data.tar.gz: 45bc19769f14d620a092fa5caa724e8f0310da02750eae60cbef29ae903bf5a80aadf3ee9876bd240533a557629c0f2e03bc1bf48a92502960afe8a75783864c
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AsciiComments:
2
+ Enabled: false
3
+
4
+ Semicolon:
5
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "thor", "~> 0.18.1"
6
+
7
+ gem "rspec", "~> 2.14.1"
8
+ gem "simplecov", "~> 0.8.2"
9
+ gem 'rubocop', '~> 0.23.0'
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tbpgr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # QiitaScouter
2
+
3
+ Qiita Scouter
4
+
5
+ ## 概要
6
+
7
+ Qiitaの記事投稿、フォロワー、タグ、ストック数を戦闘力化します
8
+
9
+ ## 動作確認済み環境
10
+ * ruby 2.0.0 環境にて動作確認済み
11
+
12
+ ## サブコマンド
13
+
14
+ |コマンド|ショートカット|内容|
15
+ |:--|:--|:--|
16
+ |analyze|a|スカウターの計測実行|
17
+ |help|h|ヘルプの表示|
18
+ |version|v|バージョンの表示|
19
+
20
+ ## インストール
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'qiita_scouter'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install qiita_scouter
33
+
34
+ ## ヘルプ
35
+
36
+ ~~~bash
37
+ $ qiita_scouter h
38
+ Commands:
39
+ qiita_scouter analyze # Analyze qiita power_levels
40
+ qiita_scouter help [COMMAND] # Describe available commands or one specific...
41
+ qiita_scouter version # version
42
+
43
+ Options:
44
+ -h, [--help] # help message.
45
+ [--version] # version
46
+ ~~~
47
+
48
+ ## 使用例
49
+
50
+ * 計測実行(ユーザー名 tbpgr の場合)
51
+
52
+ ※対象ユーザーの投稿記事数が多いと、その分時間がかかります
53
+
54
+ または
55
+
56
+ ~~~bash
57
+ $ qiitam a tbpgr
58
+ ユーザー名: tbpgr 戦闘力: 101717 攻撃力: 10780 知力: 87010 すばやさ: 3927
59
+ ~~~
60
+
61
+ または
62
+
63
+ ~~~bash
64
+ $ qiitam analyze tbpgr
65
+ ユーザー名: tbpgr 戦闘力: 101717 攻撃力: 10780 知力: 87010 すばやさ: 3927
66
+ ~~~
67
+
68
+ ## History
69
+ * version 0.0.1 : 2014/09/16 : first release
70
+
71
+ ## 注意事項
72
+ * Qiita APIに負担をかけすぎないように、短時間・大量実行は控えましょう
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/tbpgr/qiita_scouter/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
data/bin/qiita_scouter ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'qiita_scouter_core'
5
+ require 'qiita_scouter/version'
6
+ require 'thor'
7
+
8
+ # rubocop:disable LineLength
9
+ module QiitaScouter
10
+ # = QiitaScouter CLI
11
+ class CLI < Thor
12
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
13
+ class_option :version, type: :boolean, desc: 'version'
14
+ default_task :analyze
15
+
16
+ desc 'analyze', 'Analyze qiita power_levels'
17
+ def analyze(user)
18
+ exit(false) if user.nil?
19
+ power_levels = QiitaScouter::Core.new.analyze(user)
20
+ printf("ユーザー名: %s 戦闘力: %s 攻撃力: %s 知力: %s すばやさ: %s\n", user, *power_levels)
21
+ exit(true)
22
+ rescue => e
23
+ warn(e.message)
24
+ exit(false)
25
+ end
26
+
27
+ desc 'version', 'version'
28
+ def version
29
+ p QiitaScouter::VERSION
30
+ end
31
+ end
32
+ end
33
+
34
+ QiitaScouter::CLI.start(ARGV)
35
+ # rubocop:enable LineLength
@@ -0,0 +1,11 @@
1
+ module QiitaScouter
2
+ # QiitaScouter::Article
3
+ class Article
4
+ attr_accessor :tags, :stock_count
5
+
6
+ def initialize(options = {})
7
+ @tags = options['tags'].map { |e|e['name'] }
8
+ @stock_count = options['stock_count']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'models/article'
2
+
3
+ module QiitaScouter
4
+ # QiitaScouter::Articles
5
+ class Articles
6
+ include Enumerable
7
+ attr_accessor :articles
8
+
9
+ def initialize(articles = [])
10
+ @articles = articles
11
+ end
12
+
13
+ def <<(article)
14
+ @articles << article
15
+ end
16
+
17
+ def +(other)
18
+ @articles += other.articles
19
+ self
20
+ end
21
+
22
+ def size
23
+ @articles.size
24
+ end
25
+
26
+ def each
27
+ @articles.each { |article|yield(article) }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ module QiitaScouter
2
+ # QiitaScouter::User
3
+ class User
4
+ attr_accessor :url_name, :followers, :items
5
+
6
+ def initialize(options = {})
7
+ @url_name = options['url_name']
8
+ @followers = options['followers']
9
+ @items = options['items']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'models/article'
5
+ require 'models/articles'
6
+
7
+ module QiitaScouter
8
+ # QiitaScouter::QiitaItemsJsonLoader
9
+ class QiitaItemsJsonLoader
10
+ attr_reader :user, :articles
11
+ QIITA_URL = 'https://qiita.com/api/v1/users/%s/items?page=%s&per_page=%s'
12
+ PER_PAGE = 100
13
+ PAGE_LIMIT = 50
14
+
15
+ def initialize
16
+ @articles = Articles.new
17
+ end
18
+
19
+ def load(user)
20
+ @user = user
21
+ tmp_verbose = $VERBOSE
22
+ $VERBOSE = nil
23
+ OpenSSL::SSL.const_set('VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE)
24
+ $VERBOSE = tmp_verbose
25
+ (1..PAGE_LIMIT).each do |page|
26
+ before_size = @articles.size
27
+ load_page(user, page)
28
+ break if before_size == @articles.size
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def load_page(user, page)
35
+ json = open(format(QIITA_URL, user, page, PER_PAGE)).read
36
+ json_articles = JSON.parser.new(json).parse
37
+ @articles += json_articles.each_with_object(Articles.new) do |item, memo|
38
+ memo << Article.new(item)
39
+ memo
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ # QiitaScouter
2
+ module QiitaScouter
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'models/user'
3
+ require 'models/article'
4
+ require 'models/articles'
5
+
6
+ module QiitaScouter
7
+ # QiitaScouter Core
8
+ class Calculator
9
+ def initialize(user, articles)
10
+ @url_name = user.url_name
11
+ @followers = user.followers
12
+ @items = user.items
13
+ @tags = articles.reduce([]) { |a, e|a += e.tags; a }.uniq.size
14
+ stock_count = articles.map(&:stock_count).reduce(&:+)
15
+ @stock_rate = stock_count / 10
16
+ end
17
+
18
+ # 攻撃力を計算
19
+ # フォロワー数 × 10 × (ストック数/10)
20
+ def calc_strength
21
+ @followers * 10 * @stock_rate
22
+ end
23
+
24
+ # 知力を計算
25
+ # 記事数 × 5 × (ストック数/10)
26
+ def calc_intelligence
27
+ @items * 5 * @stock_rate
28
+ end
29
+
30
+ # すばやさを計算
31
+ # Tag数 × (ストック数/10)
32
+ def calc_quickness
33
+ @tags * @stock_rate
34
+ end
35
+
36
+ # 戦闘力を計算
37
+ # 攻撃力、 知力、 すばやさの合計
38
+ def calc_power_level
39
+ [calc_strength, calc_intelligence, calc_quickness].reduce(&:+)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'models/article'
3
+ require 'models/articles'
4
+ require 'models/user'
5
+ require 'qiita_user_json_loader'
6
+ require 'qiita_items_json_loader'
7
+ require 'qiita_scouter_calculator'
8
+
9
+ module QiitaScouter
10
+ # QiitaScouter Core
11
+ class Core
12
+ # Generate QiitaScouter markdown file.
13
+ def analyze(target_user)
14
+ user = read_user(target_user)
15
+ articles = read_articles(target_user)
16
+ calc_power_levels(user, articles)
17
+ end
18
+
19
+ private
20
+
21
+ def read_user(target_user)
22
+ user_loader = QiitaUserJsonLoader.new
23
+ user_loader.load(target_user)
24
+ user_loader.user
25
+ end
26
+
27
+ def read_articles(target_user)
28
+ articles_loader = QiitaItemsJsonLoader.new
29
+ articles_loader.load(target_user)
30
+ articles_loader.articles
31
+ end
32
+
33
+ def calc_power_levels(user, articles)
34
+ calc = QiitaScouter::Calculator.new(user, articles)
35
+ [
36
+ calc.calc_power_level,
37
+ calc.calc_strength,
38
+ calc.calc_intelligence,
39
+ calc.calc_quickness
40
+ ]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require 'open-uri'
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'models/user'
5
+
6
+ module QiitaScouter
7
+ # QiitaScouter::QiitaUserJsonLoader
8
+ class QiitaUserJsonLoader
9
+ attr_reader :target_user, :user
10
+ QIITA_URL = 'https://qiita.com/api/v1/users/%s'
11
+
12
+ def load(target_user)
13
+ @target_user = target_user
14
+ tmp_verbose = $VERBOSE
15
+ $VERBOSE = nil
16
+ OpenSSL::SSL.const_set('VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE)
17
+ $VERBOSE = tmp_verbose
18
+ load_page
19
+ end
20
+
21
+ private
22
+
23
+ def load_page
24
+ json = open(format(QIITA_URL, @target_user)).read
25
+ user = JSON.parser.new(json).parse
26
+ @user = User.new(user)
27
+ end
28
+ end
29
+ end