qiita_trend 0.2.7 → 0.2.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: 9430a869aefef938378e0c222578100dbd2b0d741e9dc72456785a9af315233d
4
- data.tar.gz: 3f338bddc0525275dc6238a16ff33cf872f732afe11a1b945ab7f0618149317a
3
+ metadata.gz: 3cf7e7382a8f459992a654a95bdc666c79fe7bff6379e6e3961d7d2e626c9896
4
+ data.tar.gz: 3ffc14309f8af1ff9a18f3036d354ff38a80ee6c94c2d74502a82ee71b521c5c
5
5
  SHA512:
6
- metadata.gz: 642c8ebfc58b9816b694d18ce5d32cd4c37c390c2fde42b559eb20cd732c262f7cb9b7c3caee82e3924a87bfe1d5ebef08383befa88bd61ca533f70137a28205
7
- data.tar.gz: 35415ff58aa1923a2a2cfbde6607b0e2a9dafa21a1ccfcf70977f709d109574b677ff1ca5632dbc543fa6114b77859b611efc4fe7ad2bf8846681830af22e911
6
+ metadata.gz: 2419645c6a853799de3391d7e7c56a912eaa836869a99334d82dd3a9667d0732a4e9a191d71459d9c4b88d6d3cdda6c72ab39974a0c181f7fe8d4b51141fb3e0
7
+ data.tar.gz: 5d221ad820a123c3e18caec9c2a1a40fcc35a10837a61dbce3dc8d9efbcd8133b23829847e3aa11bf3e7f93a60e1b3c57c6258d3028dafd19f02f10722856a6d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_trend (0.2.7)
4
+ qiita_trend (0.2.8)
5
5
  mechanize
6
6
  nokogiri (~> 1.9)
7
7
 
@@ -33,12 +33,5 @@ module QiitaTrend
33
33
  def cached?
34
34
  File.exist?(@full_path)
35
35
  end
36
-
37
- # キャッシュファイルをクリアする
38
- def clear_cache
39
- File.delete(@full_path) if cached?
40
- rescue StandardError => e
41
- raise e.class, 'キャッシュファイルの削除に失敗しました'
42
- end
43
36
  end
44
37
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QiitaTrend
4
+ module Error
5
+ class LoginFailureError < ::QiitaTrend::Error::SyntaxError
6
+ def message
7
+ "Login failed, Please confilm user_name and password(user:#{user_name},password:#{password})"
8
+ end
9
+
10
+ def user_name
11
+ QiitaTrend.configuration.user_name
12
+ end
13
+
14
+ def password
15
+ QiitaTrend.configuration.password
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QiitaTrend
4
+ module Error
5
+ class NotExistsCacheError < ::QiitaTrend::Error::SyntaxError
6
+ attr_reader :cache
7
+
8
+ def initialize(cache)
9
+ @cache = cache
10
+ end
11
+
12
+ def message
13
+ "Does not exist cache file #{@cache.full_path}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QiitaTrend
4
+ module Error
5
+ class SyntaxError < ::StandardError
6
+ end
7
+ end
8
+ end
@@ -16,7 +16,7 @@ module QiitaTrend
16
16
 
17
17
  # 指定されたキャッシュファイルが存在しない場合は処理を終了
18
18
  unless date.nil?
19
- raise StandardError, '指定されたキャッシュファイルが存在しません' unless @cache.cached?
19
+ raise Error::NotExistsCacheError, @cache unless @cache.cached?
20
20
  end
21
21
 
22
22
  # キャッシュが存在する場合はキャッシュから取得
@@ -31,17 +31,18 @@ module QiitaTrend
31
31
  def create_html(target)
32
32
  agent = Mechanize.new
33
33
  agent.user_agent_alias = 'Mac Safari'
34
+ login_qiita(agent) if target.need_login
35
+ agent.get(target.url).body
36
+ end
34
37
 
35
- # ログイン処理
36
- if target.need_login
37
- form = agent.get(QIITA_LOGIN_URI).forms.first
38
- form['identity'] = QiitaTrend.configuration.user_name
39
- form['password'] = QiitaTrend.configuration.password
40
- logged_page = form.submit
41
- raise StandardError, 'ログインに失敗しました(ユーザー名とパスワードでログインできることを確認してください)' if logged_page.title.include?('Login')
42
- end
38
+ def login_qiita(agent)
39
+ form = agent.get(QIITA_LOGIN_URI).forms.first
40
+ form['identity'] = QiitaTrend.configuration.user_name
41
+ form['password'] = QiitaTrend.configuration.password
42
+ logged_page = form.submit
43
43
 
44
- agent.get(target.url).body
44
+ # ページのタイトルにLoginが含まれていたらログイン失敗とする
45
+ raise Error::LoginFailureError if logged_page.title.include?('Login')
45
46
  end
46
47
  end
47
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QiitaTrend
4
- VERSION = '0.2.7'
4
+ VERSION = '0.2.8'
5
5
  end
data/lib/qiita_trend.rb CHANGED
@@ -7,6 +7,9 @@ require 'qiita_trend/cache'
7
7
  require 'qiita_trend/configuration'
8
8
  require 'qiita_trend/trend_type'
9
9
  require 'qiita_trend/target'
10
+ require 'qiita_trend/error/syntax_error'
11
+ require 'qiita_trend/error/login_failure_error'
12
+ require 'qiita_trend/error/not_exists_cache_error'
10
13
 
11
14
  module QiitaTrend
12
15
  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.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - dodonki1223
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -186,6 +186,9 @@ files:
186
186
  - lib/qiita_trend.rb
187
187
  - lib/qiita_trend/cache.rb
188
188
  - lib/qiita_trend/configuration.rb
189
+ - lib/qiita_trend/error/login_failure_error.rb
190
+ - lib/qiita_trend/error/not_exists_cache_error.rb
191
+ - lib/qiita_trend/error/syntax_error.rb
189
192
  - lib/qiita_trend/page.rb
190
193
  - lib/qiita_trend/target.rb
191
194
  - lib/qiita_trend/trend.rb