rubycious 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ config/auth.yml
5
+ lib/client_helper.rb
6
+ lib/rubycious.rb
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Rubycious
2
+
3
+ A Ruby gem wrapper to the del.icio.us API. nuff' said.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rubycious', '0.1.0') do |p|
6
+ p.description = "Ruby wrapper to the del.icio.us API"
7
+ p.url = "http://github.com/rjsvlajean/rubycious"
8
+ p.author = "Ratan Sebastian"
9
+ p.email = "rjsvaljean@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/config/auth.yml ADDED
@@ -0,0 +1,2 @@
1
+ username: arjayes
2
+ password: ./haq764
@@ -0,0 +1,40 @@
1
+ module ClientHelper
2
+ def self.included(base)
3
+ base.class_eval do
4
+ include HTTParty
5
+ include Rubycious::Errors
6
+
7
+ base_uri "https://api.del.icio.us/v1"
8
+ basic_auth base.new.username, base.new.password
9
+ format :xml
10
+
11
+ def initialize(auth_options = {:username => nil, :password => nil})
12
+ @username, @password= auth_options[:username], auth_options[:password]
13
+ end
14
+ end
15
+ end
16
+
17
+ def config
18
+ @config= YAML::load(File.read(File.join(ROOT_DIR,'config','auth.yml')))
19
+ end
20
+
21
+ def username
22
+ if username = self.instance_variable_get('@username') || config["username"]
23
+ instance_variable_set('@username', username)
24
+ username
25
+ else
26
+ raise AuthenticationError, "Couldn't find username"
27
+ end
28
+ end
29
+
30
+ def password
31
+ if password = self.instance_variable_get('@username') || config["password"]
32
+ instance_variable_set('@password', password)
33
+ password
34
+ else
35
+ raise AuthenticationError, "Couldn't find password"
36
+ end
37
+ end
38
+
39
+ end
40
+
data/lib/rubycious.rb ADDED
@@ -0,0 +1,200 @@
1
+ require 'httparty'
2
+
3
+ ROOT_DIR= File.join(File.dirname(__FILE__),'..')
4
+ # load File.join(ROOT_DIR, 'lib', 'errors.rb')
5
+ load File.join(ROOT_DIR, 'lib', 'client_helper.rb')
6
+ # load File.join(ROOT_DIR, 'lib', 'client.rb')
7
+
8
+ module Rubycious
9
+
10
+
11
+ module Errors
12
+
13
+ class DeliciousError < StandardError
14
+ end
15
+
16
+ class AuthenticationError < StandardError
17
+ end
18
+
19
+ def handle_errors
20
+ response= yield
21
+ if response.keys.include?("result")
22
+ if response["result"].match("done")
23
+ response
24
+ else
25
+ raise DeliciousError, response["result"]["code"]
26
+ end
27
+ else
28
+ response
29
+ end
30
+ end
31
+ end
32
+
33
+ module Client
34
+ def self.last_update
35
+ response= self.new.handle_errors do
36
+ get('/posts/update')
37
+ end
38
+ Time.parse(response["update"]["time"])
39
+ end
40
+
41
+ class Post
42
+ include ClientHelper
43
+
44
+ base_uri "#{base_uri}/posts"
45
+
46
+ # Options
47
+ # :url => (required) http://somelink.com/somepage
48
+ # :description => (required) This is a really cool link that I found
49
+ # :dt => (optional) CCYY-MM-DDThh:mm:ssZ filter by date
50
+ # :hash => (optional) MD5+MD5+....+MD5 Fetch multiple bookmarks by one or more URL MD5s regardless of date, separated by URL-encoded spaces (ie. '+').
51
+ # :extended => (optional) This is some further information about the link
52
+ # :tags => (optional) space seporated list of tags
53
+ # :replace => (optional) yes/no
54
+ # :shared => (optional) yes/no
55
+ def save
56
+ handle_errors { self.class.get('/add', :query => @options) }
57
+ end
58
+
59
+ # Options:
60
+ # :tag => "ruby+rails+httparty"
61
+ # :dt => CCYY-MM-DDThh:mm:ssZ
62
+ # :url => URL
63
+ # :hashes => "c0238dc0c44f07daedd9a1fd9bbdeebd+2f9704c729e7ed3b41647b7d0ad649fe+..+2f9704c729e7ed3b41647b7d0ad649fe"
64
+ # :meta => yes/no to indicate whether or not to retreive the meta hash tag
65
+ # METHOD DEPRECATED due to uselessness
66
+ def find_latest(options)
67
+ response= handle_errors { self.class.get('/get', :query => options)}
68
+ response["posts"]
69
+ end
70
+
71
+ # Options:
72
+ # :tag =>(optional) "ruby"
73
+ # :start =>(optional) Integer: Start returning posts this many results into the set
74
+ # :results =>(optional) Integer: Return these many results
75
+ # :fromdt =>(optional) {Time#iso8601}: On this date or later
76
+ # :todt =>(optional) {Time#iso8601}: On this date or earlier
77
+ # :meta =>(optional) yes/no: Include change detection signatures on each item in a 'meta' attribute. Clients wishing to maintain a synchronized local store of bookmarks should retain the value of this attribute - its value will change when any significant field of the bookmark changes.
78
+ # NOTE: Use Sparingly. Call the update function to see if you need to fetch this at all.
79
+ def find(options)
80
+ response= handle_errors { self.class.get('/all', :query => options)}
81
+ response["posts"]["post"].collect{|i| Rubycious::Post.new(i)}
82
+ end
83
+
84
+ # Options:
85
+ # :tag => (optional) "httparty"
86
+ # :count => (optional) Integer // Default: 15 Max: 100
87
+ def recent(options = nil)
88
+ response= handle_errors { self.class.get('/recent', :query => options)}
89
+ response["posts"]["post"].collect{|i| Rubycious::Post.new(i)}
90
+ end
91
+
92
+ # Options:
93
+ # :tag => (optional) "tutorial"
94
+ def dates(options = nil)
95
+ response= handle_errors{ self.class.get('/dates', :query => options)}
96
+ response["dates"]["date"].collect{|i| Rubycious::PostDate.new(i)}
97
+ end
98
+
99
+ # Options:
100
+ # :url => (required) URL
101
+ def suggest(options)
102
+ response= handle_errors{ self.class.get('/suggest', :query => options)}
103
+ response["suggest"]
104
+ end
105
+ end
106
+
107
+ class Tag
108
+ include ClientHelper
109
+
110
+ base_uri "#{base_uri}/tags"
111
+
112
+ def all
113
+ response= handle_errors{ self.class.get('/get')}
114
+ response["tags"]["tag"].collect do |tag|
115
+ t= Rubycious::Tag.new(tag)
116
+ end
117
+ end
118
+ #Options:
119
+ # :tag => (required)
120
+ def delete(options)
121
+ response= handle_errors{ self.class.get('/delete', :query => options)}
122
+ true if response["result"] == "done"
123
+ end
124
+
125
+ #Options:
126
+ # :old => (required)
127
+ # :new => (required)
128
+ def rename(options)
129
+ response= handle_errors{ self.class.get('/rename', :query => options)}
130
+ true if response["result"] == "done"
131
+ end
132
+ end
133
+
134
+ class Bundles
135
+ include ClientHelper
136
+
137
+ base_uri "#{base_uri}/tags/bundles"
138
+ end
139
+ end
140
+
141
+ class PostDate
142
+ # Attributes:
143
+ # date: Date
144
+ # count: Integer
145
+
146
+ attr_accessor :date, :count
147
+
148
+ def initialize(options)
149
+ @date= Date.parse(options["date"])
150
+ @count= options["count"].to_i
151
+ end
152
+ end
153
+
154
+ class Post
155
+ # Attributes
156
+ # :href => (required) http://somelink.com/somepage
157
+ # :description => (required) This is a really cool link that I found
158
+ # :time => (optional) CCYY-MM-DDThh:mm:ssZ filter by date
159
+ # :hash => (optional) (only for find) MD5+MD5+....+MD5 Fetch multiple bookmarks by one or more URL MD5s regardless of date, separated by URL-encoded spaces (ie. '+').
160
+ # :extended => (optional) This is some further information about the link
161
+ # :tag => (optional) space seporated list of tags
162
+ # :meta => (optional) meta hash
163
+
164
+ def initialize(params = nil)
165
+ @params= params
166
+ @attributes= [:href, :description, :time, :hash, :extended, :tag, :meta]
167
+ end
168
+
169
+ def method_missing(name, *args, &block)
170
+ if @attributes.include?(name)
171
+ if name == :time
172
+ Time.parse(@params[name.to_s])
173
+ else
174
+ @params[name.to_s]
175
+ end
176
+ else
177
+ raise NoMethodError
178
+ end
179
+ end
180
+ end
181
+
182
+ class Tag
183
+ attr_accessor :name, :count
184
+
185
+ def initialize(options = {"tag" => nil})
186
+ @name= options["tag"]
187
+ @count= options["count"]
188
+ end
189
+
190
+ def delete
191
+ client= Rubycious::Client::Tag.new
192
+ client.delete(:tag => @name)
193
+ end
194
+
195
+ def rename(new_name)
196
+ client= Rubycious::Client::Tag.new
197
+ client.rename(:old => @name, :new => new_name)
198
+ end
199
+ end
200
+ end
data/rubycious.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rubycious}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ratan Sebastian"]
9
+ s.date = %q{2010-05-12}
10
+ s.description = %q{Ruby wrapper to the del.icio.us API}
11
+ s.email = %q{rjsvaljean@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/client_helper.rb", "lib/rubycious.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "config/auth.yml", "lib/client_helper.rb", "lib/rubycious.rb", "rubycious.gemspec"]
14
+ s.homepage = %q{http://github.com/rjsvlajean/rubycious}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rubycious", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rubycious}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Ruby wrapper to the del.icio.us API}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubycious
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ratan Sebastian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-12 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby wrapper to the del.icio.us API
17
+ email: rjsvaljean@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - lib/client_helper.rb
25
+ - lib/rubycious.rb
26
+ files:
27
+ - Manifest
28
+ - README.rdoc
29
+ - Rakefile
30
+ - config/auth.yml
31
+ - lib/client_helper.rb
32
+ - lib/rubycious.rb
33
+ - rubycious.gemspec
34
+ has_rdoc: true
35
+ homepage: http://github.com/rjsvlajean/rubycious
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --line-numbers
41
+ - --inline-source
42
+ - --title
43
+ - Rubycious
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "1.2"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: rubycious
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Ruby wrapper to the del.icio.us API
67
+ test_files: []
68
+