Skip to content

Instantly share code, notes, and snippets.

@garin
Last active December 13, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garin/4952593 to your computer and use it in GitHub Desktop.
Save garin/4952593 to your computer and use it in GitHub Desktop.
catch.com 用コマンドラインツール
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# catch.com のテキストメモの作成と表示をするコマンドラインツール
#
# == 環境
# 以下の環境でのみ動作確認済み
#
# * Debian 7.0
# * ruby-1.9
#
# == 必須
# rest_client(https://github.com/archiloque/rest-client)のgemパッケージが必要
#
# # gem istall rest-client
#
# == 設定
# ~/.catchrc にユーザ名とパスワードを記入(OAuth は未対応)
# $ vi ~/.catchrc
# @name = "namae"
# @password = "oshienai"
#
# $ chmod 600 ~/.catchrc
#
# == 使い方
# // メモの表示 : default ストリームの最新メモを6個
# $ catch.rb
#
# // メモの作成 : ストリーム,タグ指定とかは未サポート
# $ catch.rb memomemo
#
# == 履歴
# 2013-02-14: 0.0.0 : 初版
# 2013-02-14: 0.0.1 : ちょっとだけリファクタリング
#
# メモ: catch.com は json のみをサポート(xml は未サポート)
#
require 'rest_client'
require 'json'
CONF_FILE="~/.catchrc"
load(CONF_FILE)
@url = "https://#{@user}:#{@password}@api.catch.com/v3/streams/default"
# メモの作成
def create(text)
RestClient.post(@url,
{:text => text},
:content_type => :json, :accept => :json
) {|response, request, result|
puts "request : #{request}" if $DEBUG
puts "response: #{respons}" if $DEBUG
puts "result : #{result}" if $DEBUG
puts response.code
}
end
# メモの検索
def search
@limit = 6
@offset = 0
@full = 1
@sort="modified_desc"
ret = RestClient.get(@url,
{:params => { :limit => @limit,
:offset => @offset,
:full => @full,
:sort => @sort},
:content_type => :json, :accept => :json
}) do |response, request, result|
puts "request : #{request}" if $DEBUG
puts "response: #{respons}" if $DEBUG
puts "result : #{result}" if $DEBUG
JSON.parse(response.body)["result"]["objects"].each_with_index do |obj, i|
puts "[#{i+1}] #{obj['text']}"
end
end
end
# = main
ARGV[0] ? create(ARGV[0]) : search if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment