qiita_trend 0.4.4 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9f72474f53962e844a41d6bc6080c3abc23b4fd2492d5be9f30a5456f66a14d
4
- data.tar.gz: 7f08bf843350d2de37e44e7966f954f19ea59b12836e15cbe38b659cff10a815
3
+ metadata.gz: 8a73fc251bb36d817331e9cc0e311dedfe4f269c750ceda90e55a28cb5888ffe
4
+ data.tar.gz: 5f2f5f8e6c7778f8712f4e21f103d3d8421fe69f4c32dc66ec5fe6043f0a11e6
5
5
  SHA512:
6
- metadata.gz: 5899976e67178dbe9662e6bf4b604ce19600b786220d5725e925498af94f61de57eada3555c6fb1dc53676240019cd0adcaa921334328b0fdfd405c9d86957a9
7
- data.tar.gz: 9d695e08ff83871d0e95bb03353fd1556acbfeab73176b05a87fb35e29bdb7599ac1f44a508942037991a5ea7f1299692895ab51e1ccf839cf7dd91b6df15afb
6
+ metadata.gz: 9faaa422189653c626a611919b3de48735fae61b2747bf6d4e791c8c17b931940445204b5b0087d5c160c367cf31d869c2bf7be174695b0e702e6feecce7c966
7
+ data.tar.gz: 26cb95bea2a55c5eb49db2394f268ec55db0183225a5bdff25356a487639dea31d95ecad44de4c2ace1e2f968e2a9d3c8e6f17844bb5a438bd9ba2e7e3895fda
data/.circleci/config.yml CHANGED
@@ -1,10 +1,14 @@
1
1
  version: 2.1
2
2
  orbs:
3
+ ruby: circleci/ruby@1.1.2
3
4
  slack: circleci/slack@3.4.2
4
5
  executors:
5
6
  base:
6
7
  docker:
7
- - image: circleci/ruby:2.6.0
8
+ - image: cimg/ruby:2.6.6
9
+ auth:
10
+ username: dodonki1223
11
+ password: $DOCKERHUB_PASSWORD
8
12
  environment:
9
13
  # Bundlerのパス設定が書き換えられ`vendor/bundle`ではなくて`/usr/local/bundle`を参照してしまい`bundle exec`でエラーになる
10
14
  # Bundlerのconfigファイル(pathの設定がされたもの)をworkspaceで永続化し`vendor/bundle`を参照するようにするための設定
@@ -14,36 +18,6 @@ executors:
14
18
  working_directory: ~/dodonki1223/qiita_trend
15
19
 
16
20
  commands:
17
- install-bundler:
18
- steps:
19
- - run:
20
- name: Install bundler(2.1.0)
21
- command: gem install bundler:2.1.0
22
-
23
- # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
24
- restore-gem-cache:
25
- steps:
26
- - restore_cache:
27
- keys:
28
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
29
- # fallback to using the latest cache if no exact match is found
30
- - v1-dependencies-
31
-
32
- install-gem:
33
- steps:
34
- - run:
35
- name: Install gem
36
- command: |
37
- # jobs=4は並列処理をして高速化するための設定(4つのjobで実行するって意味)
38
- bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
39
-
40
- save-gem-cache:
41
- steps:
42
- - save_cache:
43
- paths:
44
- - ./vendor/bundle
45
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
46
-
47
21
  save-workspace:
48
22
  steps:
49
23
  - persist_to_workspace:
@@ -57,35 +31,8 @@ commands:
57
31
  # working_directory からの相対パスか絶対パスを指定します
58
32
  at: .
59
33
 
60
- run-rubocop:
61
- steps:
62
- - run:
63
- name: Run RuboCop
64
- command: |
65
- bundle exec rubocop
66
-
67
- run-tests:
68
- steps:
69
- - run:
70
- name: Run tests
71
- command: |
72
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
73
- bundle exec rspec \
74
- --format progress \
75
- --format RspecJunitFormatter \
76
- --out test_results/rspec/rspec.xml \
77
- --format progress \
78
- $TEST_FILES
79
-
80
34
  collect-reports:
81
35
  steps:
82
- # ref:https://circleci.com/docs/ja/2.0/configuration-reference/#store_test_results
83
- - store_test_results:
84
- path: test_results
85
- - store_artifacts:
86
- # テスト結果をtest-resultsディレクトリに吐き出す
87
- path: test_results
88
- destination: test-results
89
36
  - store_artifacts:
90
37
  # カバレッジの結果をcoverage-resultsディレクトリに吐き出す
91
38
  path: coverage
@@ -104,19 +51,13 @@ commands:
104
51
 
105
52
  deploy-rubygems:
106
53
  steps:
107
- # ref:https://support.circleci.com/hc/ja/articles/115015628247-%E6%8E%A5%E7%B6%9A%E3%82%92%E7%B6%9A%E8%A1%8C%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B-%E3%81%AF%E3%81%84-%E3%81%84%E3%81%84%E3%81%88-
108
- # read/write両方の権限が必要
109
- - add_ssh_keys:
110
- fingerprints:
111
- - "38:d2:72:5e:9f:67:93:9a:ec:95:94:a2:0e:bf:41:9e"
112
-
113
- # ref:https://circleci.com/docs/2.0/gh-bb-integration/#establishing-the-authenticity-of-an-ssh-host
54
+ # https://discuss.circleci.com/t/the-authenticity-of-github-host-cant-be-stablished/33133 と同じ現象で job が進まなくなるので以下の記事を参考に実装
55
+ # ref:https://circleci.com/docs/ja/2.0/gh-bb-integration/#ssh-%E3%83%9B%E3%82%B9%E3%83%88%E3%81%AE%E4%BF%A1%E9%A0%BC%E6%80%A7%E3%81%AE%E7%A2%BA%E7%AB%8B
114
56
  - run:
115
57
  name: Avoid hosts unknown for github
116
58
  command: |
117
59
  mkdir -p ~/.ssh
118
60
  echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
119
- bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==
120
61
  ' >> ~/.ssh/known_hosts
121
62
 
122
63
  - run:
@@ -140,39 +81,37 @@ jobs:
140
81
  executor: base
141
82
  steps:
142
83
  - checkout
143
- - install-bundler
144
- - restore-gem-cache
145
- - install-gem
146
- - save-gem-cache
84
+ - ruby/install-deps
147
85
  - save-workspace
148
86
 
149
87
  lint:
150
88
  executor: base
151
89
  steps:
152
90
  - using-workspace
153
- - install-bundler
154
- - run-rubocop
91
+ - ruby/install-deps
92
+ - ruby/rubocop-check
155
93
 
156
94
  test:
157
95
  executor: base
158
96
  steps:
159
97
  - using-workspace
160
- - install-bundler
161
- - run-tests
98
+ - ruby/install-deps
99
+ - ruby/rspec-test:
100
+ out-path: 'test_results/rspec/'
162
101
  - collect-reports
163
102
 
164
103
  document:
165
104
  executor: base
166
105
  steps:
167
106
  - using-workspace
168
- - install-bundler
107
+ - ruby/install-deps
169
108
  - create-document
170
109
 
171
110
  deploy:
172
111
  executor: base
173
112
  steps:
174
113
  - using-workspace
175
- - install-bundler
114
+ - ruby/install-deps
176
115
  - deploy-rubygems
177
116
  - deploy-notification
178
117
 
data/.rubocop.yml CHANGED
@@ -4,6 +4,8 @@ require: rubocop-rspec
4
4
  AllCops:
5
5
  # Rubyのバージョン指定
6
6
  TargetRubyVersion: 2.6.5
7
+ # 新しい cop を許可
8
+ NewCops: enable
7
9
 
8
10
  # クラス名Moduleの説明をなしでもOKとする
9
11
  Style/Documentation:
data/Gemfile.lock CHANGED
@@ -1,52 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_trend (0.4.4)
4
+ qiita_trend (0.4.9)
5
5
  mechanize (~> 2.7)
6
- nokogiri (~> 1.10)
6
+ nokogiri (~> 1.11)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  addressable (2.7.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.0)
13
+ ast (2.4.2)
14
14
  byebug (11.1.3)
15
- coderay (1.1.2)
16
- connection_pool (2.2.2)
17
- crack (0.4.3)
18
- safe_yaml (~> 1.0.0)
19
- diff-lcs (1.3)
20
- docile (1.3.2)
15
+ coderay (1.1.3)
16
+ connection_pool (2.2.3)
17
+ crack (0.4.5)
18
+ rexml
19
+ diff-lcs (1.4.4)
20
+ docile (1.3.5)
21
21
  domain_name (0.5.20190701)
22
22
  unf (>= 0.0.5, < 1.0.0)
23
23
  hashdiff (1.0.1)
24
24
  http-cookie (1.0.3)
25
25
  domain_name (~> 0.5)
26
- jaro_winkler (1.5.4)
27
- mechanize (2.7.6)
28
- domain_name (~> 0.5, >= 0.5.1)
29
- http-cookie (~> 1.0)
30
- mime-types (>= 1.17.2)
31
- net-http-digest_auth (~> 1.1, >= 1.1.1)
32
- net-http-persistent (>= 2.5.2)
33
- nokogiri (~> 1.6)
34
- ntlm-http (~> 0.1, >= 0.1.1)
35
- webrobots (>= 0.0.9, < 0.2)
26
+ mechanize (2.8.0)
27
+ addressable (~> 2.7)
28
+ domain_name (~> 0.5, >= 0.5.20190701)
29
+ http-cookie (~> 1.0, >= 1.0.3)
30
+ mime-types (~> 3.0)
31
+ net-http-digest_auth (~> 1.4, >= 1.4.1)
32
+ net-http-persistent (>= 2.5.2, < 5.0.dev)
33
+ nokogiri (~> 1.11, >= 1.11.2)
34
+ rubyntlm (~> 0.6, >= 0.6.3)
35
+ webrick (~> 1.7)
36
+ webrobots (~> 0.1.2)
36
37
  method_source (1.0.0)
37
38
  mime-types (3.3.1)
38
39
  mime-types-data (~> 3.2015)
39
- mime-types-data (3.2020.0425)
40
- mini_portile2 (2.4.0)
40
+ mime-types-data (3.2021.0225)
41
41
  net-http-digest_auth (1.4.1)
42
- net-http-persistent (4.0.0)
42
+ net-http-persistent (4.0.1)
43
43
  connection_pool (~> 2.2)
44
- nokogiri (1.10.9)
45
- mini_portile2 (~> 2.4.0)
46
- ntlm-http (0.1.1)
47
- parallel (1.19.1)
48
- parser (2.7.1.2)
49
- ast (~> 2.4.0)
44
+ nokogiri (1.11.2)
45
+ racc (~> 1.4)
46
+ parallel (1.20.1)
47
+ parser (3.0.1.0)
48
+ ast (~> 2.4.1)
50
49
  pry (0.13.1)
51
50
  coderay (~> 1.1)
52
51
  method_source (~> 1.0)
@@ -56,52 +55,61 @@ GEM
56
55
  pry-doc (1.1.0)
57
56
  pry (~> 0.11)
58
57
  yard (~> 0.9.11)
59
- public_suffix (4.0.4)
58
+ public_suffix (4.0.6)
59
+ racc (1.5.2)
60
60
  rainbow (3.0.0)
61
- rake (13.0.1)
62
- rexml (3.2.4)
63
- rspec (3.9.0)
64
- rspec-core (~> 3.9.0)
65
- rspec-expectations (~> 3.9.0)
66
- rspec-mocks (~> 3.9.0)
67
- rspec-core (3.9.2)
68
- rspec-support (~> 3.9.3)
69
- rspec-expectations (3.9.1)
61
+ rake (13.0.3)
62
+ regexp_parser (2.1.1)
63
+ rexml (3.2.5)
64
+ rspec (3.10.0)
65
+ rspec-core (~> 3.10.0)
66
+ rspec-expectations (~> 3.10.0)
67
+ rspec-mocks (~> 3.10.0)
68
+ rspec-core (3.10.1)
69
+ rspec-support (~> 3.10.0)
70
+ rspec-expectations (3.10.1)
70
71
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.9.0)
72
- rspec-mocks (3.9.1)
72
+ rspec-support (~> 3.10.0)
73
+ rspec-mocks (3.10.2)
73
74
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.9.0)
75
- rspec-support (3.9.3)
75
+ rspec-support (~> 3.10.0)
76
+ rspec-support (3.10.2)
76
77
  rspec_junit_formatter (0.4.1)
77
78
  rspec-core (>= 2, < 4, != 2.12.0)
78
- rubocop (0.82.0)
79
- jaro_winkler (~> 1.5.1)
79
+ rubocop (0.93.1)
80
80
  parallel (~> 1.10)
81
- parser (>= 2.7.0.1)
81
+ parser (>= 2.7.1.5)
82
82
  rainbow (>= 2.2.2, < 4.0)
83
+ regexp_parser (>= 1.8)
83
84
  rexml
85
+ rubocop-ast (>= 0.6.0)
84
86
  ruby-progressbar (~> 1.7)
85
87
  unicode-display_width (>= 1.4.0, < 2.0)
86
- rubocop-rspec (1.39.0)
87
- rubocop (>= 0.68.1)
88
- ruby-progressbar (1.10.1)
89
- safe_yaml (1.0.5)
90
- simplecov (0.18.5)
88
+ rubocop-ast (1.4.1)
89
+ parser (>= 2.7.1.5)
90
+ rubocop-rspec (1.44.1)
91
+ rubocop (~> 0.87)
92
+ rubocop-ast (>= 0.7.1)
93
+ ruby-progressbar (1.11.0)
94
+ rubyntlm (0.6.3)
95
+ simplecov (0.21.2)
91
96
  docile (~> 1.1)
92
97
  simplecov-html (~> 0.11)
93
- simplecov-html (0.12.2)
98
+ simplecov_json_formatter (~> 0.1)
99
+ simplecov-html (0.12.3)
100
+ simplecov_json_formatter (0.1.2)
94
101
  unf (0.1.4)
95
102
  unf_ext
96
103
  unf_ext (0.0.7.7)
97
104
  unicode-display_width (1.7.0)
98
105
  vcr (5.1.0)
99
- webmock (3.8.3)
106
+ webmock (3.12.2)
100
107
  addressable (>= 2.3.6)
101
108
  crack (>= 0.3.2)
102
109
  hashdiff (>= 0.4.0, < 2.0.0)
110
+ webrick (1.7.0)
103
111
  webrobots (0.1.2)
104
- yard (0.9.24)
112
+ yard (0.9.26)
105
113
 
106
114
  PLATFORMS
107
115
  ruby
@@ -123,4 +131,4 @@ DEPENDENCIES
123
131
  yard (~> 0.9)
124
132
 
125
133
  BUNDLED WITH
126
- 2.1.2
134
+ 2.2.4
data/README.md CHANGED
@@ -8,10 +8,10 @@ Qiitaのトレンドを10秒で取得することができます
8
8
 
9
9
  ## 概要
10
10
 
11
- - [Qiita](https://qiita.com/)のTOPページをスクレイピングしDaily、Weekly、Monthlyのトレンドを取得します
11
+ - [Qiita](https://qiita.com/)のTOPページをスクレイピングしTOPページに表示されているトレンドを取得します
12
12
  - [Qiita](https://qiita.com/)のAPIにトレンドを取得する方法がないため
13
- - トレンドはDaily、Weekly、Monthlyそれぞれを日付と更新時間(5時と17時)の組み合わせごとにキャッシュを行います
14
- - Weekly、Monthlyに関してはQiitaにログインしないと取得できないためユーザー名とパスワード設定する必要があります(Dailyに関しては何も設定しなくても取得できます)
13
+ - トレンドは「通常のもの(通常トレンド)」と「ログインした時に表示されるユーザーのトレンド(ユーザートレンド)」のそれぞれを日付と更新時間(5時と17時)の組み合わせごとにキャッシュを行います
14
+ - ユーザートレンドに関してはQiitaにログインしないと取得できないためユーザー名とパスワード設定する必要があります(通常トレンドに関しては何も設定しなくても取得できます)
15
15
  - 過去のトレンドを取得することができます(**あくまでもキャッシュファイルから復元するためキャッシュファイルの無い過去のトレンドは取得することができません**)
16
16
  - いいね数は性質上取得した時の時間に依存します。どうしても現在時刻のいいね数が欲しい場合はキャシュファイルを手動で削除してもう一度実行してください
17
17
 
@@ -27,7 +27,7 @@ Qiitaのトレンドを10秒で取得することができます
27
27
  $ gem install qiita_trend
28
28
  ```
29
29
 
30
- ### QiitaのDailyのトレンドを10秒で取得する
30
+ ### Qiitaの通常トレンドを10秒で取得する
31
31
 
32
32
  ターミナルで`ruby -r qiita_trend -e "pp QiitaTrend::Trend.new.items"`を実行することでQiitaのトレンドを10秒(**gem install qiita_trendも含めて**)で取得できます
33
33
 
@@ -39,7 +39,7 @@ $ ruby -r qiita_trend -e "pp QiitaTrend::Trend.new.items"
39
39
  "https://qiita-image-store.s3.amazonaws.com/0/15319/profile-images/1473684249",
40
40
  "user_page"=>"https://qiita.com/akameco",
41
41
  "article"=>"https://qiita.com/akameco/items/e12377e55e379d29636e",
42
- "created_at"=>"2019-08-05T01:17:34Z",
42
+ "published_at"=>"2019-08-05T01:17:34Z",
43
43
  "likes_count"=>158,
44
44
  "is_new_arrival"=>false},
45
45
  {"title"=>"Excelで誰でも簡単言語処理 (感情推定, 固有表現抽出, キーワード抽出, 文類似度推定 etc...)",
@@ -47,13 +47,13 @@ $ ruby -r qiita_trend -e "pp QiitaTrend::Trend.new.items"
47
47
  "user_image"=>"https://avatars2.githubusercontent.com/u/19549989?v=4",
48
48
  "user_page"=>"https://qiita.com/Harusugi",
49
49
  "article"=>"https://qiita.com/Harusugi/items/535874c0456dbc4db231",
50
- "created_at"=>"2019-08-04T23:01:22Z",
50
+ "published_at"=>"2019-08-04T23:01:22Z",
51
51
  "likes_count"=>103,
52
52
  "is_new_arrival"=>false},
53
53
  ...
54
54
  ```
55
55
 
56
- ### Dailyのトレンドの簡易表示
56
+ ### 通常トレンドの簡易表示
57
57
 
58
58
  index + タイトル名 + いいね数 + ユーザー名
59
59
 
@@ -68,7 +68,7 @@ $ ruby -r qiita_trend -e "QiitaTrend::Trend.new.items.each_with_index {|t, i| pu
68
68
  [5]畳み込みニューラルネットワークは何を見ているか(69) - okn-yu
69
69
  ```
70
70
 
71
- ### Dailyのトレンドのタイトル一覧
71
+ ### 通常トレンドのタイトル一覧
72
72
 
73
73
  ```shell
74
74
  $ ruby -r qiita_trend -e "QiitaTrend::Trend.new.items.each {|t| puts t['title']}"
@@ -81,7 +81,7 @@ KAGGLEでどこから手を付けていいか分からず学ぶことが多す
81
81
  畳み込みニューラルネットワークは何を見ているか
82
82
  ```
83
83
 
84
- ### Dailyのトレンドのうち`new`がついているものをブラウザで一括で開く
84
+ ### 通常トレンドのうち`new`がついているものをブラウザで一括で開く
85
85
 
86
86
  ```shell
87
87
  $ ruby -r qiita_trend -e "QiitaTrend::Trend.new.new_items.each {|t| system('open ' + t['article'])}"
@@ -97,21 +97,21 @@ gem 'qiita_trend'
97
97
 
98
98
  Gemfileに追加したら`bundle install`してください
99
99
 
100
- ### Dailyのトレンドを取得する
100
+ ### 通常トレンドを取得する
101
101
 
102
102
  ```ruby
103
- daily_trend = QiitaTrend::Trend.new
103
+ normal_trend = QiitaTrend::Trend.new
104
104
 
105
- # Dailyのトレンドを全て取得する
106
- p daily_trend.items
105
+ # 通常トレンドを全て取得する
106
+ p normal_trend.items
107
107
 
108
- # DailyのトレンドでNEWのものだけを取得する
109
- p daily_trend.new_items
108
+ # 通常トレンドでNEWのものだけを取得する
109
+ p normal_trend.new_items
110
110
  ```
111
111
 
112
- ### Weekly、Monthlyのトレンドを取得する
112
+ ### ユーザートレンドを取得する
113
113
 
114
- WeeklyとMonthlyのトレンドを取得する時はQiitaにログインしている必要があるため、ログイン出来るユーザーとパスワードの設定が必要です
114
+ ユーザートレンドを取得する時はQiitaにログインしている必要があるため、ログイン出来るユーザーとパスワードの設定が必要です
115
115
  ログインできないユーザー名とパスワードを指定している時は`LoginFailureError`の例外が発生します
116
116
 
117
117
  ```ruby
@@ -121,34 +121,35 @@ QiitaTrend.configure do |config|
121
121
  config.password = 'パスワード'
122
122
  end
123
123
 
124
- # Weeklyの全てのトレンドとNEWのものだけを取得
125
- weekly_trend = QiitaTrend::Trend.new(QiitaTrend::TrendType::WEEKLY)
126
- p weekly_trend.items
127
- p weekly_trend.new_items
124
+ # ユーザーのレンドを取得
125
+ personal_trend = QiitaTrend::Trend.new(QiitaTrend::TrendType::PERSONAL)
126
+ p personal_trend.items
127
+ ```
128
+
129
+ ログインするユーザーとパスワードは環境変数に設定することもできます
128
130
 
129
- # Monthlyの全てのトレンドとNEWのものだけを取得
130
- monthly_trend = QiitaTrend::Trend.new(QiitaTrend::TrendType::MONTHLY)
131
- p monthly_trend.items
132
- p monthly_trend.new_items
131
+ ```
132
+ export QIITA_TREND_USER_NAME='ユーザー名'
133
+ export QIITA_TREND_PASSWORD='パスワード'
133
134
  ```
134
135
 
135
136
  ### キャッシュファイルからトレンドを取得する
136
137
 
137
138
  キャッシュファイルが存在しない場合は`NotExistsCacheError`の例外が発生します
138
- WeeklyもMonthlyの取得方法もDailyと同様です
139
+ ユーザートレンドの取得方法も通常トレンドと同様です
139
140
 
140
141
  ```ruby
141
- # 2019年8月8日5時更新分のDailyのトレンドを取得する
142
- daily_trend_05 = QiitaTrend::Trend.new(QiitaTrend::TrendType::DAILY, '2019080805')
142
+ # 2019年8月8日5時更新分の通常トレンドを取得する
143
+ normal_trend_05 = QiitaTrend::Trend.new(QiitaTrend::TrendType::NORMAL, '2019080805')
143
144
 
144
- p daily_trend_05.items
145
- p daily_trend_05.new_items
145
+ p normal_trend_05.items
146
+ p normal_trend_05.new_items
146
147
 
147
- # 2019年8月8日17時更新分のDailyのトレンドを取得する
148
- daily_trend_17 = QiitaTrend::Trend.new(QiitaTrend::TrendType::DAILY, '2019080817')
148
+ # 2019年8月8日17時更新分のnormalのトレンドを取得する
149
+ normal_trend_17 = QiitaTrend::Trend.new(QiitaTrend::TrendType::NORMAL, '2019080817')
149
150
 
150
- p daily_trend_17.items
151
- p daily_trend_17.new_items
151
+ p normal_trend_17.items
152
+ p normal_trend_17.new_items
152
153
  ```
153
154
 
154
155
  ### itemsメソッド、new_itemsメソッドについて
@@ -173,7 +174,7 @@ irb(main):001:0> pp QiitaTrend::Trend.new.items[0]
173
174
  "https://qiita-image-store.s3.amazonaws.com/0/15319/profile-images/1473684249",
174
175
  "user_page"=>"https://qiita.com/akameco",
175
176
  "article"=>"https://qiita.com/akameco/items/e12377e55e379d29636e",
176
- "created_at"=>"2019-08-05T01:17:34Z",
177
+ "published_at"=>"2019-08-05T01:17:34Z",
177
178
  "likes_count"=>158,
178
179
  "is_new_arrival"=>false}
179
180
  ```
@@ -213,7 +214,7 @@ irb(main):001:0> pp QiitaTrend::Trend.new.items[0]
213
214
  <td></td>
214
215
  </tr>
215
216
  <tr>
216
- <td>created_at</td>
217
+ <td>published_at</td>
217
218
  <td>記事作成日</td>
218
219
  <td></td>
219
220
  </tr>
@@ -225,7 +226,7 @@ irb(main):001:0> pp QiitaTrend::Trend.new.items[0]
225
226
  <tr>
226
227
  <td>is_new_arrival</td>
227
228
  <td>「NEW」のついている記事か</td>
228
- <td>TrueかFalseが入ります</td>
229
+ <td>TrueかFalseが入ります。ログインした時に表示されるユーザーのトレンドに関してはnilになります</td>
229
230
  </tr>
230
231
  </tbody>
231
232
  </table>
@@ -235,9 +236,8 @@ irb(main):001:0> pp QiitaTrend::Trend.new.items[0]
235
236
  キャッシュファイルはデフォルトだと`ユーザーのHOMEディレクトリ/qiita_cache/`に出力されます
236
237
 
237
238
  ```
238
- /Users/dodonki1223/qiita_cache/2019080205_daily.html
239
- /Users/dodonki1223/qiita_cache/2019080205_weekly
240
- /Users/dodonki1223/qiita_cache/2019080205_monthly.html
239
+ /Users/dodonki1223/qiita_cache/2019080205_normal.html
240
+ /Users/dodonki1223/qiita_cache/2019080205_personal
241
241
  ```
242
242
 
243
243
  プログラムで下記のように追記してください
@@ -251,6 +251,12 @@ QiitaTrend.configure do |config|
251
251
  end
252
252
  ```
253
253
 
254
+ キャッシュファイルの出力先は環境変数に設定することもできます
255
+
256
+ ```
257
+ QIITA_TREND_CACHE_DIR='/Users/dodonki1223/hoge/'
258
+ ```
259
+
254
260
  ## 注意
255
261
 
256
262
  このgemは勉強用で作成したものでソースにはアンチパターンなコメント(処理を説明するようなコメントなど)が書かれています。そこはご容赦ください
@@ -11,7 +11,7 @@ module QiitaTrend
11
11
  attr_reader :full_path
12
12
 
13
13
  # キャッシュファイルが格納されるデフォルトのディレクトリ
14
- DEFAULT_CACHE_DIRECTORY = Dir.home + '/qiita_cache/'
14
+ DEFAULT_CACHE_DIRECTORY = "#{Dir.home}/qiita_cache/"
15
15
 
16
16
  # コンストラクタ
17
17
  # Cacheクラスのインスタンスを返します
@@ -23,9 +23,9 @@ module QiitaTrend
23
23
  # コンストラクタ
24
24
  # Configurationクラスのインスタンスを返します
25
25
  def initialize
26
- @user_name = nil
27
- @password = nil
28
- @cache_directory = nil
26
+ @user_name = ENV['QIITA_TREND_USER_NAME']
27
+ @password = ENV['QIITA_TREND_PASSWORD']
28
+ @cache_directory = ENV['QIITA_TREND_CACHE_DIR']
29
29
  end
30
30
  end
31
31
  end
@@ -12,6 +12,7 @@ module QiitaTrend
12
12
  #
13
13
  # @param [Cache] cache キャッシュクラス
14
14
  def initialize(cache)
15
+ super
15
16
  @cache = cache
16
17
  end
17
18
 
@@ -23,14 +23,14 @@ module QiitaTrend
23
23
  # @param [String] date 「YYYYMMDD05」,「YYYYMMDD17」形式のどちらか
24
24
  # @raise [LoginFailureError] ログインに失敗した時に発生する
25
25
  # @raise [NotExistsCacheError] 存在しないキャッシュファイルを指定した時に発生する
26
- def initialize(trend_type = TrendType::DAILY, date = nil)
26
+ def initialize(trend_type = TrendType::NORMAL, date = nil)
27
27
  @target = Target.new(trend_type, date)
28
28
  save_cache_directory = QiitaTrend.configuration.cache_directory.nil? ? Cache::DEFAULT_CACHE_DIRECTORY : QiitaTrend.configuration.cache_directory
29
29
  @cache = Cache.new(target.cache, save_cache_directory)
30
30
 
31
31
  # 指定されたキャッシュファイルが存在しない場合は処理を終了
32
- unless date.nil?
33
- raise Error::NotExistsCacheError, @cache unless @cache.cached?
32
+ if !date.nil? && !@cache.cached?
33
+ raise Error::NotExistsCacheError, @cache
34
34
  end
35
35
 
36
36
  # キャッシュが存在する場合はキャッシュから取得
@@ -16,10 +16,10 @@ module QiitaTrend
16
16
  #
17
17
  # @param [TrendType] trend_type トレンドタイプ
18
18
  # @param [String] date 「YYYYMMDD05」,「YYYYMMDD17」形式のどちらか
19
- def initialize(trend_type = TrendType::DAILY, date = nil)
19
+ def initialize(trend_type = TrendType::NORMAL, date = nil)
20
20
  @type = trend_type
21
- @url = trend_url(trend_type)
22
- @need_login = trend_type != TrendType::DAILY
21
+ @url = trend_url
22
+ @need_login = need_login?(trend_type)
23
23
  @cache = cache_name(trend_type, date)
24
24
  end
25
25
 
@@ -27,14 +27,17 @@ module QiitaTrend
27
27
 
28
28
  # トレンドのURLを取得する
29
29
  #
30
- # @param [TrendType] type トレンドタイプ
31
30
  # @return [String] トレンドを取得するQiitaのページURL
32
- def trend_url(type)
33
- case type
34
- when TrendType::DAILY then 'https://qiita.com/'
35
- when TrendType::WEEKLY then 'https://qiita.com/?scope=weekly'
36
- when TrendType::MONTHLY then 'https://qiita.com/?scope=monthly'
37
- end
31
+ def trend_url
32
+ Page::QIITA_URI
33
+ end
34
+
35
+ # Qiitaにログインが必要か
36
+ #
37
+ # @param [TrendType] trend_type トレンドタイプ
38
+ # @return [Boolean] True:Qiitaへログインが必要、False:Qiitaへログイン不要
39
+ def need_login?(trend_type)
40
+ trend_type != TrendType::NORMAL
38
41
  end
39
42
 
40
43
  # キャッシュ名を取得する
@@ -10,6 +10,7 @@ module QiitaTrend
10
10
  class Trend
11
11
  # @return [Array] トレンドデータ
12
12
  attr_reader :data
13
+ attr_reader :trend_type
13
14
 
14
15
  # コンストラクタ
15
16
  #
@@ -17,11 +18,13 @@ module QiitaTrend
17
18
  # @param [String] date 「YYYYMMDD05」,「YYYYMMDD17」形式のどちらか
18
19
  # @raise [LoginFailureError] ログインに失敗した時に発生する
19
20
  # @raise [NotExistsCacheError] 存在しないキャッシュファイルを指定した時に発生する
20
- def initialize(trend_type = TrendType::DAILY, date = nil)
21
+ def initialize(trend_type = TrendType::NORMAL, date = nil)
22
+ @trend_type = trend_type
21
23
  page = Page.new(trend_type, date)
22
24
  parsed_html = Nokogiri::HTML.parse(page.html)
23
- trends_data = JSON.parse(parsed_html.xpath('//script[@data-component-name="HomeArticleTrendFeed"]')[0].text)
24
- @data = trends_data['trend']['edges']
25
+ xpath_str = "//script[@data-component-name=\"#{data_component_name(trend_type)}\"]"
26
+ trends_data = JSON.parse(parsed_html.xpath(xpath_str)[0].text)
27
+ @data = get_data(trends_data, trend_type)
25
28
  end
26
29
 
27
30
  # Qiitaの対象のトレンドをすべて取得
@@ -35,7 +38,7 @@ module QiitaTrend
35
38
  result['user_image'] = user_image(trend['node']['author']['profileImageUrl'])
36
39
  result['user_page'] = "#{Page::QIITA_URI}#{trend['node']['author']['urlName']}"
37
40
  result['article'] = "#{Page::QIITA_URI}#{trend['node']['author']['urlName']}/items/#{trend['node']['uuid']}"
38
- result['created_at'] = trend['node']['createdAt']
41
+ result['published_at'] = trend['node']['publishedAt']
39
42
  result['likes_count'] = trend['node']['likesCount']
40
43
  result['is_new_arrival'] = trend['isNewArrival']
41
44
  value << result
@@ -43,9 +46,12 @@ module QiitaTrend
43
46
  end
44
47
 
45
48
  # Qiitaの対象のトレンドからNEWのものだけ取得
49
+ # トレンドタイプがPERSONALの場合はNEWの概念が無いのでnilである
46
50
  #
47
51
  # @return [Array] Qiitaの対象のトレンドからNEWのものだけ
48
52
  def new_items
53
+ return nil if @trend_type == TrendType::PERSONAL
54
+
49
55
  items.select do |trend|
50
56
  trend['is_new_arrival'] == true
51
57
  end
@@ -53,6 +59,23 @@ module QiitaTrend
53
59
 
54
60
  private
55
61
 
62
+ # QiitaのトレンドのFeed名を取得する
63
+ #
64
+ # @param [TrendType] trend_type トレンドタイプ
65
+ # @return [String] トレンドタイプによるFeed名
66
+ def data_component_name(trend_type)
67
+ trend_type == TrendType::PERSONAL ? 'HomePersonalizedFeed' : 'HomeArticleTrendFeed'
68
+ end
69
+
70
+ # Qiitaのトレンドのデータを取得する
71
+ #
72
+ # @param [Hash] trends_data トレンドデータ
73
+ # @param [TrendType] trend_type トレンドタイプ
74
+ # @return [Array] トレンドタイプによるトレンドデータ
75
+ def get_data(trends_data, trend_type)
76
+ trend_type == TrendType::PERSONAL ? trends_data['personalizedFeed']['edges'] : trends_data['trend']['edges']
77
+ end
78
+
56
79
  # ユーザーの画像のURLを取得する
57
80
  # URLデコードしクエリーパラメータを排除する
58
81
  #
@@ -3,11 +3,9 @@
3
3
  module QiitaTrend
4
4
  # トレンドタイプの機能を提供する
5
5
  class TrendType
6
- # トレンドタイプ:Daily
7
- DAILY = 'daily'
8
- # トレンドタイプ:Weekly
9
- WEEKLY = 'weekly'
10
- # トレンドタイプ:Monthly
11
- MONTHLY = 'monthly'
6
+ # トレンドタイプ:Normal
7
+ NORMAL = 'normal'
8
+ # トレンドタイプ:Personal
9
+ PERSONAL = 'personal'
12
10
  end
13
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QiitaTrend
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.9'
5
5
  end
data/qiita_trend.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = QiitaTrend::VERSION
10
10
  spec.authors = ['dodonki1223']
11
11
  spec.email = ['make.an.effort.wish.come.true@gmail.com']
12
+ spec.required_ruby_version = '>= 2.6.5'
12
13
 
13
14
  spec.summary = 'Easy to get trend for Qiita in 10 seconds'
14
15
  spec.description = 'Easy to get trend for Qiita in 10 seconds'
@@ -39,7 +40,7 @@ Gem::Specification.new do |spec|
39
40
 
40
41
  # qiita_trendに必要な依存gem設定(ここは最小限にすること)
41
42
  spec.add_dependency 'mechanize', '~> 2.7'
42
- spec.add_dependency 'nokogiri', '~> 1.10'
43
+ spec.add_dependency 'nokogiri', '~> 1.11'
43
44
  # 開発中のみ必要なgem設定
44
45
  spec.add_development_dependency 'bundler', '~> 2.0'
45
46
  spec.add_development_dependency 'pry', '~> 0.13'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_trend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - dodonki1223
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.11'
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: '1.10'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -264,14 +264,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
264
  requirements:
265
265
  - - ">="
266
266
  - !ruby/object:Gem::Version
267
- version: '0'
267
+ version: 2.6.5
268
268
  required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  requirements:
270
270
  - - ">="
271
271
  - !ruby/object:Gem::Version
272
272
  version: '0'
273
273
  requirements: []
274
- rubygems_version: 3.0.1
274
+ rubygems_version: 3.1.3
275
275
  signing_key:
276
276
  specification_version: 4
277
277
  summary: Easy to get trend for Qiita in 10 seconds