ldclip 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/License.txt +20 -0
- data/Manifest.txt +9 -0
- data/README.txt +1 -4
- data/Rakefile +4 -0
- data/lib/ldclip/version.rb +9 -0
- data/lib/ldclip.rb +101 -0
- data/test/test_helper.rb +2 -0
- data/test/test_ldclip.rb +68 -0
- metadata +59 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 utadaq
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= ldclip
|
-
livedoorclip : http://clip.livedoor.com/
|
|
1
2
|
$ sudo gem install ldclip
|
2
3
|
require 'rubygems'
|
3
4
|
require 'ldclip'
|
4
5
|
# initialize
|
5
6
|
ldc = Ldclip.new('your account','your apikey')
|
6
7
|
# post new clip
|
7
8
|
res = ldc.add('http://www.lucky-ch.com/',
|
8
9
|
"lucky-star",
|
9
10
|
{
|
10
11
|
:extended => 'description',
|
11
12
|
:tags => 'lucky-star kagamin ', # separate by space
|
12
13
|
}
|
13
14
|
)
|
14
15
|
assert_match('done' ,res) # success
|
15
16
|
assert_match('wrong' ,res) # not success
|
16
17
|
# get all clips (XML)
|
17
18
|
ldc.all
|
18
19
|
ldc.all({ :tag => 'lucky-star' })
|
19
20
|
|
20
21
|
# get specified clip
|
21
22
|
ldc.get({:url => 'http://haruhi.tv/'}))
|
22
23
|
ldc.get({:tag => 'haruhi'}))
|
23
24
|
|
24
25
|
# modify posted bookmark
|
25
26
|
same as post new clip
|
26
27
|
# delete specified bookmark
|
27
28
|
ldc.delete('http://www.lucky-ch.com/'))
|
28
29
|
assert_match('done' ,res) # success
|
29
30
|
assert_match('wrong' ,res) # not success
|
30
|
-
options[:dt] not works
|
31
|
-
utadaq ( http://d.hatena.ne.jp/utadaq )
|
32
|
-
MIT Lisence
|
data/Rakefile
ADDED
data/lib/ldclip.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# = About ldclip.rb
|
2
|
+
#
|
3
|
+
# ruby interface of LivedoorClipAPI
|
4
|
+
#
|
5
|
+
# $Id: ldclip.rb 6 2008-02-10 13:58:22Z utadaq $
|
6
|
+
|
7
|
+
require 'net/https'
|
8
|
+
require 'cgi'
|
9
|
+
require 'nkf'
|
10
|
+
|
11
|
+
class Ldclip
|
12
|
+
|
13
|
+
attr_reader :user, :apikey
|
14
|
+
LIVEDOOR_CLIP_HOST = 'api.clip.livedoor.com'
|
15
|
+
|
16
|
+
# user,apikey
|
17
|
+
# get apikey at this url
|
18
|
+
# http://clip.livedoor.com/config/api
|
19
|
+
def initialize(user, apikey)
|
20
|
+
@user = user
|
21
|
+
@apikey = apikey
|
22
|
+
end
|
23
|
+
|
24
|
+
# return last update date
|
25
|
+
def update
|
26
|
+
connect('posts/update')
|
27
|
+
end
|
28
|
+
|
29
|
+
#options
|
30
|
+
# tag
|
31
|
+
# dt (date)
|
32
|
+
# url
|
33
|
+
def get(options = {})
|
34
|
+
params = []
|
35
|
+
params << "tag=#{options[:tag]}" if options[:tag]
|
36
|
+
params << "dt=#{options[:dt]}" if options[:dt]
|
37
|
+
params << "url=#{options[:url]}" if options[:url]
|
38
|
+
connect("posts/get?#{params.map{|e|CGI.escape(NKF.nkf('-w',e))}.join('&')}")
|
39
|
+
end
|
40
|
+
|
41
|
+
#options
|
42
|
+
# tag
|
43
|
+
# count (default = 15,max = 100)
|
44
|
+
def recent(options = {})
|
45
|
+
params = []
|
46
|
+
params << "tag=#{options[:tag]}" if options[:tag]
|
47
|
+
params << "count=#{options[:count]}" if options[:count]
|
48
|
+
connect("posts/recent?#{params.map{|e|CGI.escape(NKF.nkf('-w',e))}.join('&')}")
|
49
|
+
end
|
50
|
+
|
51
|
+
#options
|
52
|
+
# tag
|
53
|
+
def all(options = {})
|
54
|
+
params = ''
|
55
|
+
params += "tag=#{options[:tag]}" if options[:tag]
|
56
|
+
connect("posts/all?#{CGI.escape(NKF.nkf('-w',params))}")
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
#options
|
61
|
+
# extended # as comment for bookmark
|
62
|
+
# tags
|
63
|
+
# dt (date)
|
64
|
+
# replace
|
65
|
+
# shared
|
66
|
+
# rate
|
67
|
+
# r18
|
68
|
+
def add(url, description, options = {})
|
69
|
+
params = []
|
70
|
+
params << "url=#{url}"
|
71
|
+
params << "description=#{CGI.escape(NKF.nkf('-w',description))}"
|
72
|
+
|
73
|
+
options.each do |t,e|
|
74
|
+
params << "#{t.to_s}=#{CGI.escape(NKF.nkf('-w',e.to_s))}"
|
75
|
+
end
|
76
|
+
|
77
|
+
connect("posts/add?#{params.join('&')}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete(url)
|
81
|
+
params = "url=#{url}"
|
82
|
+
|
83
|
+
connect("posts/delete?#{params}")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def connect(url_part = 'posts/update')
|
88
|
+
Net::HTTP.version_1_2
|
89
|
+
|
90
|
+
req = res = ''
|
91
|
+
|
92
|
+
Net::HTTP.start(LIVEDOOR_CLIP_HOST) do |http|
|
93
|
+
req = Net::HTTP::Get.new("/v1/#{url_part}")
|
94
|
+
req.basic_auth @user, @apikey
|
95
|
+
res = http.request(req)
|
96
|
+
end
|
97
|
+
|
98
|
+
sleep 1
|
99
|
+
res.body
|
100
|
+
end
|
101
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_ldclip.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# $Id: test_ldclip.rb 6 2008-02-10 13:58:22Z utadaq $
|
2
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
class TestLdclip < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
# get your apikey at ( need livedoor id )
|
9
|
+
# http://clip.livedoor.com/config/api
|
10
|
+
# @ldc = Ldclip.new('your account','your apikey')
|
11
|
+
assert_nil('get your apikey at ( need livedoor id )')
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize
|
16
|
+
assert_not_nil(@ldc)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_update
|
20
|
+
assert_not_nil(t = @ldc.update)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get
|
24
|
+
assert_not_nil(@ldc.add(url = 'http://haruhi.tv/',"tmp",{:tags => '自重'}))
|
25
|
+
|
26
|
+
# assert_match(/<post /,aa = @ldc.get({:dt => CGI.escape('2008-01-22')})) # :dt not work...
|
27
|
+
assert_match(/<post /,@ldc.get({:url => 'http://haruhi.tv/'}))
|
28
|
+
assert_match(/<post /,@ldc.get({:tag => '自重'}))
|
29
|
+
|
30
|
+
assert_not_nil(@ldc.delete('http://haruhi.tv/'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_recent
|
34
|
+
assert_not_nil(notempty = @ldc.recent)
|
35
|
+
assert_match(/<post /,notempty)
|
36
|
+
|
37
|
+
assert_not_nil(empty = @ldc.recent({:tag => 'dummy'}))
|
38
|
+
## assert_no_match(/<post /,empty)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_all
|
42
|
+
# assert_not_nil(notempty = @ldc.all)
|
43
|
+
# assert_match(/<post /,notempty)
|
44
|
+
|
45
|
+
# assert_not_nil(empty = @ldc.all({:tag => 'dummy'}))
|
46
|
+
## assert_no_match(/<post /,empty)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_posts
|
50
|
+
assert_not_nil(res = @ldc.add('http://www.lucky-ch.com/',"ラッキー☆ちゃんねる#{`date`}",
|
51
|
+
{
|
52
|
+
:extended => 'かがみんは俺の嫁',
|
53
|
+
:tags => 'lucky-star kagamin 京アニ next',
|
54
|
+
:dt => Time.now.xmlschema,
|
55
|
+
:replace => :no,
|
56
|
+
:shared => :no,
|
57
|
+
:rate => 3,
|
58
|
+
:r18 => :no
|
59
|
+
}
|
60
|
+
))
|
61
|
+
assert_match('done' ,res)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_delete
|
65
|
+
assert_not_nil(res = @ldc.delete('http://www.lucky-ch.com/'))
|
66
|
+
assert_match('done',res)
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: ldclip
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2008-02-10 00:00:00 +09:00
|
8
|
+
summary: livedoor clip api for ruby
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: utadaq@gmail.com
|
12
|
+
homepage: http://ldclip.rubyforge.org
|
13
|
+
rubyforge_project: ldclip
|
14
|
+
description: livedoor clip api for ruby
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- utadaq
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- License.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- lib/ldclip.rb
|
38
|
+
- lib/ldclip/version.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- test/test_ldclip.rb
|
41
|
+
test_files:
|
42
|
+
- test/test_helper.rb
|
43
|
+
- test/test_ldclip.rb
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.txt
|
47
|
+
extra_rdoc_files:
|
48
|
+
- History.txt
|
49
|
+
- License.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
dependencies: []
|
59
|
+
|