lgs-www-delicious 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.rdoc +52 -0
  2. data/LICENSE.rdoc +25 -0
  3. data/Manifest +48 -0
  4. data/README.rdoc +206 -0
  5. data/Rakefile +55 -0
  6. data/init.rb +1 -0
  7. data/lib/www/delicious.rb +942 -0
  8. data/lib/www/delicious/bundle.rb +73 -0
  9. data/lib/www/delicious/element.rb +73 -0
  10. data/lib/www/delicious/errors.rb +46 -0
  11. data/lib/www/delicious/post.rb +123 -0
  12. data/lib/www/delicious/tag.rb +101 -0
  13. data/lib/www/delicious/version.rb +33 -0
  14. data/setup.rb +1585 -0
  15. data/test/bundle_test.rb +63 -0
  16. data/test/delicious_test.rb +369 -0
  17. data/test/fixtures/net_response_invalid_account.yml +25 -0
  18. data/test/fixtures/net_response_success.yml +23 -0
  19. data/test/online_test.rb +147 -0
  20. data/test/post_test.rb +68 -0
  21. data/test/tag_test.rb +69 -0
  22. data/test/test_all.rb +19 -0
  23. data/test/test_helper.rb +43 -0
  24. data/test/testcases/element/bundle.xml +1 -0
  25. data/test/testcases/element/invalid_root.xml +2 -0
  26. data/test/testcases/element/post.xml +2 -0
  27. data/test/testcases/element/post_unshared.xml +2 -0
  28. data/test/testcases/element/tag.xml +1 -0
  29. data/test/testcases/response/bundles_all.xml +5 -0
  30. data/test/testcases/response/bundles_all_empty.xml +2 -0
  31. data/test/testcases/response/bundles_delete.xml +2 -0
  32. data/test/testcases/response/bundles_set.xml +2 -0
  33. data/test/testcases/response/bundles_set_error.xml +2 -0
  34. data/test/testcases/response/posts_add.xml +2 -0
  35. data/test/testcases/response/posts_all.xml +12 -0
  36. data/test/testcases/response/posts_dates.xml +14 -0
  37. data/test/testcases/response/posts_dates_with_tag.xml +14 -0
  38. data/test/testcases/response/posts_delete.xml +2 -0
  39. data/test/testcases/response/posts_get.xml +7 -0
  40. data/test/testcases/response/posts_get_with_tag.xml +6 -0
  41. data/test/testcases/response/posts_recent.xml +19 -0
  42. data/test/testcases/response/posts_recent_with_tag.xml +19 -0
  43. data/test/testcases/response/tags_get.xml +5 -0
  44. data/test/testcases/response/tags_get_empty.xml +2 -0
  45. data/test/testcases/response/tags_rename.xml +2 -0
  46. data/test/testcases/response/update.delicious1.xml +2 -0
  47. data/test/testcases/response/update.xml +3 -0
  48. data/www-delicious.gemspec +44 -0
  49. metadata +148 -0
@@ -0,0 +1,23 @@
1
+ --- !ruby/object:Net::HTTPOK
2
+ body: |
3
+ <?xml version="1.0" encoding="UTF-8"?>
4
+ <update time="2008-07-29T19:29:39Z" inboxnew="0"/>
5
+ <!-- fe01.api.del.ac4.yahoo.net uncompressed/chunked Tue Jul 29 13:51:05 PDT 2008 -->
6
+
7
+ body_exist: true
8
+ code: "200"
9
+ header:
10
+ connection:
11
+ - close
12
+ p3p:
13
+ - policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
14
+ content-type:
15
+ - text/xml; charset=utf-8
16
+ date:
17
+ - Tue, 29 Jul 2008 20:51:05 GMT
18
+ transfer-encoding:
19
+ - chunked
20
+ http_version: "1.1"
21
+ message: OK
22
+ read: true
23
+ socket:
@@ -0,0 +1,147 @@
1
+ #
2
+ # = WWW::Delicious
3
+ #
4
+ # Ruby client for del.icio.us API.
5
+ #
6
+ #
7
+ # Category:: WWW
8
+ # Package:: WWW::Delicious
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ require 'test_helper'
18
+
19
+
20
+ RUN_ONLINE_TESTS = ($0 == __FILE__) unless defined?(RUN_ONLINE_TESTS)
21
+
22
+ puts "Online test #{__FILE__} skipped.\n" +
23
+ "Use `ONLINE=1` to run online tests.\n" unless RUN_ONLINE_TESTS
24
+
25
+
26
+ class OnlineTest < Test::Unit::TestCase
27
+
28
+ def setup
29
+ init_account
30
+ end
31
+
32
+
33
+ def test_update
34
+ response = @delicious.update
35
+ assert_instance_of(Time, response)
36
+ end
37
+
38
+
39
+ def test_bundles_all
40
+ response = @delicious.bundles_all
41
+ assert_kind_of(Array, response)
42
+
43
+ response.each do |bundle|
44
+ assert_instance_of(WWW::Delicious::Bundle, bundle)
45
+ assert_instance_of(Array, bundle.tags)
46
+ assert_not_nil(bundle.name)
47
+ end
48
+ end
49
+
50
+ def test_bundles_set
51
+ bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle', :tags => %w(ruby python).sort)
52
+ assert_nothing_raised() { @delicious.bundles_set(bundle) }
53
+ end
54
+
55
+ def test_bundles_delete
56
+ bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle')
57
+ assert_nothing_raised() { @delicious.bundles_delete(bundle) }
58
+ end
59
+
60
+
61
+ def test_tags_get
62
+ response = @delicious.tags_get
63
+ assert_kind_of(Array, response)
64
+
65
+ response.each do |tag|
66
+ assert_instance_of(WWW::Delicious::Tag, tag)
67
+ assert_not_nil(tag.name)
68
+ assert_not_nil(tag.count)
69
+ end
70
+ end
71
+
72
+ def test_tags_rename
73
+ ftag = WWW::Delicious::Tag.new(:name => 'old_tag')
74
+ otag = WWW::Delicious::Tag.new(:name => 'new_tag')
75
+ assert_nothing_raised() { @delicious.tags_rename(ftag, otag) }
76
+ end
77
+
78
+
79
+ def test_post_add
80
+ # TODO
81
+ end
82
+
83
+ def test_post_all
84
+ response = @delicious.posts_get
85
+ assert_kind_of(Array, response)
86
+
87
+ response.each do |post|
88
+ assert_kind_of(WWW::Delicious::Post, post)
89
+ end
90
+ end
91
+
92
+ def test_post_dates
93
+ response = @delicious.posts_dates
94
+ assert_kind_of(Hash, response)
95
+
96
+ response.each do |item, value|
97
+ assert_match(/[\d]{4}-[\d]{2}-[\d]{2}/, item)
98
+ assert_match(/[\d]+/, value.to_s)
99
+ end
100
+ end
101
+
102
+ def test_post_delete
103
+ # TODO
104
+ end
105
+
106
+ def test_posts_get
107
+ response = @delicious.posts_get
108
+ assert_kind_of(Array, response)
109
+
110
+ response.each do |post|
111
+ assert_kind_of(WWW::Delicious::Post, post)
112
+ end
113
+ end
114
+
115
+ def test_posts_recent
116
+ response = @delicious.posts_recent
117
+ assert_kind_of(Array, response)
118
+
119
+ response.each do |post|
120
+ assert_kind_of(WWW::Delicious::Post, post)
121
+ end
122
+ end
123
+
124
+
125
+ protected
126
+
127
+ def init_account(options = {}, &block)
128
+ @delicious_username ||= ENV['DELICIOUS_USERNAME'] || self.class.prompt('Delicious Username') { |value| abort('Value cannot be blank') if value.blank?; value }
129
+ @delicious_password ||= ENV['DELICIOUS_PASSWORD'] || self.class.prompt('Delicious Password') { |value| abort('Value cannot be blank') if value.blank?; value }
130
+ @delicious = WWW::Delicious.new(@delicious_username, @delicious_password, options, &block)
131
+ end
132
+
133
+ # Convenient method for collecting user input
134
+ def self.prompt(text, options = {}, &block)
135
+ default = options[:default] || ''
136
+ value = nil
137
+ while value.blank?
138
+ print "#{text} [#{default}]: "
139
+ value = STDIN.gets.chomp!
140
+ value = default if value.blank?
141
+ value = yield value if block_given?
142
+ value
143
+ end
144
+ value
145
+ end
146
+
147
+ end if RUN_ONLINE_TESTS
@@ -0,0 +1,68 @@
1
+ #
2
+ # = WWW::Delicious
3
+ #
4
+ # Ruby client for del.icio.us API.
5
+ #
6
+ #
7
+ # Category:: WWW
8
+ # Package:: WWW::Delicious
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ require 'test_helper'
18
+ require 'www/delicious/post'
19
+
20
+
21
+ class PostTest < Test::Unit::TestCase
22
+
23
+ def test_post
24
+ expected = { :title => 'JavaScript DOM reference', :url => URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1') }
25
+ assert_attributes(instance(expected), expected)
26
+ end
27
+
28
+ def test_post_shared_defaults_to_true
29
+ assert(instance(:title => 'Foo').shared)
30
+ end
31
+
32
+ def test_post_shared_is_false
33
+ assert(!instance(:title => 'Foo', :shared => false).shared)
34
+ end
35
+
36
+ def test_post_from_rexml
37
+ dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/post.xml'))
38
+ element = WWW::Delicious::Post.from_rexml(dom.root)
39
+
40
+ assert_equal(URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1'), element.url)
41
+ assert_equal("JavaScript DOM reference", element.title)
42
+ assert_equal("dom reference", element.notes)
43
+ assert_equal("c0238dc0c44f07daedd9a1fd9bbdeebd", element.uid)
44
+ assert_equal(55, element.others)
45
+ assert_equal(%w(dom javascript webdev), element.tags)
46
+ assert_equal(Time.parse("2005-11-28T05:26:09Z"), element.time)
47
+ end
48
+
49
+ def test_post_from_rexml_not_shared
50
+ dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/post_unshared.xml'))
51
+ element = WWW::Delicious::Post.from_rexml(dom.root)
52
+
53
+ assert(!element.shared)
54
+ end
55
+
56
+
57
+ # def test_valid
58
+ # end
59
+
60
+
61
+ protected
62
+
63
+ # returns a stub instance
64
+ def instance(values = {}, &block)
65
+ WWW::Delicious::Post.new(values)
66
+ end
67
+
68
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # = WWW::Delicious
3
+ #
4
+ # Ruby client for del.icio.us API.
5
+ #
6
+ #
7
+ # Category:: WWW
8
+ # Package:: WWW::Delicious
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ require 'test_helper'
18
+ require 'www/delicious/tag'
19
+
20
+
21
+ class TagTest < Test::Unit::TestCase
22
+
23
+ def test_tag
24
+ expected = { :name => 'MyTag', :count => 2 }
25
+ assert_attributes(instance(expected), expected)
26
+ end
27
+
28
+ def test_tag_from_rexml
29
+ dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/tag.xml'))
30
+ expected = { :count => 1, :name => 'activedesktop' }
31
+
32
+ element = WWW::Delicious::Tag.from_rexml(dom.root)
33
+ assert_attributes(element, expected)
34
+ end
35
+
36
+
37
+ def test_tag_name_strips_whitespaces
38
+ [' foo ', 'foo ', ' foo ', ' foo'].each do |v|
39
+ assert_equal('foo', instance(:name => v).name) # => 'foo'
40
+ end
41
+ end
42
+
43
+ def test_to_s_returns_name_as_string
44
+ assert_equal('foobar', instance(:name => 'foobar', :count => 4).to_s)
45
+ end
46
+
47
+ def test_to_s_returns_empty_string_with_name_nil
48
+ assert_equal('', instance(:name => nil).to_s)
49
+ end
50
+
51
+
52
+ # def test_api_valid
53
+ # ['foo', ' foo '].each do |v|
54
+ # assert(instance(v).api_valid?)
55
+ # end
56
+ # ['', ' '].each do |v|
57
+ # assert(!instance(v).api_valid?)
58
+ # end
59
+ # end
60
+
61
+
62
+ protected
63
+
64
+ # returns a stub instance
65
+ def instance(values = {}, &block)
66
+ WWW::Delicious::Tag.new(values)
67
+ end
68
+
69
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # = WWW::Delicious
3
+ #
4
+ # Ruby client for del.icio.us API.
5
+ #
6
+ #
7
+ # Category:: WWW
8
+ # Package:: WWW::Delicious
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ require 'test_helper'
18
+
19
+ Dir.glob(File.dirname(__FILE__) + '/**/*_test.rb').sort.each { |unit| require unit }
@@ -0,0 +1,43 @@
1
+ #
2
+ # = WWW::Delicious
3
+ #
4
+ # Ruby client for del.icio.us API.
5
+ #
6
+ #
7
+ # Category:: WWW
8
+ # Package:: WWW::Delicious
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
18
+
19
+ require 'rubygems'
20
+ require 'test/unit'
21
+ require 'mocha'
22
+ require 'www/delicious'
23
+
24
+ # testcase file path
25
+ TESTCASES_PATH = File.dirname(__FILE__) + '/testcases' unless defined?(TESTCASES_PATH)
26
+ FIXTURES_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(FIXTURES_PATH)
27
+
28
+ # prevent online tests to be run automatically
29
+ RUN_ONLINE_TESTS = (ENV['ONLINE'].to_i == 1) unless defined?(RUN_ONLINE_TESTS)
30
+
31
+
32
+ class Test::Unit::TestCase
33
+
34
+ # asserts all given attributes match mapped value in +instance+.
35
+ # +instance+ is the instance to be tested,
36
+ # +expected_mapping+ is the attribute => value mapping.
37
+ def assert_attributes(instance, expected_mapping)
38
+ expected_mapping.each do |key, value|
39
+ assert_equal(value, instance.send(key.to_sym), "Expected `#{key}` to be `#{value}`")
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1 @@
1
+ <bundle name="music" tags="ipod mp3 music" />
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <foo />
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <post href="http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1" description="JavaScript DOM reference" extended="dom reference" hash="c0238dc0c44f07daedd9a1fd9bbdeebd" others="55" tag="dom javascript webdev" time="2005-11-28T05:26:09Z"/>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <post href="http://stacktrace.it/articoli/2008/03/i-7-peccati-capitali-del-recruitment-di-hacker/" description="Stacktrace.it: I 7 peccati capitali del recruitment di hacker" hash="2ebd5cea7e3ab24f967c07994703bb4b" others="1" tag="recruitment" time="2008-03-12T08:41:19Z" shared="no" />
@@ -0,0 +1 @@
1
+ <tag count="1" tag="activedesktop" />
@@ -0,0 +1,5 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <bundles>
3
+ <bundle name="music" tags="ipod mp3 music" />
4
+ <bundle name="pc" tags="computer software hardware" />
5
+ </bundles>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <bundles></bundles>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <result>done</result>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <result>ok</result>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <result>you must supply a bundle name and at least one tag</result>
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' standalone='yes'?>
2
+ <result code="done" />
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <posts user="weppos" update="2008-08-02T11:55:35Z" tag="" total="1702">
3
+ <post href="http://github.com/blog/120-new-to-git" hash="eca1f8a028417349f71077adf64faee8" description="New to Git? - GitHub" tag="scm git" time="2008-07-31T15:44:54Z" others="-1" extended=""/>
4
+ <post href="http://arthurkoziel.com/2008/05/02/git-configuration/" hash="fd68cebf1efc8267755fffdf83d34a65" description="Git Configuration - Arthur Koziel’s Blog" tag="scm git" time="2008-07-31T15:44:19Z" others="-1" extended="Here are some useful configuration options for Git."/>
5
+ <post href="http://whytheluckystiff.net/articles/theFullyUpturnedBin.html" hash="02ae7e6473e6ad87d6d5a8fc254dd274" description=".c( whytheluckystiff )o. -- The Fully Upturned Bin" tag="programming ruby garbagecollection" time="2008-07-31T13:09:26Z" others="-1" extended="About memory management and Garbage Collection in Ruby."/>
6
+ <post href="http://www.learnasp.com/learn/subgetrows.asp" hash="14f798447ad0e8b3f98d6c89773ce345" description="dbtable" tag="programming asp vbscript database" time="2008-07-29T19:29:38Z" others="-1" extended=""/>
7
+ <post href="http://www.xmlfiles.com/articles/seth/xmldatatransfer/default.asp" hash="e3dfcc0f5cf9ce519783b7a9b1904998" description="XML Files - An ASP Class for XML Data Transfer" tag="programming asp vbscript classes xml" time="2008-07-29T19:29:17Z" others="-1" extended=""/>
8
+ <post href="http://aspalliance.com/113" hash="0919ac3a92f0ded1df657459b5e899d7" description="Database Class in Classic ASP: ASP Alliance" tag="programming asp vbscript classes database" time="2008-07-29T19:28:46Z" others="-1" extended=""/>
9
+ <post href="http://www.devguru.com/technologies/vbscript/quickref/classstatement.html" hash="f03f96952bc57d0bb928a174dd47b60c" description="DevGuru VBScript Statement: Class" tag="programming asp vbscript classes" time="2008-07-29T19:28:30Z" others="-1" extended=""/>
10
+ <post href="http://www.asp101.com/articles/richard/ooasp/default.asp" hash="27e4d04e916fa6128c8e75dbf0ee8ab4" description="ASP 101 - Object Oriented ASP: Using Classes in Classic ASP" tag="programming asp vbscript classes" time="2008-07-29T19:28:11Z" others="-1" extended=""/>
11
+ </posts>
12
+ <!-- fe04.api.del.ac4.yahoo.net uncompressed/chunked Sat Aug 2 13:59:59 PDT 2008 -->
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <dates tag="" user="weppos">
3
+ <date count="3" date="2008-07-31"/>
4
+ <date count="6" date="2008-07-29"/>
5
+ <date count="5" date="2008-07-27"/>
6
+ <date count="1" date="2008-07-25"/>
7
+ <date count="1" date="2008-07-22"/>
8
+ <date count="2" date="2008-07-20"/>
9
+ <date count="3" date="2008-07-19"/>
10
+ <date count="1" date="2008-07-16"/>
11
+ <date count="1" date="2008-07-15"/>
12
+ <date count="2" date="2008-07-14"/>
13
+ </dates>
14
+ <!-- fe02.api.del.ac4.yahoo.net uncompressed/chunked Sat Aug 2 13:39:33 PDT 2008 -->