dustin-r2flickr 0.1.1.6 → 0.1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,104 +1,102 @@
1
1
  require 'flickr/base'
2
2
 
3
3
  class Flickr::PhotoSets < Flickr::APIBase
4
- # photoset can be a PhotoSet or a a photoset id
5
- # photo can be a Photo or a photo id
6
- def addPhoto(photoset,photo)
7
- photo = photo.id if photo.class == Flickr::Photo
8
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
4
+ # photoset can be a PhotoSet or a a photoset id
5
+ # photo can be a Photo or a photo id
6
+ def addPhoto(photoset,photo)
7
+ photo = photo.id if photo.class == Flickr::Photo
8
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
9
9
 
10
- @flickr.call_method('flickr.photosets.addPhoto',
11
- 'photoset_id' => photoset, 'photo_id' => photo)
12
- end
10
+ @flickr.call_method('flickr.photosets.addPhoto',
11
+ 'photoset_id' => photoset, 'photo_id' => photo)
12
+ end
13
13
 
14
- def create(title,primary_photo, description = nil)
15
- primary_photo = primary_photo.id if
16
- primary_photo.class == Flickr::Photo
17
- args = { 'title' => title, 'primary_photo_id' =>
18
- primary_photo}
19
- args['description'] = description if description
20
- res = @flickr.call_method('flickr.photosets.create',args)
21
- id = res.elements['/photoset'].attributes['id']
22
- url = res.elements['/photoset'].attributes['url']
23
- set = Flickr::PhotoSet.new(id,@flickr)
24
- set.title = title
25
- set.url = url
26
- @flickr.photoset_cache_store(set)
27
- return set
28
- end
14
+ def create(title,primary_photo, description = nil)
15
+ primary_photo = primary_photo.id if
16
+ primary_photo.class == Flickr::Photo
17
+ args = { 'title' => title, 'primary_photo_id' => primary_photo }
18
+ args['description'] = description if description
19
+ res = @flickr.call_method('flickr.photosets.create',args)
20
+ id = res.elements['/photoset'].attributes['id']
21
+ url = res.elements['/photoset'].attributes['url']
22
+ set = Flickr::PhotoSet.new(id,@flickr)
23
+ set.title = title
24
+ set.url = url
25
+ @flickr.photoset_cache_store(set)
26
+ return set
27
+ end
29
28
 
30
- def delete(photoset)
31
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
32
- @flickr.call_method('flickr.photosets.delete',
33
- 'photoset_id' => photoset)
34
- end
29
+ def delete(photoset)
30
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
31
+ @flickr.call_method('flickr.photosets.delete',
32
+ 'photoset_id' => photoset)
33
+ end
35
34
 
36
- def editMeta(photoset,title,description=nil)
37
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
38
- args = {'photoset_id' => photoset,
39
- 'title' => title}
40
- args['description' ] = description if description
41
- @flickr.call_method('flickr.photosets.editMeta',args)
42
- end
35
+ def editMeta(photoset,title,description=nil)
36
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
37
+ args = {'photoset_id' => photoset, 'title' => title}
38
+ args['description' ] = description if description
39
+ @flickr.call_method('flickr.photosets.editMeta',args)
40
+ end
43
41
 
44
- def editPhotos(photoset,primary_photo,photos)
45
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
46
- primary_photo = primary_photo.id if
47
- primary_photo.class == Flickr::Photo
48
- photos=photos.map{|p| p.id if p.class==Flickr::Photo}.join(',')
49
- args = {'photoset_id' => photoset,
50
- 'primary_photo_id' => primary_photo,
51
- 'photo_ids' => photos }
52
- @flickr.call_method('flickr.photosets.editPhotos',args)
53
- end
42
+ def editPhotos(photoset,primary_photo,photos)
43
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
44
+ primary_photo = primary_photo.id if
45
+ primary_photo.class == Flickr::Photo
46
+ photos=photos.map{|p| p.id if p.class==Flickr::Photo}.join(',')
47
+ args = {'photoset_id' => photoset,
48
+ 'primary_photo_id' => primary_photo,
49
+ 'photo_ids' => photos }
50
+ @flickr.call_method('flickr.photosets.editPhotos',args)
51
+ end
54
52
 
55
- def getContext(photo,photoset)
56
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
57
- photo = photo.id if photo.class == Flickr::Photo
58
- res = @flickr.call_method('flickr.photosets.getContext',
59
- 'photo_id' => photo, 'photoset_id' => photoset)
60
- return Flickr::Context.from_xml(res,@flickr)
61
- end
53
+ def getContext(photo,photoset)
54
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
55
+ photo = photo.id if photo.class == Flickr::Photo
56
+ res = @flickr.call_method('flickr.photosets.getContext',
57
+ 'photo_id' => photo, 'photoset_id' => photoset)
58
+ return Flickr::Context.from_xml(res,@flickr)
59
+ end
62
60
 
63
- def getList(user=nil)
64
- user = user.nsid if user.respond_to?(:nsid)
65
- args = {}
66
- args['user_id'] = user if user
67
- res = @flickr.call_method('flickr.photosets.getList',args)
68
- list = []
69
- res.elements['/photosets'].each_element do |el|
70
- list << Flickr::PhotoSet.from_xml(el,@flickr)
71
- end
72
- return list
73
- end
61
+ def getList(user=nil)
62
+ user = user.nsid if user.respond_to?(:nsid)
63
+ args = {}
64
+ args['user_id'] = user if user
65
+ res = @flickr.call_method('flickr.photosets.getList',args)
66
+ list = []
67
+ res.elements['/photosets'].each_element do |el|
68
+ list << Flickr::PhotoSet.from_xml(el,@flickr)
69
+ end
70
+ return list
71
+ end
74
72
 
75
- def removePhoto(photoset,photo)
76
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
77
- photo = photo.id if photo.class == Flickr::Photo
78
- @flickr.call_method('flickr.photosets.removePhoto',
79
- 'photo_id' => photo, 'photoset_id' => photoset)
80
- end
73
+ def removePhoto(photoset,photo)
74
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
75
+ photo = photo.id if photo.class == Flickr::Photo
76
+ @flickr.call_method('flickr.photosets.removePhoto',
77
+ 'photo_id' => photo, 'photoset_id' => photoset)
78
+ end
81
79
 
82
- def getPhotos(photoset,extras=nil)
83
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
84
- extras = extras.join(',') if extras.class == Array
85
- args = { 'photoset_id' => photoset }
86
- args['extras'] = extras if extras
87
- res = @flickr.call_method('flickr.photosets.getPhotos',args)
88
- return Flickr::PhotoSet.from_xml(res.root,@flickr)
89
- end
80
+ def getPhotos(photoset,extras=nil)
81
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
82
+ extras = extras.join(',') if extras.class == Array
83
+ args = { 'photoset_id' => photoset }
84
+ args['extras'] = extras if extras
85
+ res = @flickr.call_method('flickr.photosets.getPhotos',args)
86
+ return Flickr::PhotoSet.from_xml(res.root,@flickr)
87
+ end
90
88
 
91
- def getInfo(photoset)
92
- photoset = photoset.id if photoset.class == Flickr::PhotoSet
93
- res = @flickr.call_method('flickr.photosets.getInfo',
94
- 'photoset_id' => photoset)
95
- return Flickr::PhotoSet.from_xml(res.root,@flickr)
96
- end
89
+ def getInfo(photoset)
90
+ photoset = photoset.id if photoset.class == Flickr::PhotoSet
91
+ res = @flickr.call_method('flickr.photosets.getInfo',
92
+ 'photoset_id' => photoset)
93
+ return Flickr::PhotoSet.from_xml(res.root,@flickr)
94
+ end
97
95
 
98
- def orderSets(photosets)
99
- photosets=photosets.map { |ps|
100
- (ps.class==Flickr::PhotoSet) ? ps.id : ps}.join(',')
101
- @flickr.call_method('flickr.photosets.orderSets',
102
- 'photoset_ids' => photosets)
103
- end
96
+ def orderSets(photosets)
97
+ photosets=photosets.map { |ps|
98
+ (ps.class==Flickr::PhotoSet) ? ps.id : ps}.join(',')
99
+ @flickr.call_method('flickr.photosets.orderSets',
100
+ 'photoset_ids' => photosets)
101
+ end
104
102
  end
data/lib/flickr/pools.rb CHANGED
@@ -1,70 +1,73 @@
1
1
  require 'flickr/groups'
2
2
 
3
3
  class Flickr::Pools < Flickr::APIBase
4
- def initialize(flickr,groups)
5
- super(flickr)
6
- @groups = groups
7
- end
4
+
5
+ def initialize(flickr,groups)
6
+ super(flickr)
7
+ @groups = groups
8
+ end
8
9
 
9
- # photo can be a Photo or photo_id
10
- # group can be a Group or group_id
11
- def add(photo,group)
12
- group = group.nsid if group.class == Flickr::Group
13
- photo = photo.id if photo.class == Flickr::Photo
14
- @flickr.call_method('flickr.groups.pools.add',
15
- 'group_id' => group, 'photo_id' => photo)
16
- end
10
+ # photo can be a Photo or photo_id
11
+ # group can be a Group or group_id
12
+ def add(photo,group)
13
+ group = group.nsid if group.class == Flickr::Group
14
+ photo = photo.id if photo.class == Flickr::Photo
15
+ @flickr.call_method('flickr.groups.pools.add',
16
+ 'group_id' => group, 'photo_id' => photo)
17
+ end
17
18
 
18
- # photo can be a Photo or photo_id
19
- # group can be a Group or group_id
20
- def remove(photo,group)
21
- group = group.nsid if group.class == Flickr::Group
22
- photo = photo.id if photo.class == Flickr::Photo
23
- @flickr.call_method('flickr.groups.pools.add',
24
- 'group_id' => group, 'photo_id' => photo)
25
- end
19
+ # photo can be a Photo or photo_id
20
+ # group can be a Group or group_id
21
+ def remove(photo,group)
22
+ group = group.nsid if group.class == Flickr::Group
23
+ photo = photo.id if photo.class == Flickr::Photo
24
+ @flickr.call_method('flickr.groups.pools.add',
25
+ 'group_id' => group, 'photo_id' => photo)
26
+ end
26
27
 
27
- # photo can be a Photo or photo_id
28
- # group can be a Group or group_id
29
- def getContext(photo,group)
30
- group = group.nsid if group.class == Flickr::Group
31
- photo = photo.id if photo.class == Flickr::Photo
32
- res = @flickr.call_method('flickr.groups.pools.getContex',
33
- 'group_id' => group, 'photo_id' => photo)
34
- return Flickr::Context.from_xml(res)
35
- end
28
+ # photo can be a Photo or photo_id
29
+ # group can be a Group or group_id
30
+ def getContext(photo,group)
31
+ group = group.nsid if group.class == Flickr::Group
32
+ photo = photo.id if photo.class == Flickr::Photo
33
+ res = @flickr.call_method('flickr.groups.pools.getContex',
34
+ 'group_id' => group, 'photo_id' => photo)
35
+ return Flickr::Context.from_xml(res)
36
+ end
36
37
 
37
- def getGroups
38
- res = @flickr.call_method('flickr.groups.pools.getGroups')
39
- list = []
40
- res.elements['/groups'].each_element do |el|
41
- att = el.attributes
42
- nsid = att['nsid']
43
- g = @flickr.group_cache_lookup(nsid) ||
44
- Flickr::Group.new(@flickr,nsid,att['name'])
45
- g.name = att['name']
46
- g.admin = att['admin'].to_i == 1
47
- g.privacy = Flickr::Group::PRIVACY[att['privacy'].to_i]
48
- g.photo_count = att['photos'].to_i
49
- g.iconserver = att['iconserver'].to_i
38
+ def getGroups
39
+ res = @flickr.call_method('flickr.groups.pools.getGroups')
40
+ list = []
50
41
 
51
- @flickr.group_cache_store(g)
52
- list << g
53
- end
54
- return list
55
- end
42
+ res.elements['/groups'].each_element do |el|
43
+ att = el.attributes
44
+ nsid = att['nsid']
45
+ g = @flickr.group_cache_lookup(nsid) ||
46
+ Flickr::Group.new(@flickr,nsid,att['name'])
47
+ g.name = att['name']
48
+ g.admin = att['admin'].to_i == 1
49
+ g.privacy = Flickr::Group::PRIVACY[att['privacy'].to_i]
50
+ g.photo_count = att['photos'].to_i
51
+ g.iconserver = att['iconserver'].to_i
56
52
 
57
- def getPhotos(group,tags=nil,extras=nil,per_page=nil,page=nil)
58
- group = group.nsid if group.class == Flickr::Group
59
- group = group.id.to_s if group.class == Flickr::PhotoPool
60
- args = { 'group_id' => group }
61
- args['tags'] = tags.map{|t| t.clean if t.class ==
62
- Flick::Tag}.join(',') if tags
63
- args['extras'] = extras.join(',') if extras.class == Array
64
- args['per_page'] = per_page if per_page
65
- args['page'] = page if page
53
+ @flickr.group_cache_store(g)
54
+ list << g
55
+ end
56
+
57
+ return list
58
+ end
66
59
 
67
- res = @flickr.call_method('flickr.groups.pools.getPhotos', args)
68
- return Flickr::PhotoList.from_xml(res,@flickr)
69
- end
60
+ def getPhotos(group,tags=nil,extras=nil,per_page=nil,page=nil)
61
+ group = group.nsid if group.class == Flickr::Group
62
+ group = group.id.to_s if group.class == Flickr::PhotoPool
63
+ args = { 'group_id' => group }
64
+ args['tags'] = tags.map{|t| t.clean if t.class ==
65
+ Flick::Tag}.join(',') if tags
66
+ args['extras'] = extras.join(',') if extras.class == Array
67
+ args['per_page'] = per_page if per_page
68
+ args['page'] = page if page
69
+
70
+ res = @flickr.call_method('flickr.groups.pools.getPhotos', args)
71
+ return Flickr::PhotoList.from_xml(res,@flickr)
72
+ end
70
73
  end
@@ -1,89 +1,89 @@
1
1
  require 'flickr/base'
2
2
 
3
3
  class Flickr::Method
4
- attr_reader :name,:authenticated,:description,:response,:explanation,
5
- :arguments, :errors
4
+ attr_reader :name, :authenticated, :description, :response, :explanation,
5
+ :arguments, :errors
6
6
 
7
- def initialize(name,authenticated,description,response,explanation)
8
- @name = name
9
- @authenticated = authenticated
10
- @description = description
11
- @response = response
12
- @explanation = explanation
13
- @arguments = []
14
- @errors = []
15
- end
7
+ def initialize(name,authenticated,description,response,explanation)
8
+ @name = name
9
+ @authenticated = authenticated
10
+ @description = description
11
+ @response = response
12
+ @explanation = explanation
13
+ @arguments = []
14
+ @errors = []
15
+ end
16
16
  end
17
17
 
18
18
  class Flickr::MethodArgument
19
- attr_reader :name, :optional, :description
20
-
21
- def initialize(name,optional,description)
22
- @name = name
23
- @optional = optional
24
- @description = description
25
- end
19
+ attr_reader :name, :optional, :description
20
+
21
+ def initialize(name,optional,description)
22
+ @name = name
23
+ @optional = optional
24
+ @description = description
25
+ end
26
26
  end
27
27
 
28
28
  class Flickr::Reflection < Flickr::APIBase
29
- # We don't bother with caching because it's not worth it for the
30
- # reflection API.
31
- def getMethodInfo(method_name)
32
- res = @flickr.call_method('flickr.reflection.getMethodInfo',
33
- 'method_name' => method_name)
34
- els = res.elements
35
- att = res.root.attributes
36
- desc = els['/method/description'] ?
37
- els['/method/description'].text : nil
38
- resp = els['/method/response'] ?
39
- els['/method/response'].text : nil
40
- expl = els['/method/explanation'] ?
41
- els['/method/explanation'].text : nil
42
- meth = Flickr::Method.new(att['name'],att['needslogin'].to_i==1,
43
- desc,resp,expl)
44
- els['/method/arguments'].each_element do |el|
45
- att = el.attributes
46
- arg = Flickr::MethodArgument.new(att['name'],
47
- att['optional'].to_i == 1,el.text)
48
- meth.arguments << arg
49
- end
50
- els['/method/errors'].each_element do |el|
51
- att = el.attributes
52
- err = XMLRPC::FaultException.new(att['code'].to_i,
53
- el.text)
54
- meth.errors << err
55
- end
56
- return meth
57
- end
29
+ # We don't bother with caching because it's not worth it for the
30
+ # reflection API.
31
+ def getMethodInfo(method_name)
32
+ res = @flickr.call_method('flickr.reflection.getMethodInfo',
33
+ 'method_name' => method_name)
34
+ els = res.elements
35
+ att = res.root.attributes
36
+ desc = els['/method/description'] ?
37
+ els['/method/description'].text : nil
38
+ resp = els['/method/response'] ?
39
+ els['/method/response'].text : nil
40
+ expl = els['/method/explanation'] ?
41
+ els['/method/explanation'].text : nil
42
+ meth = Flickr::Method.new(att['name'],att['needslogin'].to_i==1,
43
+ desc,resp,expl)
44
+ els['/method/arguments'].each_element do |el|
45
+ att = el.attributes
46
+ arg = Flickr::MethodArgument.new(att['name'],
47
+ att['optional'].to_i == 1,el.text)
48
+ meth.arguments << arg
49
+ end
50
+ els['/method/errors'].each_element do |el|
51
+ att = el.attributes
52
+ err = XMLRPC::FaultException.new(att['code'].to_i,
53
+ el.text)
54
+ meth.errors << err
55
+ end
56
+ return meth
57
+ end
58
58
 
59
- def getMethods
60
- res = @flickr.call_method('flickr.reflection.getMethods')
61
- list = []
62
- res.elements['/methods'].each_element do |el|
63
- list << el.text
64
- end
65
- return list
66
- end
59
+ def getMethods
60
+ res = @flickr.call_method('flickr.reflection.getMethods')
61
+ list = []
62
+ res.elements['/methods'].each_element do |el|
63
+ list << el.text
64
+ end
65
+ return list
66
+ end
67
67
 
68
- def missing_methods
69
- list = []
70
- methods = self.getMethods
71
- methods.each do |mname|
72
- parts = mname.split('.')
73
- parts.shift
74
- call = parts.pop
75
- obj = @flickr
76
- parts.each do |part|
77
- if obj.respond_to?(part)
78
- obj = obj.method(part).call
79
- else
80
- obj = nil
81
- list << mname
82
- break
83
- end
84
- end
85
- list << mname if (obj && !obj.respond_to?(call))
86
- end
87
- return list
88
- end
68
+ def missing_methods
69
+ list = []
70
+ methods = self.getMethods
71
+ methods.each do |mname|
72
+ parts = mname.split('.')
73
+ parts.shift
74
+ call = parts.pop
75
+ obj = @flickr
76
+ parts.each do |part|
77
+ if obj.respond_to?(part)
78
+ obj = obj.method(part).call
79
+ else
80
+ obj = nil
81
+ list << mname
82
+ break
83
+ end
84
+ end
85
+ list << mname if (obj && !obj.respond_to?(call))
86
+ end
87
+ return list
88
+ end
89
89
  end