hatena-bookmark-cli 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/hatena-bookmark +3 -0
- data/bin/hatena-bookmark-auth +3 -0
- data/config.ru +4 -0
- data/hatena-bookmark-cli.gemspec +32 -0
- data/lib/hatena-bookmark-cli/config.rb +19 -0
- data/lib/hatena-bookmark-cli/constants.rb +12 -0
- data/lib/hatena-bookmark-cli/server.rb +121 -0
- data/lib/hatena-bookmark-cli/store.rb +19 -0
- data/lib/hatena-bookmark-cli/version.rb +3 -0
- data/lib/hatena-bookmark-cli/views/index.haml +38 -0
- data/lib/hatena-bookmark-cli/views/layout.haml +20 -0
- data/lib/hatena-bookmark-cli/views/ok.haml +4 -0
- data/lib/hatena-bookmark-cli.rb +6 -0
- data/scripts/hatena-bookmark-auth.rb +10 -0
- data/scripts/hatena-bookmark.rb +128 -0
- data/spec/spec_helper.rb +0 -0
- metadata +222 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: c692e103878405689c5a0210ff8bb653ad97506a
         | 
| 4 | 
            +
              data.tar.gz: e6416cc87af3d6025a980fad0a47a453be7dcc1e
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 575b13d82c9ffaf342ad2ddbd72be5ee9356e794f6c8b41004a569b579e2c817548df5888f49e42da9b2a981551ccd5fc1ec708757aa842a962d371efcf78691
         | 
| 7 | 
            +
              data.tar.gz: 7354edd773eae1d50d7efe0193efdab301857b1a79de33a6a43e2eef36f08c1b75f5a4ed9f30cc979a4aba6ebfd1a6563b94c22c381718826d31e6ad00a620a3
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Hiroyuki Sano
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # Hatena::Bookmark::Cli
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            TODO: Write a gem description
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'hatena-bookmark-cli'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install hatena-bookmark-cli
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            TODO: Write usage instructions here
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Contributing
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            1. Fork it ( http://github.com/<my-github-username>/hatena-bookmark-cli/fork )
         | 
| 26 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 27 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 28 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 29 | 
            +
            5. Create new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
    
        data/bin/hatena-bookmark
    ADDED
    
    
    
        data/config.ru
    ADDED
    
    
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'lib/hatena-bookmark-cli/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name          = "hatena-bookmark-cli"
         | 
| 7 | 
            +
              spec.version       = HatenaBookmarkCLI::VERSION
         | 
| 8 | 
            +
              spec.authors       = ["Hiroyuki Sano"]
         | 
| 9 | 
            +
              spec.email         = ["sh19910711@gmail.com"]
         | 
| 10 | 
            +
              spec.summary       = %q{Hatena Bookmark CLI}
         | 
| 11 | 
            +
              spec.description   = %q{Hatena Bookmark CLI}
         | 
| 12 | 
            +
              spec.homepage      = "https://github.com/sh19910711/ruby-hatena-bookmark-cli"
         | 
| 13 | 
            +
              spec.license       = "MIT"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 16 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 17 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 18 | 
            +
              spec.require_paths = ["lib"]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              spec.add_dependency "rack"
         | 
| 21 | 
            +
              spec.add_dependency "rack_csrf"
         | 
| 22 | 
            +
              spec.add_dependency "sinatra"
         | 
| 23 | 
            +
              spec.add_dependency "sinatra-contrib"
         | 
| 24 | 
            +
              spec.add_dependency "haml"
         | 
| 25 | 
            +
              spec.add_dependency "oauth"
         | 
| 26 | 
            +
              spec.add_dependency "activesupport"
         | 
| 27 | 
            +
              spec.add_dependency "ratom"
         | 
| 28 | 
            +
              spec.add_dependency "highline"
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              spec.add_development_dependency "bundler", "~> 1.5"
         | 
| 31 | 
            +
              spec.add_development_dependency "rake"
         | 
| 32 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module HatenaBookmarkCLI
         | 
| 2 | 
            +
              require 'yaml'
         | 
| 3 | 
            +
              require 'fileutils'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              require_relative 'version'
         | 
| 6 | 
            +
              require_relative 'constants'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              module Config
         | 
| 9 | 
            +
                def self.load
         | 
| 10 | 
            +
                  YAML.load_file(CONFIG_FILE) || {}
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def self.save obj
         | 
| 14 | 
            +
                  File.open CONFIG_FILE, "w" do |f|
         | 
| 15 | 
            +
                    f.write obj.to_yaml
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            module HatenaBookmarkCLI
         | 
| 2 | 
            +
              # config
         | 
| 3 | 
            +
              HOME_DIR    = File.expand_path "~/.hatena-bookmark-cli"
         | 
| 4 | 
            +
              CONFIG_FILE = File.expand_path 'config.yml', HOME_DIR
         | 
| 5 | 
            +
              STORE_FILE  = File.expand_path 'store.yml', HOME_DIR
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              FileUtils.mkdir_p HOME_DIR
         | 
| 8 | 
            +
              FileUtils.touch CONFIG_FILE
         | 
| 9 | 
            +
              FileUtils.chmod 0600, CONFIG_FILE
         | 
| 10 | 
            +
              FileUtils.touch STORE_FILE
         | 
| 11 | 
            +
              FileUtils.chmod 0600, STORE_FILE
         | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,121 @@ | |
| 1 | 
            +
            module HatenaBookmarkCLI
         | 
| 2 | 
            +
              require 'rack/csrf'
         | 
| 3 | 
            +
              require 'sinatra/base'
         | 
| 4 | 
            +
              require 'sinatra/contrib'
         | 
| 5 | 
            +
              require 'haml'
         | 
| 6 | 
            +
              require 'oauth'
         | 
| 7 | 
            +
              require 'json'
         | 
| 8 | 
            +
              require 'securerandom'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              require_relative 'version'
         | 
| 11 | 
            +
              require_relative 'store'
         | 
| 12 | 
            +
              require_relative 'config'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              class Server < Sinatra::Base
         | 
| 15 | 
            +
                configure :development do
         | 
| 16 | 
            +
                  puts "### DEVELOPMENT MODE ###"
         | 
| 17 | 
            +
                  register Sinatra::Reloader
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                configure do
         | 
| 21 | 
            +
                  # session_secretを生成する
         | 
| 22 | 
            +
                  @config = Config.load
         | 
| 23 | 
            +
                  @config[:session_secret] ||= SecureRandom.hex[0...128]
         | 
| 24 | 
            +
                  Config.save @config
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  use Rack::Session::Cookie,
         | 
| 27 | 
            +
                    :key => 'HATENA_BOOKMARK_TO_LINGR_SID',
         | 
| 28 | 
            +
                    :secret => @config[:session_secret],
         | 
| 29 | 
            +
                    :expire_after => 60 * 60 * 24 * 20
         | 
| 30 | 
            +
                  use Rack::Csrf, :field => 'csrf_token'
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  helpers do
         | 
| 33 | 
            +
                    def csrf_token
         | 
| 34 | 
            +
                      Rack::Csrf.csrf_token(env)
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                    def csrf_tag
         | 
| 37 | 
            +
                      Rack::Csrf.csrf_tag(env)
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                before do
         | 
| 43 | 
            +
                  @config = Config.load
         | 
| 44 | 
            +
                  @store  = Store.load
         | 
| 45 | 
            +
                  @consumer_key     = @config[:consumer_key] || @config["consumer_key"]
         | 
| 46 | 
            +
                  @consumer_secret  = @config[:consumer_secret] || @config["consumer_secret"]
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                after do
         | 
| 50 | 
            +
                  Store.save @store
         | 
| 51 | 
            +
                  Config.save @config
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                before do
         | 
| 55 | 
            +
                  @consumer = OAuth::Consumer.new(
         | 
| 56 | 
            +
                    @consumer_key,
         | 
| 57 | 
            +
                    @consumer_secret,
         | 
| 58 | 
            +
                    :site => 'https://www.hatena.ne.jp',
         | 
| 59 | 
            +
                    :request_token_path => '/oauth/initiate',
         | 
| 60 | 
            +
                    :authorize_path     => '/oauth/authorize',
         | 
| 61 | 
            +
                    :access_token_path  => '/oauth/token',
         | 
| 62 | 
            +
                  )
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                get "/" do
         | 
| 66 | 
            +
                  haml :index
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                post "/update" do
         | 
| 70 | 
            +
                  # タグリストを更新する
         | 
| 71 | 
            +
                  access_token = OAuth::AccessToken.new(
         | 
| 72 | 
            +
                    @consumer,
         | 
| 73 | 
            +
                    @store[:oauth_token],
         | 
| 74 | 
            +
                    @store[:oauth_token_secret],
         | 
| 75 | 
            +
                  )
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  # タグを取得する
         | 
| 78 | 
            +
                  res = access_token.request(:get, 'http://b.hatena.ne.jp/1/my/tags')
         | 
| 79 | 
            +
                  tags = JSON.parse(res.body)["tags"].map {|tag| tag["tag"]}
         | 
| 80 | 
            +
                  # タグを記録する
         | 
| 81 | 
            +
                  @store[:tags] = tags
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  haml :ok
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                post "/login" do
         | 
| 87 | 
            +
                  # OAuth認証
         | 
| 88 | 
            +
                  oauth_callback_url = "http://#{@env["HTTP_HOST"]}/callback"
         | 
| 89 | 
            +
                  request_token = @consumer.get_request_token(
         | 
| 90 | 
            +
                    {
         | 
| 91 | 
            +
                      :oauth_callback => oauth_callback_url
         | 
| 92 | 
            +
                    },
         | 
| 93 | 
            +
                    :scope => 'read_public,write_public'
         | 
| 94 | 
            +
                  )
         | 
| 95 | 
            +
                  @store[:request_token] = request_token.token
         | 
| 96 | 
            +
                  @store[:request_token_secret] = request_token.secret
         | 
| 97 | 
            +
                  redirect request_token.authorize_url
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                # OAuth認証が成功したとき
         | 
| 101 | 
            +
                get "/callback" do
         | 
| 102 | 
            +
                  request_token = OAuth::RequestToken.new(
         | 
| 103 | 
            +
                    @consumer,
         | 
| 104 | 
            +
                    @store[:request_token],
         | 
| 105 | 
            +
                    @store[:request_token_secret],
         | 
| 106 | 
            +
                  )
         | 
| 107 | 
            +
                  @store[:request_token] = nil
         | 
| 108 | 
            +
                  @store[:request_token_secret] = nil
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                  oauth_token = request_token.get_access_token(
         | 
| 111 | 
            +
                    {},
         | 
| 112 | 
            +
                    :oauth_verifier => params[:oauth_verifier],
         | 
| 113 | 
            +
                  )
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                  @store[:oauth_token] = oauth_token.token
         | 
| 116 | 
            +
                  @store[:oauth_token_secret] = oauth_token.secret
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  haml :ok
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
              end
         | 
| 121 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module HatenaBookmarkCLI
         | 
| 2 | 
            +
              require 'yaml'
         | 
| 3 | 
            +
              require 'fileutils'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              require_relative 'version'
         | 
| 6 | 
            +
              require_relative 'constants'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              module Store
         | 
| 9 | 
            +
                def self.load
         | 
| 10 | 
            +
                  YAML.load_file(STORE_FILE) || {}
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def self.save obj
         | 
| 14 | 
            +
                  File.open STORE_FILE, "w" do |f|
         | 
| 15 | 
            +
                    f.write obj.to_yaml
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            %div.container
         | 
| 3 | 
            +
              %h2 コマンド
         | 
| 4 | 
            +
              %table.table
         | 
| 5 | 
            +
                %thead
         | 
| 6 | 
            +
                  %tr
         | 
| 7 | 
            +
                    %th.col-xs-2 操作
         | 
| 8 | 
            +
                    %th.col-xs-10 説明
         | 
| 9 | 
            +
                %tbody
         | 
| 10 | 
            +
                  %tr
         | 
| 11 | 
            +
                    %td
         | 
| 12 | 
            +
                      %form{"method" => "post", "action" => "/login"}
         | 
| 13 | 
            +
                        = csrf_tag
         | 
| 14 | 
            +
                        %input.btn.btn-primary{"type" => "submit", "value" => "ログイン"}
         | 
| 15 | 
            +
                    %td
         | 
| 16 | 
            +
                      %p はてなアカウントでログインする
         | 
| 17 | 
            +
                  %tr
         | 
| 18 | 
            +
                    %td
         | 
| 19 | 
            +
                      %form{"method" => "post", "action" => "/update"}
         | 
| 20 | 
            +
                        = csrf_tag
         | 
| 21 | 
            +
                        %input.btn.btn-primary{"type" => "submit", "value" => "更新"}
         | 
| 22 | 
            +
                    %td
         | 
| 23 | 
            +
                      %p タグ一覧を更新する(要ログイン)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            %div.container
         | 
| 26 | 
            +
              %h2 使い方
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              %h3 設定方法
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              %ol
         | 
| 31 | 
            +
                %li <a href="http://www.hatena.ne.jp/oauth/develop">OAuth 開発者向け設定ページ</a>からConsumer KeyとConsumer Secretを取得
         | 
| 32 | 
            +
                %li ~/.hatena-bookmark/config.ymlにConsumer KeyとConsumer Secretを設定
         | 
| 33 | 
            +
                %li ログイン
         | 
| 34 | 
            +
                %li タグの補完機能を利用する場合はタグ一覧を更新
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              %h3 w3mの設定
         | 
| 37 | 
            +
              %ol
         | 
| 38 | 
            +
                %li keymapを設定
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            !!! 5
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            %html
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              %head
         | 
| 6 | 
            +
                %meta{"charset" => "UTF-8"}
         | 
| 7 | 
            +
                - if @title.nil?
         | 
| 8 | 
            +
                  %title Hatena Bookmark CLI Auth
         | 
| 9 | 
            +
                - else
         | 
| 10 | 
            +
                  %title= "#{@title} - Hatena Bookmark CLI Auth"
         | 
| 11 | 
            +
                %link{"rel" => "stylesheet", "href" => "//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"}
         | 
| 12 | 
            +
                %script{"src" => "//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"}
         | 
| 13 | 
            +
                %style body {margin-bottom: 128px;}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              %body
         | 
| 16 | 
            +
                %div#header.container
         | 
| 17 | 
            +
                  %h1 Hatena Bookmark CLI Auth
         | 
| 18 | 
            +
                %div#wrapper.container
         | 
| 19 | 
            +
                  = yield
         | 
| 20 | 
            +
             | 
| @@ -0,0 +1,128 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module HatenaBookmarkCLI
         | 
| 4 | 
            +
              require 'oauth'
         | 
| 5 | 
            +
              require 'atom'
         | 
| 6 | 
            +
              require 'fileutils'
         | 
| 7 | 
            +
              require 'active_support/core_ext'
         | 
| 8 | 
            +
              require 'highline/import'
         | 
| 9 | 
            +
              require 'readline'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              require_relative '../lib/hatena-bookmark-cli'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def self.input_tag
         | 
| 14 | 
            +
                Readline.completion_append_character = nil
         | 
| 15 | 
            +
                Readline.completion_proc = proc { |s| @store[:tags].grep( /^#{Regexp.escape(s)}/ ) }
         | 
| 16 | 
            +
                tag = Readline.readline('> ')
         | 
| 17 | 
            +
                tag
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def self.remove_tag(tags)
         | 
| 21 | 
            +
                Readline.completion_append_character = nil
         | 
| 22 | 
            +
                Readline.completion_proc = proc { |s| tags.grep( /^#{Regexp.escape(s)}/ ) }
         | 
| 23 | 
            +
                target_tag = Readline.readline('> ')
         | 
| 24 | 
            +
                tags.select {|tag| tag != target_tag}
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              def self.get_comment
         | 
| 28 | 
            +
                if @tags.empty?
         | 
| 29 | 
            +
                  "#{@comment}"
         | 
| 30 | 
            +
                else
         | 
| 31 | 
            +
                  tags = @tags.map {|tag| "[#{tag}]"}.join ""
         | 
| 32 | 
            +
                  "#{tags} #{@comment}"
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def self.input_comment
         | 
| 37 | 
            +
                @comment = ""
         | 
| 38 | 
            +
                1000.times do
         | 
| 39 | 
            +
                  choose do |menu|
         | 
| 40 | 
            +
                    menu.prompt = "対応する番号か文字列を入力"
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    menu.choice(:comment) do
         | 
| 43 | 
            +
                      @comment = ask("コメントを入力")
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    menu.choice(:tag) do
         | 
| 47 | 
            +
                      say "タグを1つ入力(TABキーを2回押すと補完候補が表示されます)"
         | 
| 48 | 
            +
                      tag = input_tag
         | 
| 49 | 
            +
                      @tags.push tag
         | 
| 50 | 
            +
                      @tags.uniq!
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    menu.choice(:remove_tag) do
         | 
| 54 | 
            +
                      say "削除するタグを1つ入力(TABキーを2回押すと補完候補が表示されます)"
         | 
| 55 | 
            +
                      @tags = remove_tag(@tags)
         | 
| 56 | 
            +
                      @tags.uniq!
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    menu.choice(:finish) do
         | 
| 60 | 
            +
                      return get_comment
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  say "現在のコメント=#{get_comment}\n\n"
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
                comment
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              @store = Store.load
         | 
| 70 | 
            +
              @config = Config.load
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              @tags = []
         | 
| 73 | 
            +
              @comment = ""
         | 
| 74 | 
            +
              @consumer = OAuth::Consumer.new(
         | 
| 75 | 
            +
                @config[:consumer_key],
         | 
| 76 | 
            +
                @config[:consumer_secret],
         | 
| 77 | 
            +
                :site => 'https://www.hatena.ne.jp',
         | 
| 78 | 
            +
                :request_token_path => '/oauth/initiate',
         | 
| 79 | 
            +
                :authorize_path     => '/oauth/authorize',
         | 
| 80 | 
            +
                :access_token_path  => '/oauth/token',
         | 
| 81 | 
            +
              )
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              access_token = OAuth::AccessToken.new(
         | 
| 84 | 
            +
                @consumer,
         | 
| 85 | 
            +
                @store[:oauth_token],
         | 
| 86 | 
            +
                @store[:oauth_token_secret],
         | 
| 87 | 
            +
              )
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              if ARGV.length == 1
         | 
| 90 | 
            +
                url = ARGV.shift.strip
         | 
| 91 | 
            +
                comment = input_comment
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                entry = Atom::Entry.new do |e|
         | 
| 94 | 
            +
                  e.links << Atom::Link.new(:href => url)
         | 
| 95 | 
            +
                  e.summary = comment
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                puts "# 確認"
         | 
| 99 | 
            +
                puts "URL=#{url}"
         | 
| 100 | 
            +
                puts "Comment=#{comment}"
         | 
| 101 | 
            +
                puts ""
         | 
| 102 | 
            +
                ask("確定: Enter, キャンセル: Ctrl+C")
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                post_xml_text = <<END_OF_XML
         | 
| 105 | 
            +
            <entry xmlns="http://purl.org/atom/ns#">
         | 
| 106 | 
            +
              <title>dummy</title>
         | 
| 107 | 
            +
              <link rel="related" type="text/html" href="#{url}" />
         | 
| 108 | 
            +
              <summary type="text/plain">#{comment}</summary>
         | 
| 109 | 
            +
            </entry>
         | 
| 110 | 
            +
            END_OF_XML
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                say "POST: http://b.hatena.ne.jp/atom/post"
         | 
| 113 | 
            +
                puts access_token.post("http://b.hatena.ne.jp/atom/post", post_xml_text, {'Content-Type'=>'application/xml'})
         | 
| 114 | 
            +
                
         | 
| 115 | 
            +
                edit_xml_text = <<END_OF_XML
         | 
| 116 | 
            +
            <entry xmlns="http://purl.org/atom/ns#">
         | 
| 117 | 
            +
              <summary type="text/plain">#{comment}</summary>
         | 
| 118 | 
            +
            </entry>
         | 
| 119 | 
            +
            END_OF_XML
         | 
| 120 | 
            +
                
         | 
| 121 | 
            +
                say "PUT: http://b.hatena.ne.jp/atom/post"
         | 
| 122 | 
            +
                puts access_token.put("http://b.hatena.ne.jp/atom/edit/#{URI.encode url}", edit_xml_text, {'Content-Type'=>'application/xml'})
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                ask "エンターキーで終了"
         | 
| 125 | 
            +
              else
         | 
| 126 | 
            +
                puts "Usage: command <url>"
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
            File without changes
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,222 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: hatena-bookmark-cli
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Hiroyuki Sano
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-03-07 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rack
         | 
| 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 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rack_csrf
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: sinatra
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: sinatra-contrib
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: haml
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :runtime
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: oauth
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :runtime
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: activesupport
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: ratom
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0'
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: highline
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - ">="
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: '0'
         | 
| 132 | 
            +
              type: :runtime
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - ">="
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: '0'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: bundler
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - "~>"
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: '1.5'
         | 
| 146 | 
            +
              type: :development
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - "~>"
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: '1.5'
         | 
| 153 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 154 | 
            +
              name: rake
         | 
| 155 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 156 | 
            +
                requirements:
         | 
| 157 | 
            +
                - - ">="
         | 
| 158 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 159 | 
            +
                    version: '0'
         | 
| 160 | 
            +
              type: :development
         | 
| 161 | 
            +
              prerelease: false
         | 
| 162 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 163 | 
            +
                requirements:
         | 
| 164 | 
            +
                - - ">="
         | 
| 165 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 166 | 
            +
                    version: '0'
         | 
| 167 | 
            +
            description: Hatena Bookmark CLI
         | 
| 168 | 
            +
            email:
         | 
| 169 | 
            +
            - sh19910711@gmail.com
         | 
| 170 | 
            +
            executables:
         | 
| 171 | 
            +
            - hatena-bookmark
         | 
| 172 | 
            +
            - hatena-bookmark-auth
         | 
| 173 | 
            +
            extensions: []
         | 
| 174 | 
            +
            extra_rdoc_files: []
         | 
| 175 | 
            +
            files:
         | 
| 176 | 
            +
            - ".gitignore"
         | 
| 177 | 
            +
            - Gemfile
         | 
| 178 | 
            +
            - LICENSE.txt
         | 
| 179 | 
            +
            - README.md
         | 
| 180 | 
            +
            - Rakefile
         | 
| 181 | 
            +
            - bin/hatena-bookmark
         | 
| 182 | 
            +
            - bin/hatena-bookmark-auth
         | 
| 183 | 
            +
            - config.ru
         | 
| 184 | 
            +
            - hatena-bookmark-cli.gemspec
         | 
| 185 | 
            +
            - lib/hatena-bookmark-cli.rb
         | 
| 186 | 
            +
            - lib/hatena-bookmark-cli/config.rb
         | 
| 187 | 
            +
            - lib/hatena-bookmark-cli/constants.rb
         | 
| 188 | 
            +
            - lib/hatena-bookmark-cli/server.rb
         | 
| 189 | 
            +
            - lib/hatena-bookmark-cli/store.rb
         | 
| 190 | 
            +
            - lib/hatena-bookmark-cli/version.rb
         | 
| 191 | 
            +
            - lib/hatena-bookmark-cli/views/index.haml
         | 
| 192 | 
            +
            - lib/hatena-bookmark-cli/views/layout.haml
         | 
| 193 | 
            +
            - lib/hatena-bookmark-cli/views/ok.haml
         | 
| 194 | 
            +
            - scripts/hatena-bookmark-auth.rb
         | 
| 195 | 
            +
            - scripts/hatena-bookmark.rb
         | 
| 196 | 
            +
            - spec/spec_helper.rb
         | 
| 197 | 
            +
            homepage: https://github.com/sh19910711/ruby-hatena-bookmark-cli
         | 
| 198 | 
            +
            licenses:
         | 
| 199 | 
            +
            - MIT
         | 
| 200 | 
            +
            metadata: {}
         | 
| 201 | 
            +
            post_install_message: 
         | 
| 202 | 
            +
            rdoc_options: []
         | 
| 203 | 
            +
            require_paths:
         | 
| 204 | 
            +
            - lib
         | 
| 205 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 206 | 
            +
              requirements:
         | 
| 207 | 
            +
              - - ">="
         | 
| 208 | 
            +
                - !ruby/object:Gem::Version
         | 
| 209 | 
            +
                  version: '0'
         | 
| 210 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 211 | 
            +
              requirements:
         | 
| 212 | 
            +
              - - ">="
         | 
| 213 | 
            +
                - !ruby/object:Gem::Version
         | 
| 214 | 
            +
                  version: '0'
         | 
| 215 | 
            +
            requirements: []
         | 
| 216 | 
            +
            rubyforge_project: 
         | 
| 217 | 
            +
            rubygems_version: 2.2.0
         | 
| 218 | 
            +
            signing_key: 
         | 
| 219 | 
            +
            specification_version: 4
         | 
| 220 | 
            +
            summary: Hatena Bookmark CLI
         | 
| 221 | 
            +
            test_files:
         | 
| 222 | 
            +
            - spec/spec_helper.rb
         |