hatenikki 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cacdb6cc13cdf2bd49abfbde46eadca78dea4f120e2cad6aee5405f99b6435f7
4
+ data.tar.gz: 3880daf589a4a138c51520f239330a7123e4525c788c66b97544f2cde3eaa48c
5
+ SHA512:
6
+ metadata.gz: 23cc9288162253c267ac89a1be1f60e182bd178f3ac0a638be346cd2651e358ff551fc1dce3caadb1295df37691bd007186d50e69e037d7334c0cc6c1d455202
7
+ data.tar.gz: 6ed78af41822b0ab243191f528cd1104e2f017fc1d464f4eadce8221beb21d06a3cd35ebd6a3b0ffebc1ee544b289d98114690f397f1b4cc89e1dd678fcb42b0
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hatenikki.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hatenikki (0.1.0)
5
+ hatenablog
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ hatenablog (0.6.0)
11
+ nokogiri
12
+ oauth
13
+ mini_portile2 (2.4.0)
14
+ nokogiri (1.10.7)
15
+ mini_portile2 (~> 2.4.0)
16
+ oauth (0.5.4)
17
+ rake (12.3.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ hatenikki!
24
+ rake (~> 12.0)
25
+
26
+ BUNDLED WITH
27
+ 2.1.1
@@ -0,0 +1,36 @@
1
+ # Hatenikki
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hatenikki`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hatenikki'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hatenikki
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/hatenikki.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hatenikki"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'hatenikki'
6
+
7
+ Hatenikki::CLI.new(ARGV).run
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/hatenikki/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "hatenikki"
5
+ spec.version = Hatenikki::VERSION
6
+ spec.authors = ["Masataka Pocke Kuwabara"]
7
+ spec.email = ["kuwabara@pocke.me"]
8
+
9
+ spec.summary = %q{Write nikki every day!}
10
+ spec.description = %q{Write nikki every day!}
11
+ spec.homepage = "https://github.com/pocke/hatenikki"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency 'hatenablog'
28
+ end
@@ -0,0 +1,10 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+ require 'hatenablog'
4
+ require "hatenikki/version"
5
+ require 'hatenikki/cli'
6
+
7
+ module Hatenikki
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,78 @@
1
+ module Hatenikki
2
+ class CLI
3
+ CONFIG_DIR = Pathname(File.expand_path("~/.config/hatenikki"))
4
+ HATENABLOG_CONFIG_PATH = CONFIG_DIR / 'hatenablog.yaml'
5
+
6
+ def initialize(argv)
7
+ @argv = argv
8
+ end
9
+
10
+ def run
11
+ case subcommand
12
+ when 'load', 'save', 'publish'
13
+ __send__ subcommand
14
+ else
15
+ raise "Unknown subcommand: #{subcommand}"
16
+ end
17
+ end
18
+
19
+ # Load today's diary.
20
+ private def load
21
+ if entry = todays_entry
22
+ puts entry.content
23
+ end
24
+ end
25
+
26
+ # Save today's diary as draft
27
+ private def save
28
+ content = STDIN.read
29
+ categories = []
30
+
31
+ if entry = todays_entry
32
+ client.update_entry(
33
+ entry.id,
34
+ today,
35
+ content,
36
+ categories,
37
+ entry.draft,
38
+ )
39
+ else
40
+ client.post_entry(
41
+ today,
42
+ content,
43
+ categories,
44
+ 'yes', # draft
45
+ )
46
+ end
47
+ end
48
+
49
+ # Publish drafts except today's
50
+ private def publish
51
+ client.entries.each do |e|
52
+ next unless e.draft?
53
+ next if e.title == today
54
+
55
+ draft = 'no'
56
+ client.update_entry(e.id, e.title, e.content, e.categories, draft)
57
+ puts "#{e.title} has been published."
58
+ end
59
+ end
60
+
61
+ private def client
62
+ @client ||= Hatenablog::Client.create(HATENABLOG_CONFIG_PATH)
63
+ end
64
+
65
+ private def subcommand
66
+ @argv[0]
67
+ end
68
+
69
+ private def todays_entry
70
+ client.entries.find{|entry| entry.title == today }
71
+ end
72
+
73
+ private def today
74
+ # TODO: configurable the offset
75
+ @today ||= (Time.now - 4 * 60 * 60).strftime('%Y-%m-%d')
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Hatenikki
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hatenikki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hatenablog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Write nikki every day!
28
+ email:
29
+ - kuwabara@pocke.me
30
+ executables:
31
+ - hatenikki
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - exe/hatenikki
43
+ - hatenikki.gemspec
44
+ - lib/hatenikki.rb
45
+ - lib/hatenikki/cli.rb
46
+ - lib/hatenikki/version.rb
47
+ homepage: https://github.com/pocke/hatenikki
48
+ licenses: []
49
+ metadata:
50
+ homepage_uri: https://github.com/pocke/hatenikki
51
+ source_code_uri: https://github.com/pocke/hatenikki
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Write nikki every day!
71
+ test_files: []