qiita_trend 0.4.7 → 0.4.8

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: 0f0ee86709a430ad4746e77fda12993c3d06166dc4c9a41402c9ff8fa36929a5
4
- data.tar.gz: d74ac15ab1d63456b775b3792cfab42747f78e88c00bcd204c97386c078e56d6
3
+ metadata.gz: f340c9bd896889d3328ca2e2df7127fcbd9ec03e0452baef8fc1960ed508b2aa
4
+ data.tar.gz: 9b446ac321c031d503b73d694e68295acf485ba23a6a8d4dd7c27dcab3446434
5
5
  SHA512:
6
- metadata.gz: 69a33d9e13ea5b645db1c111f8bcfaa592332e45054389c0fa4466eb284ffa6511437761412a49cb15e1632eacb2c509170237a8460374a0aa7a07f15017efc8
7
- data.tar.gz: 9614b80041a22274d6b317a9350acd7857fceef306f0ce726041e54c4bdd3bf96c90a9a8c154f999d6a7e4c72e2bb167ac3357c660ca4c6274a8ec08074cbf0c
6
+ metadata.gz: 065a262b04b7e9f3b19d72a5cf9471d8e7cbed1465465193098190f0490211d199e9f771a970f813822eefe7b13adaef6d849d8b07d2bf89d86ff9735a77323e
7
+ data.tar.gz: f2bbf97d05c5bea4c6137398312742f542b33278ba658cfe120a59d300152eec466a17b5987117dd9c8c8b7ba0742d769d60f38af72012e2f787344e0df4d79f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_trend (0.4.7)
4
+ qiita_trend (0.4.8)
5
5
  mechanize (~> 2.7)
6
6
  nokogiri (~> 1.11)
7
7
 
@@ -38,12 +38,10 @@ GEM
38
38
  mime-types (3.3.1)
39
39
  mime-types-data (~> 3.2015)
40
40
  mime-types-data (3.2021.0225)
41
- mini_portile2 (2.5.0)
42
41
  net-http-digest_auth (1.4.1)
43
42
  net-http-persistent (4.0.1)
44
43
  connection_pool (~> 2.2)
45
44
  nokogiri (1.11.2)
46
- mini_portile2 (~> 2.5.0)
47
45
  racc (~> 1.4)
48
46
  parallel (1.20.1)
49
47
  parser (3.0.1.0)
@@ -23,7 +23,7 @@ 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)
@@ -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
  # キャッシュ名を取得する
@@ -17,10 +17,11 @@ module QiitaTrend
17
17
  # @param [String] date 「YYYYMMDD05」,「YYYYMMDD17」形式のどちらか
18
18
  # @raise [LoginFailureError] ログインに失敗した時に発生する
19
19
  # @raise [NotExistsCacheError] 存在しないキャッシュファイルを指定した時に発生する
20
- def initialize(trend_type = TrendType::DAILY, date = nil)
20
+ def initialize(trend_type = TrendType::NORMAL, date = nil)
21
21
  page = Page.new(trend_type, date)
22
22
  parsed_html = Nokogiri::HTML.parse(page.html)
23
- trends_data = JSON.parse(parsed_html.xpath('//script[@data-component-name="NewHomeArticleTrendFeed"]')[0].text)
23
+ xpath_str = "//script[@data-component-name=\"#{data_component_name(trend_type)}\"]"
24
+ trends_data = JSON.parse(parsed_html.xpath(xpath_str)[0].text)
24
25
  @data = trends_data['trend']['edges']
25
26
  end
26
27
 
@@ -53,6 +54,13 @@ module QiitaTrend
53
54
 
54
55
  private
55
56
 
57
+ # QiitaのトレンドのFeed名を取得する
58
+ #
59
+ # @return [String] トレンドタイプによるFeed名
60
+ def data_component_name(trend_type)
61
+ trend_type == TrendType::PERSONAL ? 'HomePersonalizedFeed' : 'NewHomeArticleTrendFeed'
62
+ end
63
+
56
64
  # ユーザーの画像のURLを取得する
57
65
  # URLデコードしクエリーパラメータを排除する
58
66
  #
@@ -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.7'
4
+ VERSION = '0.4.8'
5
5
  end
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.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - dodonki1223
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize