mirrored 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ 0.1.6
2
+ * added require 'time'
3
+
1
4
  0.1.5
2
5
  * tweaked destroy and save to be a little less brittle
3
6
 
@@ -16,6 +16,7 @@ end
16
16
 
17
17
  require 'rubygems'
18
18
  require 'hpricot'
19
+ require 'time'
19
20
 
20
21
  require 'mirrored/base'
21
22
  require 'mirrored/connection'
@@ -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
- class << self
10
- # Sets up the login information for either magnolia or delicious.
11
- #
12
- # Usage:
13
- # Mirrored::Base.establish_connection(:delicious, 'jnunemaker', 'password')
14
- # Mirrored::Base.establish_connection(:magnolia, 'jnunemaker', 'password')
15
- def establish_connection(s, u, p)
16
- remove_connection
17
- raise InvalidService unless valid_service?(s)
18
- @@service = s
19
- @@connection = Connection.new(api_url, :username => u, :password => p)
20
- end
21
-
22
- # Removes the current connection information
23
- def remove_connection
24
- @@service, @@connection = nil, nil
25
- end
26
-
27
- def valid_service?(s) #:nodoc:
28
- s = s.nil? ? '' : s
29
- API_URL.keys.include?(s)
30
- end
31
-
32
- def api_url
33
- API_URL[@@service]
34
- end
35
-
36
- def service
37
- @@service
38
- end
39
-
40
- def connection
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
@@ -1,28 +1,26 @@
1
1
  module Mirrored
2
2
  class Date < Base
3
- attr_accessor :count, :date
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
- class << self
6
- def new_from_xml(xml) #:nodoc:
7
- d = Date.new
8
- d.date = ::Date.parse((xml)['date'])
9
- d.count = (xml)['count']
10
- d
11
- end
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
- # Does all the hard work finding the dates you have posted and how many posts on those days.
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
@@ -1,79 +1,77 @@
1
1
  module Mirrored
2
2
  class Post < Base
3
- attr_accessor :href, :description, :extended, :hash, :others, :tags, :time, :code, :share
4
-
5
- alias :url :href
6
- alias :url= :href=
7
- alias :dt :time
8
- alias :dt= :time=
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
- class << self
11
- # Creates a new post from an hpricot post instance.
12
- def new_from_xml(xml) #:nodoc:
13
- p = Post.new
14
- p.href = (xml)['href']
15
- p.description = (xml)['description']
16
- p.extended = (xml)['extended']
17
- p.hash = (xml)['hash']
18
- p.others = (xml)['others']
19
- p.tags = (xml)['tag']
20
- p.time = Time.parse((xml)['time'])
21
- p
22
- end
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
- # Does all the hard work finding your posts by various filters and such.
25
- #
26
- # Usage:
27
- #
28
- # Valid hash options for :get are :tag, :dt and :url. All are optional and can be used in any combination.
29
- # Mirrored::Post.find(:get) # => posts
30
- # Mirrored::Post.find(:get, :tag => 'ruby') # => posts tagged ruby
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
- # Destroys a post by url.
62
- #
63
- # Usage:
64
- # Mirrored::Post.destroy('http://microsoft.com')
65
- # Mirrored::Post.delete('http://microsoft.com') # => aliased version
66
- def destroy(url)
67
- doc = Hpricot::XML(connection.get('posts/delete', :url => url))
68
- if doc && doc.at('result')
69
- code = doc.at('result')['code']
70
- code == 'done' ? true : false
71
- else
72
- false
73
- end
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
  #
@@ -1,34 +1,32 @@
1
1
  module Mirrored
2
2
  class Tag < Base
3
- attr_accessor :count, :name
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
- class << self
6
- def new_from_xml(xml) #:nodoc:
7
- t = Tag.new
8
- t.count = (xml)['count']
9
- t.name = (xml)['tag']
10
- t
11
- end
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
@@ -1,16 +1,14 @@
1
1
  module Mirrored
2
2
  class Update < Base
3
- class << self
4
- # 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).
5
- #
6
- # Usage:
7
- # Mirrored::Update.last # => a ruby time object in UTC
8
- def last
9
- result = connection.get('posts/update')
10
- doc = Hpricot::XML(result)
11
- update = doc.at('update')
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
@@ -2,7 +2,7 @@ module Mirrored #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
File without changes
File without changes
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
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: 2008-02-07 00:00:00 -05:00
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: 0.9.5
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