qiita_trend 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 132ff1d32ba9c8a824e07a7e3d2c6823098242ec82c9088b311d11d966e97edb
4
- data.tar.gz: b84e41afe0e2d10d00b1fa3afc699b47ac3ae4f0aa11e80eec0accbd4d7a0fd8
3
+ metadata.gz: 9241e184861dc9fee0df4aa5778615dab53853598e142a1ae8198974389c2bcb
4
+ data.tar.gz: b9f86e912aeda7087f4e3ecdc6a228f791edc2b3bb4b474eda07e6070ee38b81
5
5
  SHA512:
6
- metadata.gz: e0dab4659f2944b0a9edd128a23f897dfe35101632c192a40296c0c49de224f865345c7e4cef7e0e92e65d56873afec3f1674eb21079c06fea1f586023d67b46
7
- data.tar.gz: 0f36488b2bb23ce076ff9bf9e34141b26f3c83883caec6ed15952fc3964d325cea64ac25fbb4e817931bada3f1f6c40375747a161faf59a54b7b938b00cae51b
6
+ metadata.gz: 699141a6d5cc9459bd5f5e067a1499925be6929d97532194e51bb656067b903b3623d648e404345ac78a2d560be73fc11fb0bd486fc40b209fa230ae47c7f6df
7
+ data.tar.gz: '098b313ca4a1d45fa8ded72b55df76d820674abadb625ae57168e0af5756de32a436e277a5802423e1acfa52c1eb666d854a5411886c87fa529fa405ff9f65cc'
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.6)
4
+ qiita_trend (0.5.0)
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
 
@@ -53,7 +53,7 @@ $ ruby -r qiita_trend -e "pp QiitaTrend::Trend.new.items"
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メソッドについて
@@ -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の対象のトレンドをすべて取得
@@ -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 ? 'HomeIndexPage' : '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']['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.6'
4
+ VERSION = '0.5.0'
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.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dodonki1223
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-12-09 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,7 +264,7 @@ 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
  - - ">="