yummy 0.0.1

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.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.0.1 / 2007-04-29
2
+
3
+ * proof of concept
4
+ * Birthday!
5
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/yummy
6
+ lib/yummy.rb
7
+ test/test_yummy.rb
data/README.txt ADDED
@@ -0,0 +1,53 @@
1
+ yummy
2
+ by Bryan Liles (bryan@osesm.com)
3
+ http://smartic.us
4
+
5
+ == DESCRIPTION:
6
+
7
+ Yummy is a ruby implementation of the del.icio.us API
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * No very feature complete :)
12
+
13
+ == SYNOPSIS:
14
+
15
+ require 'rubygems'
16
+ require 'yummy'
17
+
18
+ # find all posts with a todemo tag
19
+ yummy = Smarticus::Yummy.new(:user => "test", :password => "pass")
20
+ p yummy.posts(:tag => "todemo").map{|p| p.tag}
21
+
22
+ == REQUIREMENTS:
23
+
24
+ * None
25
+
26
+ == INSTALL:
27
+
28
+ * sudo gem install yummy
29
+
30
+ == LICENSE:
31
+
32
+ (The MIT License)
33
+
34
+ Copyright (c) 2007 Bryan Liles <bryan@osesm.com>
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ 'Software'), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
51
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/yummy.rb'
6
+
7
+ Hoe.new('yummy', Smarticus::Yummy::VERSION) do |p|
8
+ p.rubyforge_name = 'smarticus'
9
+ # p.summary = 'FIX'
10
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
11
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ end
14
+
15
+ # vim: syntax=Ruby
data/bin/yummy ADDED
File without changes
data/lib/yummy.rb ADDED
@@ -0,0 +1,93 @@
1
+ # Copyright (c) 2007 Bryan Liles <bryan@osesm.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'net/https'
22
+ require 'rexml/document'
23
+ require 'ostruct'
24
+
25
+ module Smarticus
26
+
27
+ USER_AGENT = "Yummy"
28
+
29
+ class Yummy
30
+ VERSION = "0.0.1"
31
+
32
+ def initialize(options)
33
+ raise "need user and password" if !options[:user] || !options[:password]
34
+ @connection = DeliciousConnection.new(options[:user], options[:password])
35
+ end
36
+
37
+ def posts(options={})
38
+ response = @connection.get(options)
39
+ doc = REXML::Document.new(response)
40
+
41
+ collected_posts = []
42
+
43
+ # iterate over each element <tag count="200" tag="Rails"/>
44
+ doc.root.elements.each do |element|
45
+ record = OpenStruct.new
46
+ record.send("href=", element.attributes['href'])
47
+ record.send("description=", element.attributes['description'])
48
+ record.send("extended=", element.attributes['extended'])
49
+ record.send("hash=", element.attributes['hash'])
50
+ record.send("others=", element.attributes['others'])
51
+ record.send("tag=", element.attributes['tag'])
52
+ record.send("time=", element.attributes['time'])
53
+ collected_posts << record
54
+ end
55
+
56
+ collected_posts
57
+ end
58
+
59
+ end
60
+
61
+ class DeliciousConnection
62
+ def initialize(user,pass)
63
+ @user = user
64
+ @pass = pass
65
+
66
+ @http = Net::HTTP.new("api.del.icio.us", 443)
67
+ @http.use_ssl = true
68
+ end
69
+
70
+ def get(options={})
71
+ body = ""
72
+ params = parameterize_hash(options)
73
+ path = "/v1/posts/get?" + params
74
+
75
+ @http.start do |http|
76
+ request = Net::HTTP::Get.new(path, {"User-Agent" => Smarticus::USER_AGENT})
77
+ request.basic_auth(@user, @pass)
78
+ response = @http.request(request)
79
+ body = response.body
80
+ end
81
+
82
+ body
83
+ end
84
+
85
+ private
86
+
87
+ def parameterize_hash(options)
88
+ get_path = ""
89
+ options.each_pair{|x,y| get_path+="&" unless get_path.empty? ; get_path+="#{x}=#{y}"}
90
+ get_path
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,68 @@
1
+ require "test/unit"
2
+ require 'rubygems'
3
+ require 'mocha'
4
+
5
+ require "yummy"
6
+
7
+ class TestYummy < Test::Unit::TestCase
8
+
9
+ # connection tests
10
+ def test_should_require_user_and_password
11
+ assert_raise(RuntimeError) { Smarticus::Yummy.new :user => "test" }
12
+ assert_raise(RuntimeError) { Smarticus::Yummy.new :password => "blah" }
13
+ end
14
+
15
+ def test_should_connect_with_supplied_user_password
16
+ assert_equal Smarticus::Yummy, new_yummy.class
17
+ end
18
+
19
+ # operation tests
20
+ def test_single_post_count
21
+ options = {:tag => "webdev"}
22
+ yummy = new_yummy
23
+ @connection.stubs(:get).returns(single_post_response)
24
+ assert_equal 1, yummy.posts(options).size
25
+ end
26
+
27
+ def test_multiple_post_count
28
+ options = {:tag => "webdev"}
29
+ yummy = new_yummy
30
+ @connection.stubs(:get).returns(multiple_post_response)
31
+ assert_equal 2, yummy.posts(options).size
32
+ end
33
+
34
+ private
35
+
36
+ def new_yummy
37
+ options = {:user => "test", :password => "test"}
38
+ @connection = mock("connection")
39
+ Smarticus::DeliciousConnection.expects(:new).with(options[:user], options[:password]).returns(@connection)
40
+ Smarticus::Yummy.new(options)
41
+ end
42
+
43
+ def single_post_response
44
+ str = <<POST
45
+ <posts dt="2005-11-28" tag="webdev" user="user">
46
+ <post href="http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1"
47
+ description="JavaScript DOM reference"
48
+ extended="dom reference"
49
+ hash="c0238dc0c44f07daedd9a1fd9bbdeebd"
50
+ others="55" tag="dom javascript webdev" time="2005-11-28T05:26:09Z" />
51
+ </posts>
52
+ POST
53
+ end
54
+
55
+ def multiple_post_response
56
+ str = <<POST
57
+ <posts tag="" user="user">
58
+ <post href="http://www.weather.com/" description="weather.com"
59
+ hash="6cfedbe75f413c56b6ce79e6fa102aba" tag="weather reference"
60
+ time="2005-11-29T20:30:47Z" />
61
+ <post href="http://www.nytimes.com/"
62
+ description="The New York Times - Breaking News, World News & Multimedia"
63
+ extended="requires login" hash="ca1e6357399774951eed4628d69eb84b"
64
+ tag="news media" time="2005-11-29T20:30:05Z" />
65
+ </posts>
66
+ POST
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: yummy
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-05-08 00:00:00 -04:00
8
+ summary: The author was too lazy to write a summary
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: http://www.zenspider.com/ZSS/Products/yummy/
13
+ rubyforge_project: smarticus
14
+ description: The author was too lazy to write a description
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
+ - Ryan Davis
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/yummy
37
+ - lib/yummy.rb
38
+ - test/test_yummy.rb
39
+ test_files:
40
+ - test/test_yummy.rb
41
+ rdoc_options: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ executables:
46
+ - yummy
47
+ extensions: []
48
+
49
+ requirements: []
50
+
51
+ dependencies:
52
+ - !ruby/object:Gem::Dependency
53
+ name: hoe
54
+ version_requirement:
55
+ version_requirements: !ruby/object:Gem::Version::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.2.0
60
+ version: