hatena_fotolife 0.1.4 → 0.1.5.1

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: 9dc8501c1b6d97f8057aa97822f195372cd6bb73cbcbc9e70594f3cdb9199b96
4
- data.tar.gz: 3bc1a4b4fb88346f334ca3dcb7a9315deba966f1ee2a791b5f43508478636027
3
+ metadata.gz: acb08e0297b2a479091092a49ef22cd09729595e856d167910687db96e49eee6
4
+ data.tar.gz: 666a8527ca760259ccec92bbfc4f337f9adb653a104feb3b9ff07169b5d2a533
5
5
  SHA512:
6
- metadata.gz: d7625609e36d227ddcf21c1ca1221baa240f3614edebcbab7ccb174662cde9d6e714744e4993cc7cbf48be8d48cbe45c4f912aac2aea1fe6ae90bc125aa6a858
7
- data.tar.gz: e4eb6b35a972b440f7121bd0e093ffee419b2f7f85a1932013425a083adc24932bbc749b3671f0e10ced85e7ed5f6e007e6bab88c899d698d1f5102da3994d20
6
+ metadata.gz: 39c752af5786aedba3e905b76dc24dc7279fcddc0eae383c9fd33b8e17e4e926559029ef16bfbf6e6dac33d2fee34118177799c1762f3fd530ac09aad8b008a2
7
+ data.tar.gz: 77cb6a40b933d3bc49a96d5347dd7459d9a912450bcc077b53b479c4a03e1ccaff42ad6216edf429c142a02e568d906cb4984e412e1ce9455a1271e93d8f4924
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hatena_fotolife (0.1.3)
4
+ hatena_fotolife (0.1.5.1)
5
5
  hatenablog
6
6
  nokogiri
7
7
  oauth
@@ -9,34 +9,46 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- coderay (1.1.2)
13
- diff-lcs (1.3)
14
- hatenablog (0.6.0)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.6.1)
14
+ hashie (5.0.0)
15
+ hatenablog (0.9.0)
15
16
  nokogiri
16
17
  oauth
17
- method_source (1.0.0)
18
- mini_portile2 (2.4.0)
19
- nokogiri (1.10.9)
20
- mini_portile2 (~> 2.4.0)
21
- oauth (0.5.4)
22
- pry (0.13.1)
18
+ method_source (1.1.0)
19
+ mini_portile2 (2.8.8)
20
+ nokogiri (1.18.6)
21
+ mini_portile2 (~> 2.8.2)
22
+ racc (~> 1.4)
23
+ oauth (1.1.0)
24
+ oauth-tty (~> 1.0, >= 1.0.1)
25
+ snaky_hash (~> 2.0)
26
+ version_gem (~> 1.1)
27
+ oauth-tty (1.0.5)
28
+ version_gem (~> 1.1, >= 1.1.1)
29
+ pry (0.15.2)
23
30
  coderay (~> 1.1)
24
31
  method_source (~> 1.0)
25
- rake (13.0.1)
26
- rspec (3.9.0)
27
- rspec-core (~> 3.9.0)
28
- rspec-expectations (~> 3.9.0)
29
- rspec-mocks (~> 3.9.0)
30
- rspec-core (3.9.2)
31
- rspec-support (~> 3.9.3)
32
- rspec-expectations (3.9.2)
32
+ racc (1.8.1)
33
+ rake (13.2.1)
34
+ rspec (3.13.0)
35
+ rspec-core (~> 3.13.0)
36
+ rspec-expectations (~> 3.13.0)
37
+ rspec-mocks (~> 3.13.0)
38
+ rspec-core (3.13.3)
39
+ rspec-support (~> 3.13.0)
40
+ rspec-expectations (3.13.3)
33
41
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-mocks (3.9.1)
42
+ rspec-support (~> 3.13.0)
43
+ rspec-mocks (3.13.2)
36
44
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.9.0)
38
- rspec-support (3.9.3)
39
- yard (0.9.25)
45
+ rspec-support (~> 3.13.0)
46
+ rspec-support (3.13.2)
47
+ snaky_hash (2.0.1)
48
+ hashie
49
+ version_gem (~> 1.1, >= 1.1.1)
50
+ version_gem (1.1.6)
51
+ yard (0.9.37)
40
52
 
41
53
  PLATFORMS
42
54
  ruby
@@ -50,4 +62,4 @@ DEPENDENCIES
50
62
  yard
51
63
 
52
64
  BUNDLED WITH
53
- 2.0.2
65
+ 2.6.6
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "hatena_fotolife/version"
@@ -24,7 +23,7 @@ Gem::Specification.new do |spec|
24
23
  spec.require_paths = ["lib"]
25
24
 
26
25
  spec.add_dependency "nokogiri"
27
- spec.add_dependency "oauth"
26
+ spec.add_dependency "oauth", "~> 1.1"
28
27
  spec.add_dependency "hatenablog"
29
28
 
30
29
  spec.add_development_dependency "bundler", "~> 2.0"
@@ -28,18 +28,35 @@ module HatenaFotolife
28
28
  @requester = Requester.create(config)
29
29
  end
30
30
 
31
+ def file_path_to_mime_type(file_path:)
32
+ ext = File.extname(file_path).downcase
33
+ mime_type = case ext
34
+ when '.png' then 'image/png'
35
+ when '.gif' then 'image/gif'
36
+ when '.jpg','.jpeg' then 'image/jpeg'
37
+ else
38
+ raise "Unsupported file extension: #{ext}"
39
+ end
40
+ return mime_type
41
+ end
42
+
31
43
  # Post a image.
32
44
  # @param [String] title entry title
33
45
  # @param [String] content entry content
34
- # @return [HatenaImage::Image] posted image
46
+ # @return [String] URI of posted image
35
47
  def post_image(title: nil, file_path:, subject: nil)
36
- title = File.basename(file_path, '.*') unless title
37
- content = Base64.encode64(open(file_path).read)
38
- entry_xml = image_xml(title: title, content: content, subject:subject)
39
- response = post(entry_xml)
40
- image = Image.load_xml(response.body)
41
- puts "Image url: #{image.image_uri}"
42
- image.image_uri
48
+ begin
49
+ title = File.basename(file_path, '.*') unless title
50
+ content = Base64.encode64(File.open(file_path, 'rb').read)
51
+ mime_type = file_path_to_mime_type(file_path: file_path)
52
+ entry_xml = image_xml(title: title, content: content, subject: subject, mime_type: mime_type)
53
+ response = post(entry_xml)
54
+ image = Image.load_xml(response.body)
55
+ puts "Image url: #{image.image_uri}"
56
+ image.image_uri
57
+ rescue StandardError => e
58
+ puts "Error: #{e.message}"
59
+ end
43
60
  end
44
61
 
45
62
  # Build a entry XML from arguments.
@@ -47,11 +64,11 @@ module HatenaFotolife
47
64
  # @param [String] subject folder name
48
65
  # @param [String] content entry content
49
66
  # @return [String] XML string
50
- def image_xml(title:, content:, subject:)
67
+ def image_xml(title:, content:, subject:, mime_type:)
51
68
  builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml|
52
69
  xml.entry('xmlns' => 'http://purl.org/atom/ns') do
53
70
  xml.title title
54
- xml.content(content, type: 'image/jpeg', mode: 'base64')
71
+ xml.content(content, type: mime_type, mode: 'base64')
55
72
  if subject
56
73
  xml.doc.root.add_namespace_definition('dc', 'http://purl.org/dc/elements/1.1/')
57
74
  xml['dc'].subject(subject)
@@ -1,3 +1,3 @@
1
1
  module HatenaFotolife
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatena_fotolife
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - riho.takagi
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
10
+ date: 2025-03-31 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nokogiri
@@ -28,16 +27,16 @@ dependencies:
28
27
  name: oauth
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - ">="
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
32
+ version: '1.1'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - ">="
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '0'
39
+ version: '1.1'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: hatenablog
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +150,6 @@ homepage: https://github.com/rlho/hatena_fotolife
151
150
  licenses:
152
151
  - MIT
153
152
  metadata: {}
154
- post_install_message:
155
153
  rdoc_options: []
156
154
  require_paths:
157
155
  - lib
@@ -166,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
164
  - !ruby/object:Gem::Version
167
165
  version: '0'
168
166
  requirements: []
169
- rubygems_version: 3.0.3
170
- signing_key:
167
+ rubygems_version: 3.6.6
171
168
  specification_version: 4
172
169
  summary: A ruby gem for Uploading image to Hatena Fotolife
173
170
  test_files: []