markoa-r2flickr 0.1.1 → 0.1.1.4

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/lib/flickr.rb CHANGED
@@ -17,3 +17,4 @@ require 'flickr/upload'
17
17
  require 'flickr/urls'
18
18
  require 'flickr/tags'
19
19
  require 'flickr/interestingness'
20
+ require 'flickr/comments'
data/lib/flickr/auth.rb CHANGED
@@ -1,23 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'flickr/base'
4
+ require 'flickr/token_cache'
4
5
 
5
6
  class Flickr::Auth < Flickr::APIBase
6
- attr_accessor :cache_file, :token
7
+ attr_accessor :token_cache, :token
7
8
 
8
9
  def clear_cache
9
10
  @token = nil
10
11
  @frob = nil
11
12
  end
12
13
 
13
- def initialize(flickr,cache_file=nil)
14
+ def initialize(flickr, token_cache=nil)
14
15
  super(flickr)
15
16
  @frob = nil
16
17
  @token = nil
17
- @cache_file = cache_file
18
- if @cache_file && File.exists?(@cache_file)
19
- load_token
18
+ @token_cache = case token_cache
19
+ when String
20
+ Flickr::FileTokenCache.new token_cache
21
+ else
22
+ token_cache
20
23
  end
24
+ @token = @token_cache.load_token if @token_cache
21
25
  end
22
26
 
23
27
  def login_link(perms='delete')
@@ -31,22 +35,6 @@ class Flickr::Auth < Flickr::APIBase
31
35
  def frob=(frob) @frob = frob end
32
36
  def frob() return @frob || getFrob end
33
37
 
34
- def cache_token
35
- File.open(@cache_file,'w'){ |f| f.write @token.to_xml } if token
36
- end
37
-
38
- def load_token
39
- token = nil
40
- File.open(@cache_file,'r'){ |f| token = f.read }
41
- # Dirt stupid check to see if it's probably XML or
42
- # not. If it is, then we don't call checkToken.
43
- #
44
- # Backwwards compatible with old token storage.
45
- @token = token.include?('<') ?
46
- Flickr::Token.from_xml(REXML::Document.new(token)) :
47
- @token = checkToken(token)
48
- end
49
-
50
38
  def getToken(frob=nil)
51
39
  frob ||= @frob
52
40
  res=@flickr.call_unauth_method('flickr.auth.getToken',
@@ -54,6 +42,10 @@ class Flickr::Auth < Flickr::APIBase
54
42
  @token = Flickr::Token.from_xml(res)
55
43
  end
56
44
 
45
+ def cache_token
46
+ @token_cache.cache_token(@token) if @token_cache
47
+ end
48
+
57
49
  def getFullToken(mini_token)
58
50
  res = flickr.call_unauth_method('flickr.auth.getFullToken',
59
51
  'mini_token' => mini_token)
@@ -66,11 +58,4 @@ class Flickr::Auth < Flickr::APIBase
66
58
  return @frob
67
59
  end
68
60
 
69
- def checkToken(token=nil)
70
- token ||= @token
71
- token = token.token if token.class == Flickr::Token
72
- res = @flickr.call_unauth_method('flickr.auth.checkToken',
73
- 'auth_token' => token)
74
- @token = Flickr::Token.from_xml(res)
75
- end
76
61
  end
data/lib/flickr/base.rb CHANGED
@@ -110,6 +110,7 @@ class Flickr
110
110
  @photosets = nil
111
111
  @test = nil
112
112
  @urls = nil
113
+ @comments = nil
113
114
 
114
115
  @ticket_by_id = {}
115
116
  @person_by_nsid = {}
@@ -133,6 +134,7 @@ class Flickr
133
134
  def test() @test ||= Test.new(self) end
134
135
  def urls() @urls ||= Urls.new(self) end
135
136
  def tags() @tags ||= Tags.new(self) end
137
+ def comments() @comments ||= Comments.new(self) end
136
138
  def interestingness() @interestingness ||= Interestingness.new(self) end
137
139
 
138
140
  def call_method(method,args={})
@@ -791,3 +793,21 @@ class Flickr::PhotoPool < Array
791
793
  return pool
792
794
  end
793
795
  end
796
+
797
+ class Flickr::Comment
798
+ attr_accessor :id, :authorid, :authorname, :datecreated, :permalink, :text
799
+
800
+ def self.from_xml(xml, flickr=nil)
801
+ att = xml.attributes
802
+ c = new
803
+ c.id = att['id']
804
+ c.authorid = att['author']
805
+ c.authorname = att['authorname']
806
+ c.datecreated = Time.at(att['datecreate'].to_i)
807
+ c.permalink = att['permalink']
808
+ c.text = xml.text
809
+ c
810
+ end
811
+
812
+ end
813
+
@@ -0,0 +1,35 @@
1
+ require 'flickr/base'
2
+
3
+ class Flickr::Comments < Flickr::APIBase
4
+
5
+ def add(photo, comment)
6
+ photo = photo.id if photo.class == Flickr::Photo
7
+ res = @flickr.call_method('flickr.photos.comments.addComment',
8
+ 'photo_id' => photo, 'comment_text' => comment)
9
+ xml = res.root
10
+ xml.attributes['id']
11
+ end
12
+
13
+ def delete(comment_id)
14
+ @flickr.call_method('flickr.photos.comments.deleteComment',
15
+ 'comment_id' => comment_id)
16
+ end
17
+
18
+ def edit(comment_id, comment)
19
+ @flickr.call_method('flickr.photos.comments.editComment',
20
+ 'comment_id' => comment_id, 'comment_text' => comment)
21
+ end
22
+
23
+ def list(photo)
24
+ photo = photo.id if photo.class == Flickr::Photo
25
+ res = @flickr.call_method('flickr.photos.comments.getList',
26
+ 'photo_id' => photo)
27
+ rv = []
28
+ res.elements['//comments'].each_element do |e|
29
+ rv << Flickr::Comment.from_xml(e, @flickr)
30
+ end
31
+ rv
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'flickr/base'
2
+
3
+ class Flickr::BaseTokenCache < Flickr::APIBase
4
+
5
+ def load_token
6
+ nil
7
+ end
8
+
9
+ def cache_token(token)
10
+ nil
11
+ end
12
+
13
+ end
14
+
15
+ class Flickr::FileTokenCache < Flickr::BaseTokenCache
16
+
17
+ def initialize(filename)
18
+ @cache_file = filename
19
+ end
20
+
21
+ def load_token
22
+ token = nil
23
+ File.open(@cache_file,'r'){ |f| token = f.read }
24
+ @token = Flickr::Token.from_xml(REXML::Document.new(token))
25
+ rescue Errno::ENOENT
26
+ nil
27
+ end
28
+
29
+ def cache_token(token)
30
+ File.open(@cache_file,'w'){ |f| f.write token.to_xml } if token
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markoa-r2flickr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marko Anastasov
@@ -40,9 +40,11 @@ files:
40
40
  - lib/flickr/reflection.rb
41
41
  - lib/flickr/tags.rb
42
42
  - lib/flickr/test.rb
43
+ - lib/flickr/token_cache.rb
43
44
  - lib/flickr/transform.rb
44
45
  - lib/flickr/upload.rb
45
46
  - lib/flickr/urls.rb
47
+ - lib/flickr/comments.rb
46
48
  - lib/flickr.rb
47
49
  - examples/album_test.rb
48
50
  - examples/comics-reorder.rb