flickrie 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,8 +95,7 @@ module Flickrie
95
95
  #
96
96
  # @note This method requires authentication with "read" permissions.
97
97
  def photos_from_user(nsid, params = {})
98
- media_from_user(nsid, params).
99
- select { |media| media.is_a?(Photo) }
98
+ media_from_user(nsid, params).select { |media| media.is_a?(Photo) }
100
99
  end
101
100
  # Fetches videos from the Flickr user with the given NSID.
102
101
  #
@@ -106,8 +105,7 @@ module Flickrie
106
105
  #
107
106
  # @note This method requires authentication with "read" permissions.
108
107
  def videos_from_user(nsid, params = {})
109
- media_from_user(nsid, params).
110
- select { |media| media.is_a?(Video) }
108
+ media_from_user(nsid, params).select { |media| media.is_a?(Video) }
111
109
  end
112
110
 
113
111
  # Fetches public photos and videos from the Flickr user with the given
@@ -126,8 +124,7 @@ module Flickrie
126
124
  # @return [Flickrie::Collection<Flickrie::Photo>]
127
125
  # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
128
126
  def public_photos_from_user(nsid, params = {})
129
- public_media_from_user(nsid, params).
130
- select { |media| media.is_a?(Photo) }
127
+ public_media_from_user(nsid, params).select { |media| media.is_a?(Photo) }
131
128
  end
132
129
  # Fetches public videos from the Flickr user with the given NSID.
133
130
  #
@@ -135,8 +132,7 @@ module Flickrie
135
132
  # @return [Flickrie::Collection<Flickrie::Video>]
136
133
  # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
137
134
  def public_videos_from_user(nsid, params = {})
138
- public_media_from_user(nsid, params).
139
- select { |media| media.is_a?(Video) }
135
+ public_media_from_user(nsid, params).select { |media| media.is_a?(Video) }
140
136
  end
141
137
 
142
138
  # Returns the upload status of the user who is currently authenticated.
@@ -505,7 +501,7 @@ module Flickrie
505
501
  # @api_method [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
506
502
  def sets_from_user(nsid, params = {})
507
503
  response = client.sets_from_user(nsid, params)
508
- Set.from_user(response.body['photosets']['photoset'], nsid)
504
+ Set.from_user(response.body['photosets'], nsid)
509
505
  end
510
506
 
511
507
  # Fetches photos and videos from a set with the given ID.
@@ -3,26 +3,34 @@ if Flickrie.pagination == :will_paginate
3
3
  end
4
4
 
5
5
  module Flickrie
6
- # You can think of this as a richer Array. It defines some pagination attributes
7
- # (you can evem use it with [will_paginate](https://github.com/mislav/will_paginate),
8
- # see {Flickrie.pagination}). It also has the method {#find} which finds by ID
9
- # (just like ActiveRecord).
10
- class Collection < (defined?(WillPaginate) ? WillPaginate::Collection : Array)
11
- attr_reader :current_page, :per_page, :total_entries, :total_pages
6
+ if Flickrie.pagination == :will_paginate
7
+ const_set(:Collection, Class.new(WillPaginate::Collection) do
8
+ def initialize(hash)
9
+ current_page = Integer(hash['page'])
10
+ per_page = Integer(hash['per_page'] || hash['perpage'])
11
+ total_entries = Integer(hash['total'])
12
+ super(current_page, per_page, total_entries)
13
+ end
14
+ end)
15
+ else
16
+ const_set(:Collection, Class.new(Array) do
17
+ attr_reader :current_page, :per_page, :total_entries, :total_pages
12
18
 
13
- def initialize(params)
14
- hash = params[:pagination]
15
- if defined?(WillPaginate)
16
- @current_page = WillPaginate::PageNumber(Integer(hash['page']))
17
- else
19
+ def initialize(hash)
18
20
  @current_page = Integer(hash['page'])
21
+ @per_page = Integer(hash['per_page'] || hash['perpage'])
22
+ @total_entries = Integer(hash['total'])
23
+ @total_pages = Integer(hash['pages'])
19
24
  end
20
- @per_page = Integer(hash['per_page'] || hash['perpage'])
21
- @total_entries = Integer(hash['total'])
22
- @total_pages = Integer(hash['pages'])
25
+ end)
26
+ end
23
27
 
24
- Array.instance_method(:initialize).bind(self).call(params[:array])
25
- end
28
+ # You can think of this as a richer Array. It defines some pagination attributes
29
+ # (you can even use it with [will_paginate](https://github.com/mislav/will_paginate),
30
+ # see {Flickrie.pagination}). It also has the method {#find} which finds by ID
31
+ # (just like ActiveRecord).
32
+ class Collection
33
+ # @!parse attr_reader :current_page, :per_page, :total_entries, :total_pages
26
34
 
27
35
  # Finds an object by ID (just like ActiveRecord does). This is just a
28
36
  # shorthand for
@@ -3,18 +3,17 @@ module Flickrie
3
3
  # @private
4
4
  module ClassMethods
5
5
  def from_set(hash)
6
- hash['photo'].map! do |individual_hash|
7
- individual_hash['owner'] = {
6
+ collection = hash.delete('photo').map do |media_hash|
7
+ media_hash['owner'] = {
8
8
  'id' => hash['owner'],
9
9
  'nsid' => hash['owner'],
10
10
  'username' => hash['ownername'],
11
11
  }
12
- fix_extras(individual_hash)
13
- new(individual_hash)
12
+ fix_extras(media_hash)
13
+ new(media_hash)
14
14
  end
15
15
 
16
- Collection.new :array => hash.delete('photo'),
17
- :pagination => hash
16
+ Collection.new(hash).replace(collection)
18
17
  end
19
18
 
20
19
  def from_info(hash)
@@ -23,19 +22,18 @@ module Flickrie
23
22
  end
24
23
 
25
24
  def from_user(hash)
26
- hash['photo'].map! do |individual_hash|
27
- individual_hash['owner'] = {
28
- 'id' => individual_hash['owner'],
29
- 'nsid' => individual_hash.delete('owner'),
30
- 'username' => individual_hash.delete('ownername')
25
+ collection = hash.delete('photo').map do |media_hash|
26
+ media_hash['owner'] = {
27
+ 'id' => media_hash['owner'],
28
+ 'nsid' => media_hash.delete('owner'),
29
+ 'username' => media_hash.delete('ownername')
31
30
  }
32
- fix_extras(individual_hash)
33
- fix_visibility(individual_hash)
34
- new(individual_hash)
31
+ fix_extras(media_hash)
32
+ fix_visibility(media_hash)
33
+ new(media_hash)
35
34
  end
36
35
 
37
- Collection.new :array => hash.delete('photo'),
38
- :pagination => hash
36
+ Collection.new(hash).replace(collection)
39
37
  end
40
38
 
41
39
  def from_sizes(hash)
@@ -48,8 +46,8 @@ module Flickrie
48
46
  end
49
47
 
50
48
  def from_contacts(hash)
51
- hash['photo'].each do |individual_hash|
52
- individual_hash['ownername'] = individual_hash.delete('username')
49
+ hash['photo'].each do |media_hash|
50
+ media_hash['ownername'] = media_hash.delete('username')
53
51
  end
54
52
 
55
53
  from_user(hash)
@@ -142,8 +142,13 @@ module Flickrie
142
142
  # @return [Array<Flickrie::Media::Note>]
143
143
  def notes() @hash['notes']['note'].map { |info| Note.new(info) } rescue nil end
144
144
 
145
- # @return [Array<Flickrie::User>]
146
- def favorites() @hash['person'].map { |info| User.new(info) } rescue nil end
145
+ # @return [Flickrie::Collection<Flickrie::User>]
146
+ def favorites
147
+ collection = @hash['person'].map { |info| User.new(info) }
148
+ Collection.new(@hash).replace(collection)
149
+ rescue
150
+ nil
151
+ end
147
152
 
148
153
  def [](key) @hash[key] end
149
154
  # Returns the raw hash from the response. Useful if something isn't available by methods.
data/lib/flickrie/set.rb CHANGED
@@ -8,38 +8,38 @@ module Flickrie
8
8
  # :created_at, :updated_at, :url, :hash
9
9
 
10
10
  # @return [String]
11
- def id() @info['id'] end
11
+ def id() @hash['id'] end
12
12
  # @return [String]
13
- def secret() @info['secret'] end
13
+ def secret() @hash['secret'] end
14
14
  # @return [String]
15
- def server() @info['server'] end
15
+ def server() @hash['server'] end
16
16
  # @return [Fixnum]
17
- def farm() @info['farm'] end
17
+ def farm() @hash['farm'] end
18
18
  # @return [String]
19
- def title() @info['title'] end
19
+ def title() @hash['title'] end
20
20
  # @return [String]
21
- def description() @info['description'] end
21
+ def description() @hash['description'] end
22
22
 
23
23
  # @return [String]
24
- def primary_media_id() @info['primary'] end
24
+ def primary_media_id() @hash['primary'] end
25
25
  alias primary_photo_id primary_media_id
26
26
  alias primary_video_id primary_media_id
27
27
 
28
28
  # @return [Fixnum]
29
- def views_count() Integer(@info['count_views']) rescue nil end
29
+ def views_count() Integer(@hash['count_views']) rescue nil end
30
30
  # @return [Fixnum]
31
- def comments_count() Integer(@info['count_comments']) rescue nil end
31
+ def comments_count() Integer(@hash['count_comments']) rescue nil end
32
32
  # @return [Fixnum]
33
- def photos_count() Integer(@info['count_photos']) rescue nil end
33
+ def photos_count() Integer(@hash['count_photos']) rescue nil end
34
34
  # @return [Fixnum]
35
- def videos_count() Integer(@info['count_videos']) rescue nil end
35
+ def videos_count() Integer(@hash['count_videos']) rescue nil end
36
36
  # @return [Fixnum]
37
37
  def media_count
38
38
  photos_count + videos_count rescue nil
39
39
  end
40
40
 
41
41
  # @return [Flickrie::User]
42
- def owner() User.new('nsid' => @info['owner']) if @info['owner'] end
42
+ def owner() User.new('nsid' => @hash['owner']) if @hash['owner'] end
43
43
 
44
44
  # Same as calling `Flickrie.photos_from_set(set.id)`.
45
45
  #
@@ -61,59 +61,64 @@ module Flickrie
61
61
  end
62
62
 
63
63
  # @return [Boolean]
64
- def can_comment?() Integer(@info['can_comment']) == 1 rescue nil end
64
+ def can_comment?() Integer(@hash['can_comment']) == 1 rescue nil end
65
65
 
66
66
  # @return [Boolean]
67
- def needs_interstitial?() Integer(@info['needs_interstitial']) == 1 rescue nil end
67
+ def needs_interstitial?() Integer(@hash['needs_interstitial']) == 1 rescue nil end
68
68
  # @return [Boolean]
69
- def visibility_can_see_set?() Integer(@info['visibility_can_see_set']) == 1 rescue nil end
69
+ def visibility_can_see_set?() Integer(@hash['visibility_can_see_set']) == 1 rescue nil end
70
70
 
71
71
  # @return [Time]
72
- def created_at() Time.at(Integer(@info['date_create'])) rescue nil end
72
+ def created_at() Time.at(Integer(@hash['date_create'])) rescue nil end
73
73
  # @return [Time]
74
- def updated_at() Time.at(Integer(@info['date_update'])) rescue nil end
74
+ def updated_at() Time.at(Integer(@hash['date_update'])) rescue nil end
75
75
 
76
76
  # @return [String]
77
77
  def url() "http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}" rescue nil end
78
78
 
79
- def [](key) @info[key] end
79
+ def [](key) @hash[key] end
80
80
  # @return [Hash]
81
- def hash() @info end
81
+ def hash() @hash end
82
82
 
83
83
  # Same as calling `Flickrie.get_set_info(set.id)`
84
84
  #
85
85
  # @return [self]
86
- def get_info(params = {}, info = nil)
87
- info ||= Flickrie.client.get_set_info(id, params).body['photoset']
88
- @info.update(info)
89
-
90
- # Fixes
91
- @info['title'] = @info['title']['_content']
92
- @info['description'] = @info['description']['_content']
86
+ def get_info(params = {})
87
+ hash ||= Flickrie.client.get_set_info(id, params).body['photoset']
88
+ self.class.fix_info(hash)
89
+ @hash.update(hash)
93
90
 
94
91
  self
95
92
  end
96
93
 
97
94
  private
98
95
 
99
- def initialize(info = {})
100
- @info = info
96
+ def initialize(hash = {})
97
+ @hash = hash
98
+ end
99
+
100
+ def self.from_info(hash)
101
+ fix_info(hash)
102
+ new(hash)
101
103
  end
102
104
 
103
- def self.from_info(info)
104
- new.get_info({}, info)
105
+ def self.fix_info(hash)
106
+ hash['title'] = hash['title']['_content']
107
+ hash['description'] = hash['description']['_content']
105
108
  end
106
109
 
107
- def self.from_user(info, user_nsid)
108
- info.map do |info|
109
- info['count_photos'] = info.delete('photos')
110
- info['count_videos'] = info.delete('videos')
111
- info['title'] = info['title']['_content']
112
- info['description'] = info['description']['_content']
113
- info['owner'] = user_nsid
110
+ def self.from_user(hash, user_nsid)
111
+ collection = hash.delete('photoset').map do |set_hash|
112
+ set_hash['count_photos'] = set_hash.delete('photos')
113
+ set_hash['count_videos'] = set_hash.delete('videos')
114
+ set_hash['title'] = set_hash['title']['_content']
115
+ set_hash['description'] = set_hash['description']['_content']
116
+ set_hash['owner'] = user_nsid
114
117
 
115
- new(info)
118
+ new(set_hash)
116
119
  end
120
+
121
+ Collection.new(hash).replace(collection)
117
122
  end
118
123
  end
119
124
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickrie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70354735471460 !ruby/object:Gem::Requirement
16
+ requirement: &70205943354860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0.9'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70354735471460
27
+ version_requirements: *70205943354860
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
- requirement: &70354735469600 !ruby/object:Gem::Requirement
30
+ requirement: &70205943340760 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '0.9'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70354735469600
41
+ version_requirements: *70205943340760
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: simple_oauth
44
- requirement: &70354735467340 !ruby/object:Gem::Requirement
44
+ requirement: &70205943338120 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '0.1'
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *70354735467340
52
+ version_requirements: *70205943338120
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_xml
55
- requirement: &70354735466580 !ruby/object:Gem::Requirement
55
+ requirement: &70205943336520 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0.4'
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *70354735466580
63
+ version_requirements: *70205943336520
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: bundler
66
- requirement: &70354740714520 !ruby/object:Gem::Requirement
66
+ requirement: &70205943335000 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '1.0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *70354740714520
74
+ version_requirements: *70205943335000
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
- requirement: &70354740713980 !ruby/object:Gem::Requirement
77
+ requirement: &70205943333720 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '0.9'
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *70354740713980
85
+ version_requirements: *70205943333720
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: rspec
88
- requirement: &70354740713460 !ruby/object:Gem::Requirement
88
+ requirement: &70205943325680 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ! '>='
@@ -96,10 +96,10 @@ dependencies:
96
96
  version: '3'
97
97
  type: :development
98
98
  prerelease: false
99
- version_requirements: *70354740713460
99
+ version_requirements: *70205943325680
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: vcr
102
- requirement: &70354740712620 !ruby/object:Gem::Requirement
102
+ requirement: &70205943322700 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
105
  - - ~>
@@ -107,7 +107,7 @@ dependencies:
107
107
  version: '2.1'
108
108
  type: :development
109
109
  prerelease: false
110
- version_requirements: *70354740712620
110
+ version_requirements: *70205943322700
111
111
  description: This gem wraps the Flickr API with a nice object-oriented interface.
112
112
  email: janko.marohnic@gmail.com
113
113
  executables: []
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: -4020731564119486214
166
+ hash: -3848221286022942563
167
167
  requirements: []
168
168
  rubyforge_project:
169
169
  rubygems_version: 1.8.11