hatenablog 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/hatenablog.gemspec +1 -1
- data/lib/hatenablog/client.rb +27 -14
- data/lib/hatenablog/entry.rb +13 -6
- data/lib/hatenablog/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b3523997853851a6cfaf4a4d00230dd4f6b8b06
|
4
|
+
data.tar.gz: bcfa0433a24776cabbb92b16add175064bf7983d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c65f0473fd3f11b137b329a7af1d14916262383ef090b4e11da81d9519820068971623b33459199e99b1be1ad0847150bec7230987fa8bd519f2ed2e7b9b61
|
7
|
+
data.tar.gz: 479bfb1f32b41e701f23ef8c3f5da750177d4894a4154a34f350fb681db8f5557d8bb80445e2c59c26577c86cdf61e856f112b14e6022cd87d72a209ba5f5d4b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Hatenablog
|
1
|
+
# Hatenablog [![Build Status](https://travis-ci.org/kymmt90/hatenablog.svg?branch=master)](https://travis-ci.org/kymmt90/hatenablog)
|
2
2
|
|
3
3
|
A library for Hatenablog AtomPub API.
|
4
4
|
This gem supports following operations using OAuth authorization:
|
@@ -44,7 +44,7 @@ Execute this command:
|
|
44
44
|
|
45
45
|
#### 3. Set up the YAML configuration file
|
46
46
|
|
47
|
-
The default configuration file name is `
|
47
|
+
The default configuration file name is `config.yml`:
|
48
48
|
|
49
49
|
```yml
|
50
50
|
consumer_key: <Hatena application consumer key>
|
@@ -60,7 +60,7 @@ blog_id: <Hatenablog ID>
|
|
60
60
|
```ruby
|
61
61
|
require 'hatenablog'
|
62
62
|
|
63
|
-
# Read the OAuth configuration from '
|
63
|
+
# Read the OAuth configuration from 'config.yml'
|
64
64
|
Hatenablog::Client.create do |blog|
|
65
65
|
# Get each entry's content
|
66
66
|
blog.entries.each do |entry|
|
data/Rakefile
CHANGED
data/hatenablog.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.required_ruby_version = '>= 2.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rr", "~> 1.1.2"
|
27
27
|
spec.add_development_dependency "test-unit", "~> 3.1.4"
|
data/lib/hatenablog/client.rb
CHANGED
@@ -45,20 +45,28 @@ module Hatenablog
|
|
45
45
|
# @param [Fixnum] page page number to get
|
46
46
|
# @return [Array] blog entries
|
47
47
|
def entries(page = 0)
|
48
|
-
|
49
|
-
|
50
|
-
entries = []
|
51
|
-
while current_page <= page
|
52
|
-
feed = Feed.load_xml(get_collection(next_page_uri).body)
|
53
|
-
entries += feed.entries
|
48
|
+
feed = Feed.load_xml(get_collection(collection_uri).body)
|
49
|
+
entries = feed.entries
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
(1..page).each do
|
52
|
+
feed = next_feed(feed)
|
53
|
+
break if feed.nil?
|
54
|
+
entries += feed.entries
|
58
55
|
end
|
56
|
+
|
59
57
|
entries
|
60
58
|
end
|
61
59
|
|
60
|
+
# Get the next feed of the given feed.
|
61
|
+
# Return the first feed if no argument is passed.
|
62
|
+
# @param [Hatenablog::Feed] feed blog feed
|
63
|
+
# @return [Hatenablog::Feed] next blog feed
|
64
|
+
def next_feed(feed = nil)
|
65
|
+
return Feed.load_xml(get_collection(collection_uri).body) if feed.nil?
|
66
|
+
return nil unless feed.has_next?
|
67
|
+
Feed.load_xml(get_collection(feed.next_uri).body)
|
68
|
+
end
|
69
|
+
|
62
70
|
# Get blog categories array.
|
63
71
|
# @return [Array] blog categories
|
64
72
|
def categories
|
@@ -92,9 +100,10 @@ module Hatenablog
|
|
92
100
|
# @param [String] content entry content
|
93
101
|
# @param [Array] categories entry categories
|
94
102
|
# @param [String] draft this entry is draft if 'yes', otherwise it is not draft
|
103
|
+
# @param [String] updated entry updated datetime (ISO 8601)
|
95
104
|
# @return [Hatenablog::BlogEntry] updated entry
|
96
|
-
def update_entry(entry_id, title = '', content = '', categories = [], draft = 'no')
|
97
|
-
entry_xml = entry_xml(title, content, categories, draft)
|
105
|
+
def update_entry(entry_id, title = '', content = '', categories = [], draft = 'no', updated = '')
|
106
|
+
entry_xml = entry_xml(title, content, categories, draft, updated)
|
98
107
|
response = put(entry_xml, member_uri(entry_id))
|
99
108
|
Entry.load_xml(response.body)
|
100
109
|
end
|
@@ -135,9 +144,10 @@ module Hatenablog
|
|
135
144
|
# @param [String] content entry content
|
136
145
|
# @param [Array] categories entry categories
|
137
146
|
# @param [String] draft this entry is draft if 'yes', otherwise it is not draft
|
147
|
+
# @param [String] updated entry updated datetime (ISO 8601)
|
138
148
|
# @param [String] author_name entry author name
|
139
149
|
# @return [String] XML string
|
140
|
-
def entry_xml(title = '', content = '', categories = [], draft = 'no', author_name = @user_id)
|
150
|
+
def entry_xml(title = '', content = '', categories = [], draft = 'no', updated = '', author_name = @user_id)
|
141
151
|
xml = <<XML
|
142
152
|
<?xml version="1.0" encoding="utf-8"?>
|
143
153
|
<entry xmlns="http://www.w3.org/2005/Atom"
|
@@ -145,17 +155,20 @@ module Hatenablog
|
|
145
155
|
<title>%s</title>
|
146
156
|
<author><name>%s</name></author>
|
147
157
|
<content type="text/x-markdown">%s</content>
|
148
|
-
%s
|
158
|
+
%s%s
|
149
159
|
<app:control>
|
150
160
|
<app:draft>%s</app:draft>
|
151
161
|
</app:control>
|
152
162
|
</entry>
|
153
163
|
XML
|
154
164
|
|
165
|
+
unless updated.empty?
|
166
|
+
updated = '<updated>' + updated + '</updated>'
|
167
|
+
end
|
155
168
|
categories_tag = categories.inject('') do |s, c|
|
156
169
|
s + "<category term=\"#{c}\" />\n"
|
157
170
|
end
|
158
|
-
xml % [title, author_name, content, categories_tag, draft]
|
171
|
+
xml % [title, author_name, content, updated, categories_tag, draft]
|
159
172
|
end
|
160
173
|
|
161
174
|
|
data/lib/hatenablog/entry.rb
CHANGED
@@ -2,7 +2,7 @@ require 'nokogiri'
|
|
2
2
|
|
3
3
|
module Hatenablog
|
4
4
|
class Entry
|
5
|
-
attr_reader :uri, :edit_uri, :id, :author_name, :title, :content
|
5
|
+
attr_reader :uri, :edit_uri, :id, :author_name, :title, :content, :updated
|
6
6
|
|
7
7
|
# Create a new blog entry from a XML string.
|
8
8
|
# @param [String] xml XML string representation
|
@@ -19,11 +19,12 @@ module Hatenablog
|
|
19
19
|
# @param [String] content entry content
|
20
20
|
# @param [String] draft this entry is draft if 'yes', otherwise it is not draft
|
21
21
|
# @param [Array] categories categories array
|
22
|
+
# @param [String] updated entry updated datetime (ISO 8601)
|
22
23
|
# @return [Hatenablog::Entry]
|
23
24
|
def self.create(uri: '', edit_uri: '', author_name: '', title: '',
|
24
|
-
content: '', draft: 'no', categories: [])
|
25
|
+
content: '', draft: 'no', categories: [], updated: '')
|
25
26
|
Hatenablog::Entry.new(self.build_xml(uri, edit_uri, author_name, title,
|
26
|
-
content, draft, categories))
|
27
|
+
content, draft, categories, updated))
|
27
28
|
end
|
28
29
|
|
29
30
|
# @return [Boolean]
|
@@ -50,7 +51,7 @@ module Hatenablog
|
|
50
51
|
|
51
52
|
private
|
52
53
|
|
53
|
-
def self.build_xml(uri, edit_uri, author_name, title, content, draft, categories)
|
54
|
+
def self.build_xml(uri, edit_uri, author_name, title, content, draft, categories, updated)
|
54
55
|
xml = <<XML
|
55
56
|
<?xml version='1.0' encoding='UTF-8'?>
|
56
57
|
<entry xmlns:app='http://www.w3.org/2007/app' xmlns='http://www.w3.org/2005/Atom'>
|
@@ -59,17 +60,20 @@ module Hatenablog
|
|
59
60
|
<author><name>%s</name></author>
|
60
61
|
<title>%s</title>
|
61
62
|
<content type='text/x-markdown'>%s</content>
|
62
|
-
%s
|
63
|
+
%s%s
|
63
64
|
<app:control>
|
64
65
|
<app:draft>%s</app:draft>
|
65
66
|
</app:control>
|
66
67
|
</entry>
|
67
68
|
XML
|
68
69
|
|
70
|
+
unless updated.nil?
|
71
|
+
updated = '<updated>' + updated + '</updated>'
|
72
|
+
end
|
69
73
|
categories_tag = categories.inject('') do |s, c|
|
70
74
|
s + "<category term=\"#{c}\" />\n"
|
71
75
|
end
|
72
|
-
xml % [edit_uri, uri, author_name, title, content, categories_tag, draft]
|
76
|
+
xml % [edit_uri, uri, author_name, title, content, updated, categories_tag, draft]
|
73
77
|
end
|
74
78
|
|
75
79
|
def initialize(xml)
|
@@ -86,6 +90,9 @@ XML
|
|
86
90
|
@content = @document.at_css('content').content
|
87
91
|
@draft = @document.at_css('entry app|control app|draft').content
|
88
92
|
@categories = parse_categories
|
93
|
+
unless @document.at_css('entry updated').nil?
|
94
|
+
@updated = Time.parse(@document.at_css('entry updated').content)
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
def parse_categories
|
data/lib/hatenablog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatenablog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.4.
|
170
|
+
rubygems_version: 2.4.8
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Hatenablog AtomPub API library
|