mirrored 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/lib/mirrored.rb +1 -0
- data/lib/mirrored/base.rb +32 -34
- data/lib/mirrored/date.rb +19 -21
- data/lib/mirrored/post.rb +66 -68
- data/lib/mirrored/tag.rb +26 -28
- data/lib/mirrored/update.rb +9 -11
- data/lib/mirrored/version.rb +1 -1
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- metadata +15 -4
data/History.txt
CHANGED
data/lib/mirrored.rb
CHANGED
data/lib/mirrored/base.rb
CHANGED
@@ -6,40 +6,38 @@ module Mirrored
|
|
6
6
|
API_URL = {:delicious => 'https://api.del.icio.us/v1/', :magnolia => 'https://ma.gnolia.com/api/mirrord/v1/'}
|
7
7
|
|
8
8
|
class Base
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@@connection
|
42
|
-
end
|
9
|
+
# Sets up the login information for either magnolia or delicious.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# Mirrored::Base.establish_connection(:delicious, 'jnunemaker', 'password')
|
13
|
+
# Mirrored::Base.establish_connection(:magnolia, 'jnunemaker', 'password')
|
14
|
+
def self.establish_connection(s, u, p)
|
15
|
+
remove_connection
|
16
|
+
raise InvalidService unless valid_service?(s)
|
17
|
+
@@service = s
|
18
|
+
@@connection = Connection.new(api_url, :username => u, :password => p)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Removes the current connection information
|
22
|
+
def self.remove_connection
|
23
|
+
@@service, @@connection = nil, nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.valid_service?(s) #:nodoc:
|
27
|
+
s = s.nil? ? '' : s
|
28
|
+
API_URL.keys.include?(s)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.api_url
|
32
|
+
API_URL[@@service]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.service
|
36
|
+
@@service
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.connection
|
40
|
+
@@connection
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
data/lib/mirrored/date.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
module Mirrored
|
2
2
|
class Date < Base
|
3
|
-
|
3
|
+
def self.new_from_xml(xml) #:nodoc:
|
4
|
+
d = Date.new
|
5
|
+
d.date = ::Date.parse((xml)['date'])
|
6
|
+
d.count = (xml)['count']
|
7
|
+
d
|
8
|
+
end
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
# Does all the hard work finding the dates you have posted and how many posts on those days.
|
11
|
+
#
|
12
|
+
# Usage:
|
13
|
+
# Mirrored::Date.find(:all) # => finds all dates you have posted with counts for each day
|
14
|
+
# Mirrored::Date.find(:all, :tag => 'ruby') # => finds all dates you have posted something tagged ruby with counts for each day
|
15
|
+
def self.find(*args)
|
16
|
+
raise ArgumentError, "First argument must be symbol (:all)" unless args.first.kind_of?(Symbol)
|
17
|
+
params = args.extract_options!
|
18
|
+
params = params == {} ? nil : params
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
# Usage:
|
16
|
-
# Mirrored::Date.find(:all) # => finds all dates you have posted with counts for each day
|
17
|
-
# Mirrored::Date.find(:all, :tag => 'ruby') # => finds all dates you have posted something tagged ruby with counts for each day
|
18
|
-
def find(*args)
|
19
|
-
raise ArgumentError, "First argument must be symbol (:all)" unless args.first.kind_of?(Symbol)
|
20
|
-
params = args.extract_options!
|
21
|
-
params = params == {} ? nil : params
|
22
|
-
|
23
|
-
doc = Hpricot::XML(connection.get("posts/dates", params))
|
24
|
-
(doc/:date).inject([]) { |elements, el| elements << new_from_xml(el); elements }
|
25
|
-
end
|
20
|
+
doc = Hpricot::XML(connection.get("posts/dates", params))
|
21
|
+
(doc/:date).inject([]) { |elements, el| elements << new_from_xml(el); elements }
|
26
22
|
end
|
23
|
+
|
24
|
+
attr_accessor :count, :date
|
27
25
|
end
|
28
26
|
end
|
data/lib/mirrored/post.rb
CHANGED
@@ -1,79 +1,77 @@
|
|
1
1
|
module Mirrored
|
2
2
|
class Post < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# Creates a new post from an hpricot post instance.
|
4
|
+
def self.new_from_xml(xml) #:nodoc:
|
5
|
+
p = Post.new
|
6
|
+
p.href = (xml)['href']
|
7
|
+
p.description = (xml)['description']
|
8
|
+
p.extended = (xml)['extended']
|
9
|
+
p.hash = (xml)['hash']
|
10
|
+
p.others = (xml)['others']
|
11
|
+
p.tags = (xml)['tag']
|
12
|
+
p.time = Time.parse((xml)['time'])
|
13
|
+
p
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Does all the hard work finding your posts by various filters and such.
|
17
|
+
#
|
18
|
+
# Usage:
|
19
|
+
#
|
20
|
+
# Valid hash options for :get are :tag, :dt and :url. All are optional and can be used in any combination.
|
21
|
+
# Mirrored::Post.find(:get) # => posts
|
22
|
+
# Mirrored::Post.find(:get, :tag => 'ruby') # => posts tagged ruby
|
23
|
+
# Mirrored::Post.find(:get, :tag => 'ruby', :dt => '2007-10-05')# => posts tagged ruby on oct. 5, 2007
|
24
|
+
# Mirrored::Post.find(:get, :url => 'http://addictedtonew') # => posts with url http://addictedtonew
|
25
|
+
#
|
26
|
+
# Valid hash option for :all is :tag. All are optional and can be used in any combination.
|
27
|
+
# Use sparingly according to magnolia and delicious.
|
28
|
+
# Mirrored::Post.find(:all) # => all posts
|
29
|
+
# Mirrored::Post.find(:all, :tag => 'ruby') # => all posts for tag ruby
|
30
|
+
#
|
31
|
+
# Valid hash options for :recent are :tag and :count. All are optional and can be used in any combination.
|
32
|
+
# Mirrored::Post.find(:recent) # most recent posts
|
33
|
+
# Mirrored::Post.find(:recent, :tag => 'ruby') # => most recent posts for tag ruby
|
34
|
+
# Mirrored::Post.find(:recent, :tag => 'ruby', :count => '5') # => 5 most recent posts for tag ruby
|
35
|
+
def self.find(*args)
|
36
|
+
raise ArgumentError, "First argument must be symbol (:all or :recent)" unless args.first.kind_of?(Symbol)
|
37
|
+
params = args.extract_options!
|
38
|
+
params = params == {} ? nil : params
|
23
39
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# Mirrored::Post.find(:get, :tag => 'ruby', :dt => '2007-10-05')# => posts tagged ruby on oct. 5, 2007
|
32
|
-
# Mirrored::Post.find(:get, :url => 'http://addictedtonew') # => posts with url http://addictedtonew
|
33
|
-
#
|
34
|
-
# Valid hash option for :all is :tag. All are optional and can be used in any combination.
|
35
|
-
# Use sparingly according to magnolia and delicious.
|
36
|
-
# Mirrored::Post.find(:all) # => all posts
|
37
|
-
# Mirrored::Post.find(:all, :tag => 'ruby') # => all posts for tag ruby
|
38
|
-
#
|
39
|
-
# Valid hash options for :recent are :tag and :count. All are optional and can be used in any combination.
|
40
|
-
# Mirrored::Post.find(:recent) # most recent posts
|
41
|
-
# Mirrored::Post.find(:recent, :tag => 'ruby') # => most recent posts for tag ruby
|
42
|
-
# Mirrored::Post.find(:recent, :tag => 'ruby', :count => '5') # => 5 most recent posts for tag ruby
|
43
|
-
def find(*args)
|
44
|
-
raise ArgumentError, "First argument must be symbol (:all or :recent)" unless args.first.kind_of?(Symbol)
|
45
|
-
params = args.extract_options!
|
46
|
-
params = params == {} ? nil : params
|
47
|
-
|
48
|
-
filter = case args.first
|
49
|
-
when :recent
|
50
|
-
'recent'
|
51
|
-
when :all
|
52
|
-
'all'
|
53
|
-
else
|
54
|
-
'get'
|
55
|
-
end
|
56
|
-
|
57
|
-
doc = Hpricot::XML(connection.get("posts/#{filter}", params))
|
58
|
-
(doc/:post).inject([]) { |elements, el| elements << Post.new_from_xml(el); elements }
|
40
|
+
filter = case args.first
|
41
|
+
when :recent
|
42
|
+
'recent'
|
43
|
+
when :all
|
44
|
+
'all'
|
45
|
+
else
|
46
|
+
'get'
|
59
47
|
end
|
60
48
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
49
|
+
doc = Hpricot::XML(connection.get("posts/#{filter}", params))
|
50
|
+
(doc/:post).inject([]) { |elements, el| elements << Post.new_from_xml(el); elements }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Destroys a post by url.
|
54
|
+
#
|
55
|
+
# Usage:
|
56
|
+
# Mirrored::Post.destroy('http://microsoft.com')
|
57
|
+
# Mirrored::Post.delete('http://microsoft.com') # => aliased version
|
58
|
+
def self.destroy(url)
|
59
|
+
doc = Hpricot::XML(connection.get('posts/delete', :url => url))
|
60
|
+
if doc && doc.at('result')
|
61
|
+
code = doc.at('result')['code']
|
62
|
+
code == 'done' ? true : false
|
63
|
+
else
|
64
|
+
false
|
74
65
|
end
|
75
|
-
alias :delete :destroy
|
76
66
|
end
|
67
|
+
class << self; alias :delete :destroy end
|
68
|
+
|
69
|
+
attr_accessor :href, :description, :extended, :hash, :others, :tags, :time, :code, :share
|
70
|
+
|
71
|
+
alias :url :href
|
72
|
+
alias :url= :href=
|
73
|
+
alias :dt :time
|
74
|
+
alias :dt= :time=
|
77
75
|
|
78
76
|
# Saves a post to delicious or magnolia.
|
79
77
|
#
|
data/lib/mirrored/tag.rb
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
module Mirrored
|
2
2
|
class Tag < Base
|
3
|
-
|
3
|
+
def self.new_from_xml(xml) #:nodoc:
|
4
|
+
t = Tag.new
|
5
|
+
t.count = (xml)['count']
|
6
|
+
t.name = (xml)['tag']
|
7
|
+
t
|
8
|
+
end
|
9
|
+
|
10
|
+
# Does all the hard work finding your tags and how much you've used them.
|
11
|
+
#
|
12
|
+
# Usage:
|
13
|
+
# Mirrored::Tag.find(:get)
|
14
|
+
def self.find(*args)
|
15
|
+
raise ArgumentError, "Only takes a symbol as the argument (:get, :all)" unless args.first.kind_of?(Symbol)
|
16
|
+
doc = Hpricot::XML(connection.get('tags/get'))
|
17
|
+
(doc/:tag).inject([]) { |elements, el| elements << Tag.new_from_xml(el); elements }
|
18
|
+
end
|
4
19
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# Does all the hard work finding your tags and how much you've used them.
|
14
|
-
#
|
15
|
-
# Usage:
|
16
|
-
# Mirrored::Tag.find(:get)
|
17
|
-
def find(*args)
|
18
|
-
raise ArgumentError, "Only takes a symbol as the argument (:get, :all)" unless args.first.kind_of?(Symbol)
|
19
|
-
doc = Hpricot::XML(connection.get('tags/get'))
|
20
|
-
(doc/:tag).inject([]) { |elements, el| elements << Tag.new_from_xml(el); elements }
|
21
|
-
end
|
22
|
-
|
23
|
-
# Renames a tag from the old name to a new one.
|
24
|
-
#
|
25
|
-
# Usage:
|
26
|
-
# Mirrored::Tag.rename('microsoft', 'suckfest')
|
27
|
-
def rename(old_name, new_name)
|
28
|
-
doc = Hpricot::XML(connection.get('tags/rename', :old => old_name, :new => new_name))
|
29
|
-
result = (doc).at(:result)
|
30
|
-
(result && result.inner_html == 'done') ? true : false
|
31
|
-
end
|
20
|
+
# Renames a tag from the old name to a new one.
|
21
|
+
#
|
22
|
+
# Usage:
|
23
|
+
# Mirrored::Tag.rename('microsoft', 'suckfest')
|
24
|
+
def self.rename(old_name, new_name)
|
25
|
+
doc = Hpricot::XML(connection.get('tags/rename', :old => old_name, :new => new_name))
|
26
|
+
result = (doc).at(:result)
|
27
|
+
(result && result.inner_html == 'done') ? true : false
|
32
28
|
end
|
29
|
+
|
30
|
+
attr_accessor :count, :name
|
33
31
|
end
|
34
32
|
end
|
data/lib/mirrored/update.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
module Mirrored
|
2
2
|
class Update < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
update ? Time.parse(update['time']) : ''
|
13
|
-
end
|
3
|
+
# Returns a ruby time object that is equal to the last time you posted something. If you haven't posted anything it returns an empty string (probably).
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# Mirrored::Update.last # => a ruby time object in UTC
|
7
|
+
def self.last
|
8
|
+
result = connection.get('posts/update')
|
9
|
+
doc = Hpricot::XML(result)
|
10
|
+
update = doc.at('update')
|
11
|
+
update ? Time.parse(update['time']) : ''
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
data/lib/mirrored/version.rb
CHANGED
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mirrored
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
platform:
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-05-11 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hpricot
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -21,6 +22,16 @@ dependencies:
|
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: "0.5"
|
23
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
24
35
|
description: Wrapper for delicious and magnolia mirrored apis
|
25
36
|
email: nunemaker@gmail.com
|
26
37
|
executables: []
|
@@ -102,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
113
|
requirements: []
|
103
114
|
|
104
115
|
rubyforge_project: mirrored
|
105
|
-
rubygems_version:
|
116
|
+
rubygems_version: 1.3.1
|
106
117
|
signing_key:
|
107
118
|
specification_version: 2
|
108
119
|
summary: Wrapper for delicious and magnolia mirrored apis
|