kakuyomu_client 0.1.0 → 0.2.0
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +9 -5
- data/lib/kakuyomu_client.rb +33 -9
- data/lib/kakuyomu_client/url_utils.rb +13 -0
- data/lib/kakuyomu_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5821352e15f24aa5ac2d2a3c77765c26c1429a00e18c742c74fd2a8ef1ec2c19
|
4
|
+
data.tar.gz: 8f1d3cf2deb8aea32e114427ae4c6a331c550505683f6495a1f31b9d2c26dde5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f7d3cbd1785d5216d806cdc04466b0403fa85706244d050fd8cd01ad416cf02b83c3d8a8655d12da2d9a2c737b84361a5d5181e6acf6f1640614885a397892
|
7
|
+
data.tar.gz: 261c6aaf2f4895c4ab2e0922a3702c50abd224c63e36909e9cbaf7ee57d202bac4923a0e12f745962e93a2324d47761cfd7ad1be2486d9cca087ac0c7b6d9e48
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kakuyomu_client (0.
|
4
|
+
kakuyomu_client (0.2.0)
|
5
5
|
selenium-webdriver (~> 3.14)
|
6
6
|
|
7
7
|
GEM
|
@@ -17,7 +17,7 @@ GEM
|
|
17
17
|
jaro_winkler (1.5.1)
|
18
18
|
meowcop (1.17.1)
|
19
19
|
rubocop (>= 0.57.0)
|
20
|
-
method_source (0.9.
|
20
|
+
method_source (0.9.1)
|
21
21
|
parallel (1.12.1)
|
22
22
|
parser (2.5.3.0)
|
23
23
|
ast (~> 2.4.0)
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
unicode-display_width (~> 1.4.0)
|
51
51
|
ruby-progressbar (1.10.0)
|
52
52
|
rubyzip (1.2.2)
|
53
|
-
selenium-webdriver (3.
|
53
|
+
selenium-webdriver (3.141.0)
|
54
54
|
childprocess (~> 0.5)
|
55
55
|
rubyzip (~> 1.2, >= 1.2.2)
|
56
56
|
unicode-display_width (1.4.0)
|
data/README.md
CHANGED
@@ -23,18 +23,22 @@ Or install it yourself as:
|
|
23
23
|
```ruby
|
24
24
|
require 'kakuyomu_client'
|
25
25
|
|
26
|
-
WORK_ID = 1234567890123456789 # URLから取得した小説ID https://kakuyomu.jp/works/#{WORK_ID}
|
27
|
-
|
28
26
|
client = KakuyomuClient.new
|
29
27
|
|
28
|
+
# ログイン
|
29
|
+
client.login!(email: YOUR_EMAIL, password: YOUR_PASSWORD)
|
30
|
+
|
31
|
+
# 小説の URL から work_id を抽出
|
32
|
+
work_id = UrlUtils.extract_work_id('https://kakuyomu.jp/works/1234567890123456789') # => 1234567890123456789
|
33
|
+
|
30
34
|
# エピソードを執筆
|
31
|
-
episode_id = client.create_episode(work_id:
|
35
|
+
episode_id = client.create_episode(work_id: work_id, title: 'タイトル', body: '本文')
|
32
36
|
|
33
37
|
# エピソードを編集
|
34
|
-
client.update_episode(work_id:
|
38
|
+
client.update_episode(work_id: work_id, episode_id: episode_id, title: '新しいタイトル', body: '新しい本文')
|
35
39
|
|
36
40
|
# エピソードを削除
|
37
|
-
client.delete_episode(work_id:
|
41
|
+
client.delete_episode(work_id: work_id, episode_id: episode_id)
|
38
42
|
```
|
39
43
|
|
40
44
|
## Development
|
data/lib/kakuyomu_client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "selenium-webdriver"
|
2
2
|
|
3
|
+
require_relative "kakuyomu_client/url_utils"
|
3
4
|
require_relative "kakuyomu_client/version"
|
4
5
|
|
5
6
|
class KakuyomuClient
|
@@ -21,7 +22,7 @@ class KakuyomuClient
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def login!(email:, password:)
|
24
|
-
driver.navigate.to(
|
25
|
+
driver.navigate.to(login_url)
|
25
26
|
driver.find_element(name: 'email_address').send_keys(email)
|
26
27
|
driver.find_element(name: 'password').send_keys(password)
|
27
28
|
driver.find_element(xpath: '//button[text()="ログイン"]').click
|
@@ -32,13 +33,13 @@ class KakuyomuClient
|
|
32
33
|
|
33
34
|
@logged_in = true
|
34
35
|
rescue Selenium::WebDriver::Error::WebDriverError => e
|
35
|
-
raise Error,
|
36
|
+
raise Error, "Logging in failed: #{e.message}"
|
36
37
|
end
|
37
38
|
|
38
39
|
def create_episode(work_id:, title:, body:)
|
39
40
|
raise NotLoggedInError unless logged_in?
|
40
41
|
|
41
|
-
driver.navigate.to(
|
42
|
+
driver.navigate.to(new_episode_url(work_id))
|
42
43
|
driver.find_element(name: 'title').send_keys(title)
|
43
44
|
driver.find_element(name: 'body').send_keys(body)
|
44
45
|
driver.find_element(id: 'reserveButton').click
|
@@ -48,15 +49,16 @@ class KakuyomuClient
|
|
48
49
|
driver.find_element(id: 'page-my-works-episodes-published')
|
49
50
|
end
|
50
51
|
|
51
|
-
driver.current_url
|
52
|
+
episode_id = UrlUtils.extract_episode_id(driver.current_url)
|
53
|
+
episode_url(work_id, episode_id)
|
52
54
|
rescue Selenium::WebDriver::Error::WebDriverError => e
|
53
|
-
raise Error,
|
55
|
+
raise Error, "Creating episode failed: #{e.message}"
|
54
56
|
end
|
55
57
|
|
56
58
|
def update_episode(work_id:, episode_id:, title:, body:)
|
57
59
|
raise NotLoggedInError unless logged_in?
|
58
60
|
|
59
|
-
driver.navigate.to(
|
61
|
+
driver.navigate.to(edit_episode_url(work_id, episode_id))
|
60
62
|
|
61
63
|
title_input = driver.find_element(name: 'title')
|
62
64
|
title_input.clear
|
@@ -71,14 +73,16 @@ class KakuyomuClient
|
|
71
73
|
Selenium::WebDriver::Wait.new.until do
|
72
74
|
driver.find_element(id: 'page-my-works-episodes-published')
|
73
75
|
end
|
76
|
+
|
77
|
+
episode_url(work_id, episode_id)
|
74
78
|
rescue Selenium::WebDriver::Error::WebDriverError => e
|
75
|
-
raise Error,
|
79
|
+
raise Error, "Updating episode failed: #{e.message}"
|
76
80
|
end
|
77
81
|
|
78
82
|
def delete_episode(work_id:, episode_id:)
|
79
83
|
raise NotLoggedInError unless logged_in?
|
80
84
|
|
81
|
-
driver.navigate.to(
|
85
|
+
driver.navigate.to(edit_episode_url(work_id, episode_id))
|
82
86
|
driver.find_element(id: 'contentMainHeader-toolButton').click
|
83
87
|
driver.find_element(id: 'contentAsideHeader').find_element(xpath: '//*[contains(text(), "ツール")]').click
|
84
88
|
driver.find_element(id: 'deleteEpisode').find_element(tag_name: 'button').click
|
@@ -87,7 +91,27 @@ class KakuyomuClient
|
|
87
91
|
Selenium::WebDriver::Wait.new.until do
|
88
92
|
driver.find_element(id: 'modelessMessage')
|
89
93
|
end
|
94
|
+
|
95
|
+
true
|
90
96
|
rescue Selenium::WebDriver::Error::WebDriverError => e
|
91
|
-
raise Error,
|
97
|
+
raise Error, "Deleting episode failed: #{e.message}"
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def login_url
|
103
|
+
"#{base_url}/login"
|
104
|
+
end
|
105
|
+
|
106
|
+
def episode_url(work_id, episode_id)
|
107
|
+
"#{base_url}/works/#{work_id}/episodes/#{episode_id}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def new_episode_url(work_id)
|
111
|
+
"#{base_url}/my/works/#{work_id}/episodes/new"
|
112
|
+
end
|
113
|
+
|
114
|
+
def edit_episode_url(work_id, episode_id)
|
115
|
+
"#{base_url}/my/works/#{work_id}/episodes/#{episode_id}"
|
92
116
|
end
|
93
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kakuyomu_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuji Nakahara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: selenium-webdriver
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- bin/setup
|
131
131
|
- kakuyomu_client.gemspec
|
132
132
|
- lib/kakuyomu_client.rb
|
133
|
+
- lib/kakuyomu_client/url_utils.rb
|
133
134
|
- lib/kakuyomu_client/version.rb
|
134
135
|
homepage: https://github.com/fuji-nakahara/kakuyomu_client
|
135
136
|
licenses:
|