hatenablog 0.4.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +32 -0
- data/.gitignore +3 -3
- data/Gemfile +3 -1
- data/README.md +144 -19
- data/exe/get_access_token +3 -1
- data/hatenablog.gemspec +9 -9
- data/lib/hatenablog/category.rb +4 -2
- data/lib/hatenablog/client.rb +38 -18
- data/lib/hatenablog/configuration.rb +18 -7
- data/lib/hatenablog/entry.rb +13 -2
- data/lib/hatenablog/requester.rb +18 -30
- data/lib/hatenablog/version.rb +1 -1
- metadata +37 -39
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f5ba2be4110aba1299f43e9392477651511fc8f25b833fa0cbbadf19ead23b9
|
4
|
+
data.tar.gz: afbde859959d37d364e249e22b4a02206db70bd274040fb62068227f74e9447e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3578cefbfeddc8cd8d7ebd143fc581daea4e76a8299acb2d1de0004b18ead98969f7245cd9569c216664163e0940ae54a85f0a3a73d9edeb83be8e054b5ca4d9
|
7
|
+
data.tar.gz: 34c100e0157ae121c65baf6c71cbd13b50fbcad17a6fe3e330bb4413f290632568a287c33562b72a1dc7c49eb924f93b29415f8e67544684722a1cd2bc506174
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on: [pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.4', '2.5', '2.6', '2.7']
|
11
|
+
include:
|
12
|
+
- ruby: '2.7'
|
13
|
+
report-coverage: true
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- run: gem install bundler
|
20
|
+
- run: bundle install -j4
|
21
|
+
- name: Run tests and report test coverage
|
22
|
+
if: matrix.report-coverage
|
23
|
+
uses: paambaati/codeclimate-action@v2.4.0
|
24
|
+
env:
|
25
|
+
CC_TEST_REPORTER_ID: 309cf0784d00d2a6009566d28be111a8a0280cdeb2da280225eedf577b16beb5
|
26
|
+
with:
|
27
|
+
coverageCommand: bundle exec rake
|
28
|
+
- name: Run tests
|
29
|
+
if: "!matrix.report-coverage"
|
30
|
+
env:
|
31
|
+
TZ: Asia/Tokyo
|
32
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
@@ -28,9 +28,9 @@ build/
|
|
28
28
|
|
29
29
|
# for a library or gem, you might want to ignore these files since the code is
|
30
30
|
# intended to run in multiple environments; otherwise, check them in:
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
Gemfile.lock
|
32
|
+
.ruby-version
|
33
|
+
.ruby-gemset
|
34
34
|
|
35
35
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
36
|
.rvmrc
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# Hatenablog
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/hatenablog.svg)](https://badge.fury.io/rb/hatenablog) [![Build Status](https://
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/hatenablog.svg)](https://badge.fury.io/rb/hatenablog) [![Build Status](https://github.com/kymmt90/hatenablog/workflows/build/badge.svg)](https://github.com/kymmt90/hatenablog/actions?workflow=build)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/kymmt90/hatenablog/badges/gpa.svg)](https://codeclimate.com/github/kymmt90/hatenablog)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/kymmt90/hatenablog/badges/coverage.svg)](https://codeclimate.com/github/kymmt90/hatenablog/coverage)
|
6
6
|
|
7
|
-
A library for
|
8
|
-
|
7
|
+
> A library for Hatena Blog AtomPub API
|
8
|
+
|
9
|
+
This gem supports following operations through OAuth 1.0a or Basic authentication:
|
9
10
|
|
10
11
|
- Get blog feeds, entries and categories
|
11
12
|
- Post blog entries
|
@@ -28,7 +29,7 @@ Or install it yourself as:
|
|
28
29
|
|
29
30
|
$ gem install hatenablog
|
30
31
|
|
31
|
-
### Get OAuth
|
32
|
+
### Get OAuth credentials
|
32
33
|
|
33
34
|
You need to set up OAuth 1.0a keys and tokens before using this gem.
|
34
35
|
|
@@ -41,12 +42,12 @@ Access [Hatena application registoration page](http://developer.hatena.ne.jp/) a
|
|
41
42
|
Execute this command:
|
42
43
|
|
43
44
|
$ get_access_token <your consumer key> <your consumer secret>
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
Visit this website and get the PIN: https://www.hatena.com/oauth/authorize?oauth_token=XXXXXXXXXXXXXXXXXXXX
|
46
|
+
Enter the PIN: <your PIN> [Enter]
|
47
|
+
Access token: <your access token>
|
48
|
+
Access token secret: <your access token secret>
|
48
49
|
|
49
|
-
#### 3. Set up the YAML configuration file
|
50
|
+
#### 3. [Optional] Set up the YAML configuration file
|
50
51
|
|
51
52
|
The default configuration file name is `config.yml`:
|
52
53
|
|
@@ -70,9 +71,13 @@ user_id: <%= ENV['USER_ID'] %>
|
|
70
71
|
blog_id: <%= ENV['BLOG_ID'] %>
|
71
72
|
```
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
`blog_id` means your Hatena Blog domain, like "example-user.hatenablog.com".
|
75
|
+
|
76
|
+
You also can set these configurations in your code as described in [the below section](#factories).
|
77
|
+
|
78
|
+
### [Optional] Get Basic authentication credentials
|
79
|
+
If you want to use Basic authentication, visit `http://blog.hatena.ne.jp/#{user_id}/#{blog_id}/config/detail`
|
80
|
+
and check your API key and set up `config.yml` like the following.
|
76
81
|
|
77
82
|
```yml
|
78
83
|
auth_type: basic
|
@@ -94,17 +99,137 @@ Hatenablog::Client.create do |blog|
|
|
94
99
|
end
|
95
100
|
|
96
101
|
# Post new entry
|
97
|
-
posted_entry = blog.post_entry(
|
98
|
-
|
99
|
-
|
102
|
+
posted_entry = blog.post_entry(
|
103
|
+
'Entry Title',
|
104
|
+
'This is entry contents', # markdown form
|
105
|
+
['Test', 'Programming'] # categories
|
106
|
+
)
|
100
107
|
|
101
108
|
# Update entry
|
102
|
-
updated_entry = blog.update_entry(
|
103
|
-
|
104
|
-
|
105
|
-
|
109
|
+
updated_entry = blog.update_entry(
|
110
|
+
posted_entry.id,
|
111
|
+
'Revised Entry Title',
|
112
|
+
posted_entry.content,
|
113
|
+
posted_entry.categories
|
114
|
+
)
|
106
115
|
|
107
116
|
# Delete entry
|
108
117
|
blog.delete_entry(updated_entry.id)
|
109
118
|
end
|
110
119
|
```
|
120
|
+
|
121
|
+
## API
|
122
|
+
|
123
|
+
### Factories
|
124
|
+
|
125
|
+
You can create the client from the configuration file.
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
# Create the client from "./config.yml"
|
129
|
+
client = Hatenablog::Client.create
|
130
|
+
|
131
|
+
# Create the client from the specified configuration
|
132
|
+
client = Hatenablog::Client.create('../another_config.yml')
|
133
|
+
|
134
|
+
Hatenablog::Client.create do |client|
|
135
|
+
# Use the client in the block
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
You can also create the client with a block for configurations.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
client = Hatenablog::Client.new do |config|
|
143
|
+
config.consumer_key = 'XXXXXXXXXXXXXXXXXXXX'
|
144
|
+
config.consumer_secret = 'XXXXXXXXXXXXXXXXXXXX'
|
145
|
+
config.access_token = 'XXXXXXXXXXXXXXXXXXXX'
|
146
|
+
config.access_token_secret = 'XXXXXXXXXXXXXXXXXXXX'
|
147
|
+
config.user_id = 'example-user'
|
148
|
+
config.blog_id = 'example-user.hatenablog.com'
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
### Blog
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
client.title # Get the blog title
|
156
|
+
client.author_name # Get the blog author name
|
157
|
+
```
|
158
|
+
|
159
|
+
### Feeds
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
feed = client.next_feed # Get the first feed when no argument is passed
|
163
|
+
feed.uri
|
164
|
+
feed.next_uri # The next feed URI
|
165
|
+
feed.title
|
166
|
+
feed.author_name
|
167
|
+
feed.update # Updated datetime
|
168
|
+
|
169
|
+
feed.entries # entries in the feed
|
170
|
+
feed.each_entry do |entry|
|
171
|
+
# ...
|
172
|
+
end
|
173
|
+
feed.has_next? # true if the next page exists
|
174
|
+
next_feed = client.next_feed(feed)
|
175
|
+
```
|
176
|
+
|
177
|
+
### Entries
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
client.get_entry('0000000000000000000') # Get the entry specifed by its ID
|
181
|
+
client.entries # Get blog entries in the first page
|
182
|
+
client.entries(1) # Get blog entries in the first and the second page
|
183
|
+
client.all_entries # Get all entries in the blog
|
184
|
+
|
185
|
+
entry = client.post_entry(
|
186
|
+
'Example Title', # title
|
187
|
+
'This is the **example** entry.', # content
|
188
|
+
['Ruby', 'Rails'], # categories
|
189
|
+
'yes' # draft
|
190
|
+
)
|
191
|
+
entry.id
|
192
|
+
entry.uri
|
193
|
+
entry.edit_uri
|
194
|
+
entry.author_name
|
195
|
+
entry.title #=> 'Example Title'
|
196
|
+
entry.content #=> 'This is the **example** entry.'
|
197
|
+
entry.formatted_content #=> '<p>This is the <strong>example</strong> entry.</p>'
|
198
|
+
entry.draft #=> 'yes'
|
199
|
+
entry.draft? #=> true
|
200
|
+
entry.categories #=> ['Ruby', 'Rails']
|
201
|
+
entry.updated # Updated datetime
|
202
|
+
|
203
|
+
client.update_entry(
|
204
|
+
entry.id,
|
205
|
+
entry.title,
|
206
|
+
'This is the **modified** example entry.',
|
207
|
+
entry.categories,
|
208
|
+
'no'
|
209
|
+
)
|
210
|
+
client.delete_entry(entry.id)
|
211
|
+
```
|
212
|
+
|
213
|
+
### Categories
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
categories = client.categories # Get categories registered in the blog
|
217
|
+
categories.each do |cat|
|
218
|
+
puts cat
|
219
|
+
end
|
220
|
+
|
221
|
+
# When categories are fixed, you can only use those categories for your entries.
|
222
|
+
# ref: https://tools.ietf.org/html/rfc5023#section-7.2.1.1
|
223
|
+
categories.fixed?
|
224
|
+
```
|
225
|
+
|
226
|
+
## Contributing
|
227
|
+
|
228
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
229
|
+
2. Commit your changes (`git commit -am 'Add some feature'`)
|
230
|
+
3. Push to the branch (`git push origin my-new-feature`)
|
231
|
+
4. Create a new Pull Request
|
232
|
+
|
233
|
+
## License
|
234
|
+
|
235
|
+
MIT
|
data/exe/get_access_token
CHANGED
@@ -10,6 +10,7 @@ class AccessTokenGetter
|
|
10
10
|
SITE_URI = 'https://www.hatena.com'
|
11
11
|
REQUEST_TOKEN_URI = '/oauth/initiate?scope=read_public%2Cread_private%2Cwrite_public%2Cwrite_private'
|
12
12
|
ACCESS_TOKEN_URI = '/oauth/token'
|
13
|
+
AUTHORIZE_URI = 'https://www.hatena.ne.jp/oauth/authorize'
|
13
14
|
|
14
15
|
def initialize(consumer_key, consumer_secret)
|
15
16
|
@consumer_key = consumer_key
|
@@ -19,7 +20,8 @@ class AccessTokenGetter
|
|
19
20
|
oauth_callback: 'oob',
|
20
21
|
site: SITE_URI,
|
21
22
|
request_token_url: REQUEST_TOKEN_URI,
|
22
|
-
access_token_url: ACCESS_TOKEN_URI
|
23
|
+
access_token_url: ACCESS_TOKEN_URI,
|
24
|
+
authorize_url: AUTHORIZE_URI)
|
23
25
|
end
|
24
26
|
|
25
27
|
def get_request_token
|
data/hatenablog.gemspec
CHANGED
@@ -19,15 +19,15 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.2'
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rr"
|
27
|
-
spec.add_development_dependency "test-unit"
|
28
|
-
spec.add_development_dependency "test-unit-rr"
|
29
|
-
spec.add_development_dependency "yard"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rr"
|
27
|
+
spec.add_development_dependency "test-unit"
|
28
|
+
spec.add_development_dependency "test-unit-rr"
|
29
|
+
spec.add_development_dependency "yard"
|
30
30
|
|
31
|
-
spec.add_dependency "nokogiri"
|
32
|
-
spec.add_dependency "oauth"
|
31
|
+
spec.add_dependency "nokogiri"
|
32
|
+
spec.add_dependency "oauth"
|
33
33
|
end
|
data/lib/hatenablog/category.rb
CHANGED
data/lib/hatenablog/client.rb
CHANGED
@@ -24,6 +24,16 @@ module Hatenablog
|
|
24
24
|
yield blog
|
25
25
|
end
|
26
26
|
|
27
|
+
def initialize(config = nil)
|
28
|
+
if block_given?
|
29
|
+
yield config = Configuration.new
|
30
|
+
config.check_valid_or_raise
|
31
|
+
end
|
32
|
+
@requester = Requester.create(config)
|
33
|
+
@user_id = config.user_id
|
34
|
+
@blog_id = config.blog_id
|
35
|
+
end
|
36
|
+
|
27
37
|
# Get a blog title.
|
28
38
|
# @return [String] blog title
|
29
39
|
def title
|
@@ -38,20 +48,18 @@ module Hatenablog
|
|
38
48
|
feed.author_name
|
39
49
|
end
|
40
50
|
|
41
|
-
# Get blog entries
|
51
|
+
# Get a enumerator of blog entries.
|
42
52
|
# @param [Fixnum] page page number to get
|
43
|
-
# @return [
|
53
|
+
# @return [Hatenablog::Entries] enumerator of blog entries
|
44
54
|
def entries(page = 0)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
(1..page).each do
|
49
|
-
feed = next_feed(feed)
|
50
|
-
break if feed.nil?
|
51
|
-
entries += feed.entries
|
52
|
-
end
|
55
|
+
raise ArgumentError.new('page must be non-negative') if page < 0
|
56
|
+
Entries.new(self, page)
|
57
|
+
end
|
53
58
|
|
54
|
-
|
59
|
+
# Get all blog entries.
|
60
|
+
# @return [Hatenablog::Entries] enumerator of blog entries
|
61
|
+
def all_entries
|
62
|
+
Entries.new(self, nil)
|
55
63
|
end
|
56
64
|
|
57
65
|
# Get the next feed of the given feed.
|
@@ -166,15 +174,8 @@ module Hatenablog
|
|
166
174
|
builder.to_xml
|
167
175
|
end
|
168
176
|
|
169
|
-
|
170
177
|
private
|
171
178
|
|
172
|
-
def initialize(config)
|
173
|
-
@requester = Requester.create(config)
|
174
|
-
@user_id = config.user_id
|
175
|
-
@blog_id = config.blog_id
|
176
|
-
end
|
177
|
-
|
178
179
|
def get(uri)
|
179
180
|
@requester.get(uri)
|
180
181
|
end
|
@@ -202,4 +203,23 @@ module Hatenablog
|
|
202
203
|
@requester.delete(uri)
|
203
204
|
end
|
204
205
|
end
|
206
|
+
|
207
|
+
class Entries
|
208
|
+
include Enumerable
|
209
|
+
|
210
|
+
def initialize(client, page = 0)
|
211
|
+
@client = client
|
212
|
+
@page = page
|
213
|
+
end
|
214
|
+
|
215
|
+
def each(&block)
|
216
|
+
return enum_for(__method__) unless block_given?
|
217
|
+
|
218
|
+
current_page = 0
|
219
|
+
until (@page && current_page > @page) || !(feed = @client.next_feed(feed))
|
220
|
+
feed.entries.each { |entry| block.call(entry) }
|
221
|
+
current_page += 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
205
225
|
end
|
@@ -4,20 +4,31 @@ require 'ostruct'
|
|
4
4
|
|
5
5
|
module Hatenablog
|
6
6
|
class Configuration < OpenStruct
|
7
|
-
OAUTH_KEYS = %
|
8
|
-
BASIC_KEYS = %
|
7
|
+
OAUTH_KEYS = %i(consumer_key consumer_secret access_token access_token_secret user_id blog_id)
|
8
|
+
BASIC_KEYS = %i(api_key user_id blog_id)
|
9
9
|
|
10
10
|
# Create a new configuration.
|
11
11
|
# @param [String] config_file configuration file path
|
12
12
|
# @return [Hatenablog::Configuration]
|
13
13
|
def self.create(config_file)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
loaded_config = YAML.load(ERB.new(File.read(config_file)).result)
|
15
|
+
config = new(loaded_config)
|
16
|
+
config.check_valid_or_raise
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_valid_or_raise
|
20
|
+
unless (lacking_keys = self.send(:lacking_keys)).empty?
|
21
|
+
raise ConfigurationError, "Following keys are not setup. #{lacking_keys.map(&:to_s)}"
|
18
22
|
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
19
27
|
|
20
|
-
|
28
|
+
def lacking_keys
|
29
|
+
required_keys = self['auth_type'] == 'basic' ? BASIC_KEYS : OAUTH_KEYS
|
30
|
+
config_keys = to_h.keys
|
31
|
+
required_keys.select { |key| !config_keys.include?(key) }
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
data/lib/hatenablog/entry.rb
CHANGED
@@ -19,6 +19,7 @@ module Hatenablog
|
|
19
19
|
define_method(method) do |*args, &block|
|
20
20
|
result = send(origin_method, *args, &block)
|
21
21
|
send(hook)
|
22
|
+
result
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -27,8 +28,9 @@ module Hatenablog
|
|
27
28
|
class Entry
|
28
29
|
extend AfterHook
|
29
30
|
|
30
|
-
attr_accessor :uri, :author_name, :title, :content, :draft
|
31
|
+
attr_accessor :uri, :author_name, :title, :content, :draft
|
31
32
|
attr_reader :edit_uri, :id, :updated
|
33
|
+
attr_writer :categories
|
32
34
|
|
33
35
|
def updated=(date)
|
34
36
|
@updated = Time.parse(date)
|
@@ -87,6 +89,11 @@ module Hatenablog
|
|
87
89
|
@document.to_s.gsub(/\"/, "'")
|
88
90
|
end
|
89
91
|
|
92
|
+
# @return [String]
|
93
|
+
def formatted_content
|
94
|
+
@formatted_content
|
95
|
+
end
|
96
|
+
|
90
97
|
def self.build_xml(uri, edit_uri, author_name, title, content, draft, categories, updated)
|
91
98
|
builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml|
|
92
99
|
xml.entry('xmlns' => 'http://www.w3.org/2005/Atom',
|
@@ -128,10 +135,14 @@ module Hatenablog
|
|
128
135
|
@author_name = @document.at_css('author name').content
|
129
136
|
@title = @document.at_css('title').content
|
130
137
|
@content = @document.at_css('content').content
|
138
|
+
@formatted_content = @document.xpath('//hatena:formatted-content', hatena: 'http://www.hatena.ne.jp/info/xmlns#')[0]
|
139
|
+
@formatted_content = @formatted_content.content if @formatted_content
|
131
140
|
@draft = @document.at_css('entry app|control app|draft').content
|
132
141
|
@categories = parse_categories
|
133
|
-
|
142
|
+
if @document.at_css('entry updated')
|
134
143
|
@updated = Time.parse(@document.at_css('entry updated').content)
|
144
|
+
else
|
145
|
+
@updated = nil
|
135
146
|
end
|
136
147
|
end
|
137
148
|
|
data/lib/hatenablog/requester.rb
CHANGED
@@ -3,6 +3,9 @@ require 'oauth'
|
|
3
3
|
|
4
4
|
module Hatenablog
|
5
5
|
module Requester
|
6
|
+
ATOM_CONTENT_TYPE = 'application/atom+xml; type=entry'.freeze
|
7
|
+
DEFAULT_HEADER = { 'Content-Type' => ATOM_CONTENT_TYPE }
|
8
|
+
|
6
9
|
class RequestError < StandardError; end
|
7
10
|
|
8
11
|
def self.create(config)
|
@@ -25,12 +28,7 @@ module Hatenablog
|
|
25
28
|
# @param [string] uri target URI
|
26
29
|
# @return [Net::HTTPResponse] HTTP response
|
27
30
|
def get(uri)
|
28
|
-
|
29
|
-
response = @access_token.get(uri)
|
30
|
-
rescue => problem
|
31
|
-
raise RequestError, 'Fail to GET: ' + problem.to_s
|
32
|
-
end
|
33
|
-
response
|
31
|
+
request(:get, uri)
|
34
32
|
end
|
35
33
|
|
36
34
|
# HTTP POST method
|
@@ -38,15 +36,8 @@ module Hatenablog
|
|
38
36
|
# @param [string] body HTTP request body
|
39
37
|
# @param [string] headers HTTP request headers
|
40
38
|
# @return [Net::HTTPResponse] HTTP response
|
41
|
-
def post(uri,
|
42
|
-
|
43
|
-
headers = { 'Content-Type' => 'application/atom+xml; type=entry' } )
|
44
|
-
begin
|
45
|
-
response = @access_token.post(uri, body, headers)
|
46
|
-
rescue => problem
|
47
|
-
raise RequestError, 'Fail to POST: ' + problem.to_s
|
48
|
-
end
|
49
|
-
response
|
39
|
+
def post(uri, body = '', headers = DEFAULT_HEADER)
|
40
|
+
request(:post, uri, body: body, headers: headers)
|
50
41
|
end
|
51
42
|
|
52
43
|
# HTTP PUT method
|
@@ -54,29 +45,26 @@ module Hatenablog
|
|
54
45
|
# @param [string] body HTTP request body
|
55
46
|
# @param [string] headers HTTP request headers
|
56
47
|
# @return [Net::HTTPResponse] HTTP response
|
57
|
-
def put(uri,
|
58
|
-
|
59
|
-
headers = { 'Content-Type' => 'application/atom+xml; type=entry' } )
|
60
|
-
begin
|
61
|
-
response = @access_token.put(uri, body, headers)
|
62
|
-
rescue => problem
|
63
|
-
raise RequestError, 'Fail to PUT: ' + problem.to_s
|
64
|
-
end
|
65
|
-
response
|
48
|
+
def put(uri, body = '', headers = DEFAULT_HEADER)
|
49
|
+
request(:put, uri, body: body, headers: headers)
|
66
50
|
end
|
67
51
|
|
68
52
|
# HTTP DELETE method
|
69
53
|
# @param [string] uri target URI
|
70
54
|
# @param [string] headers HTTP request headers
|
71
55
|
# @return [Net::HTTPResponse] HTTP response
|
72
|
-
def delete(uri,
|
73
|
-
|
56
|
+
def delete(uri, headers = DEFAULT_HEADER)
|
57
|
+
request(:delete, uri, headers: headers)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def request(method, uri, body: nil, headers: nil)
|
74
63
|
begin
|
75
|
-
|
64
|
+
@access_token.send(method, *[uri, body, headers].compact)
|
76
65
|
rescue => problem
|
77
|
-
raise RequestError,
|
66
|
+
raise RequestError, "Fail to #{method.upcase}: " + problem.to_s
|
78
67
|
end
|
79
|
-
response
|
80
68
|
end
|
81
69
|
end
|
82
70
|
|
@@ -136,7 +124,7 @@ module Hatenablog
|
|
136
124
|
req.basic_auth @user_id, @api_key
|
137
125
|
if body
|
138
126
|
req.body = body
|
139
|
-
req.content_type =
|
127
|
+
req.content_type = ATOM_CONTENT_TYPE
|
140
128
|
end
|
141
129
|
|
142
130
|
http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.port == 443)
|
data/lib/hatenablog/version.rb
CHANGED
metadata
CHANGED
@@ -1,127 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatenablog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: test-unit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: test-unit-rr
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: yard
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: nokogiri
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: oauth
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
117
|
+
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0
|
124
|
+
version: '0'
|
125
125
|
description: Hatenablog AtomPub API library
|
126
126
|
email:
|
127
127
|
- kymmt90@gmail.com
|
@@ -130,8 +130,8 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/workflows/build.yml"
|
133
134
|
- ".gitignore"
|
134
|
-
- ".travis.yml"
|
135
135
|
- Gemfile
|
136
136
|
- LICENSE.txt
|
137
137
|
- README.md
|
@@ -160,17 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
160
|
requirements:
|
161
161
|
- - ">="
|
162
162
|
- !ruby/object:Gem::Version
|
163
|
-
version: '2.
|
163
|
+
version: '2.2'
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
166
|
- - ">="
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
|
171
|
-
rubygems_version: 2.5.1
|
170
|
+
rubygems_version: 3.1.2
|
172
171
|
signing_key:
|
173
172
|
specification_version: 4
|
174
173
|
summary: Hatenablog AtomPub API library
|
175
174
|
test_files: []
|
176
|
-
has_rdoc:
|