hatenagroup 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +2 -0
- data/lib/hatenagroup.rb +2 -5
- data/lib/hatenagroup/calendar.rb +7 -65
- data/lib/hatenagroup/calendar/client.rb +37 -0
- data/lib/hatenagroup/calendar/keyword.rb +30 -0
- data/lib/hatenagroup/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzM5ZDU3MDgzNjM3NjdjOTAyYjNlM2Q2OWZkY2I5Y2QwMjdhMDJmOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzdkMzRhMTI4NGE2MTI1NTdmNGI4ZjcwNmNmOGJmMWFhY2UxMmRiMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzliNjM0NTdlZThhNzUwNzBmNGQ2ODljZDRmMWE0ZGNjNmNkZTc4OTkxZTI0
|
10
|
+
MzBjMTRkY2JiZGU2MWEyMDM3ZDI0YWEwNmJkMmQ1OGI2ZDI0NjljN2JmMzFl
|
11
|
+
OGJiNDk1ZWI0NzZhZTJhOWMzODQ0YjJmOGMwNDViYjRiNDExZjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjA5YjQ1MGY5OThhMTA1NzI0MjY3M2MxYmQ5MTJlZDZkOTYxMzViOGI2NmE4
|
14
|
+
NjUxNjRiNTE0OThlMDQwYTNmODNmMWZkOGZiOTI0OTFmODNmNmNiODFmMTVl
|
15
|
+
MmZhNjdhOTgyOGZjOWZkM2U3YjU5MjA4ODg5Zjc1YzJmZDZmN2M=
|
data/README.md
CHANGED
data/lib/hatenagroup.rb
CHANGED
data/lib/hatenagroup/calendar.rb
CHANGED
@@ -1,71 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'hatenagroup/calendar/client'
|
2
|
+
require 'hatenagroup/calendar/keyword'
|
2
3
|
|
3
4
|
module HatenaGroup
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
@agent = Mechanize.new
|
8
|
-
agent.log = Logger.new(STDERR)
|
9
|
-
agent.log.level = Logger::INFO
|
10
|
-
agent.user_agent = USER_AGENT
|
11
|
-
login! hatena_user_id, hatena_password
|
5
|
+
module Calendar
|
6
|
+
def self.new(*args)
|
7
|
+
Client.new *args
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
attr_reader :agent
|
20
|
-
attr_reader :group
|
21
|
-
|
22
|
-
USER_AGENT = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
|
23
|
-
HATENA_LOGIN_URL = 'https://www.hatena.ne.jp/login'
|
24
|
-
|
25
|
-
def login!(hatena_user_id, hatena_password)
|
26
|
-
agent.get(HATENA_LOGIN_URL).form_with(:action => '/login') do |form|
|
27
|
-
form['name'] = hatena_user_id
|
28
|
-
form['password'] = hatena_password
|
29
|
-
form['persistent'] = 0
|
30
|
-
form.submit
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def keyword(s)
|
35
|
-
Keyword.new agent, group, s
|
36
|
-
end
|
37
|
-
|
38
|
-
class Keyword
|
39
|
-
def initialize(agent, group, keyword)
|
40
|
-
@agent = agent
|
41
|
-
@group = group
|
42
|
-
@keyword = keyword
|
43
|
-
end
|
44
|
-
|
45
|
-
def body
|
46
|
-
agent.get(read_url).form_with(:name => 'edit', :action => '/keyword').field_with(:name => 'body').value
|
47
|
-
end
|
48
|
-
|
49
|
-
def body=(s)
|
50
|
-
agent.get(edit_url).form_with(:name => 'edit', :action => '/keyword') do |form|
|
51
|
-
next unless form
|
52
|
-
form['body'] = s
|
53
|
-
form.submit
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
attr_reader :agent
|
59
|
-
attr_reader :keyword
|
60
|
-
attr_reader :group
|
61
|
-
|
62
|
-
def read_url
|
63
|
-
"http://#{group}.g.hatena.ne.jp/keyword/#{keyword}?mode=edit&#{Time.now.to_i}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def edit_url
|
67
|
-
"http://#{group}.g.hatena.ne.jp/keyword/#{keyword}?mode=edit"
|
68
|
-
end
|
69
|
-
end
|
10
|
+
USER_AGENT = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
|
11
|
+
HATENA_LOGIN_URL = 'https://www.hatena.ne.jp/login'
|
70
12
|
end
|
71
13
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
module HatenaGroup
|
4
|
+
module Calendar
|
5
|
+
class Client
|
6
|
+
attr_reader :agent
|
7
|
+
attr_reader :group
|
8
|
+
|
9
|
+
def initialize(group, hatena_user_id, hatena_password)
|
10
|
+
@group = group
|
11
|
+
@agent = ::Mechanize.new
|
12
|
+
agent.log = ::Logger.new(STDERR)
|
13
|
+
agent.log.level = ::Logger::INFO
|
14
|
+
agent.user_agent = USER_AGENT
|
15
|
+
login! hatena_user_id, hatena_password
|
16
|
+
end
|
17
|
+
|
18
|
+
def day(d)
|
19
|
+
if d.instance_of?(Date)
|
20
|
+
Keyword.new self, d.strftime("%Y-%m-%d")
|
21
|
+
else
|
22
|
+
Keyword.new self, d
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def login!(hatena_user_id, hatena_password)
|
28
|
+
agent.get(HATENA_LOGIN_URL).form_with(:action => '/login') do |form|
|
29
|
+
form['name'] = hatena_user_id
|
30
|
+
form['password'] = hatena_password
|
31
|
+
form['persistent'] = 0
|
32
|
+
form.submit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module HatenaGroup
|
2
|
+
module Calendar
|
3
|
+
class Keyword
|
4
|
+
def initialize(client, keyword)
|
5
|
+
@client = client
|
6
|
+
@keyword = keyword
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
edit_form.field_with(:name => 'body').value
|
11
|
+
end
|
12
|
+
|
13
|
+
def body=(s)
|
14
|
+
edit_form do |form|
|
15
|
+
form['body'] = s
|
16
|
+
form.submit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
attr_reader :client
|
22
|
+
attr_reader :keyword
|
23
|
+
|
24
|
+
def edit_form(&b)
|
25
|
+
url = "http://#{client.group}.g.hatena.ne.jp/keyword/#{keyword}?mode=edit"
|
26
|
+
client.agent.get(url).form_with(:action => '/keyword', &b)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/hatenagroup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatenagroup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Sano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- hatenagroup.gemspec
|
112
112
|
- lib/hatenagroup.rb
|
113
113
|
- lib/hatenagroup/calendar.rb
|
114
|
+
- lib/hatenagroup/calendar/client.rb
|
115
|
+
- lib/hatenagroup/calendar/keyword.rb
|
114
116
|
- lib/hatenagroup/version.rb
|
115
117
|
homepage: https://github.com/sh19910711/hatenagroup.rb
|
116
118
|
licenses: []
|