flickrie 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@ TODO.md
2
2
  Gemfile.lock
3
3
  pkg/
4
4
  credentials.rb
5
+ doc/
6
+ .DS_Store
data/CHANGELOG.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Flickrie changelog
2
2
 
3
+ ## Version 0.6.1
4
+
5
+ - `Flickrie::Media::Ticket` is now called just `Flickrie::Ticket`
6
+
3
7
  ## Version 0.6.0
4
8
 
5
9
  - you can access the raw response hash with square brackets, if you notice I
6
- didn't cover some part of it with methods. So, for example, `photo['id']`
7
- will access the photo's ID.
10
+ didn't cover some part of it with methods. So, for example, after calling
11
+ `Flickrie.get_photo_info`, you can get the photo ID by calling `photo['id']`
8
12
 
9
- - when `Flickrie::Error` is raises, you can now access its `#code`
13
+ - when `Flickrie::Error` is raised, you can now access its `#code`
10
14
  attribute. This makes better error handling, because error code
11
15
  is (supposed to be) unique, unlike the error message
12
16
 
data/README.md CHANGED
@@ -94,28 +94,35 @@ photo.get_info
94
94
  photo.description # => "In this photo Peter said something really funny..."
95
95
  ```
96
96
 
97
- You'll also probably want to display these photos in your app.
97
+ You'll also probably want to display these photos in your app. There are
98
+ some neat methods available for you to help you out with this.
98
99
 
99
100
  ```ruby
100
101
  photo = Flickrie.get_photo_sizes(8232348)
101
102
  # or "photo.get_sizes" on an existing photo
102
103
 
103
- photo.medium!(800)
104
- photo.size # => "Medium 800"
105
- photo.source_url # => "http://farm8.staticflickr.com/7049/6946979188_25bb44852b_c.jpg"
106
- photo.width # => 600
107
- photo.height # => 800
108
-
109
- photo.small!(320)
110
- photo.size # => "Small 320"
111
- photo.source_url # => "http://farm8.staticflickr.com/7049/6946979188_25bb44852b_n.jpg"
112
- photo.width # => 240
113
- photo.width # => 320
104
+ photo.medium!(500)
105
+ photo.size # => "Medium 500"
106
+ photo.source_url # => "http://farm8.staticflickr.com/7090/7093101501_9337f28800.jpg"
107
+ photo.width # => 375
108
+ photo.height # => 500
109
+
110
+ photo.available_sizes # => ["Square 75", "Thumbnail", "Square 150", "Small 240", "Small 320", "Medium 500"]
111
+ ```
112
+
113
+ So, in your ERB template you could do something like this (in Rails):
114
+
115
+ ```erb
116
+ <%= image_tag photo.source_url, :size => "#{photo.width}x#{photo.height}" %>
114
117
  ```
115
118
 
116
119
  You can see the full list of available methods and attributes in the
117
- [documentation](http://rubydoc.info/gems/flickrie/0.1.2/frames). Also,
118
- be sure to check the [wiki](https://github.com/janko-m/flickrie/wiki) for some additional info and tips.
120
+ [documentation](http://janko-m.github.com/flickrie/doc/Flickrie.html).
121
+ For photos (and videos) have a look at the `Flickrie::Media` module,
122
+ because it's included into `Flickrie::Photo` and `Flickrie::Video`, and most
123
+ of the attributes are there.
124
+
125
+ Also, be sure to check the [wiki](https://github.com/janko-m/flickrie/wiki) for some additional info and tips.
119
126
 
120
127
  ## Authentication
121
128
 
@@ -8,6 +8,7 @@ require 'flickrie/photo'
8
8
  require 'flickrie/video'
9
9
  require 'flickrie/set'
10
10
  require 'flickrie/media_count'
11
+ require 'flickrie/ticket'
11
12
 
12
13
  module Flickrie
13
14
  module ApiMethods
@@ -31,18 +32,18 @@ module Flickrie
31
32
 
32
33
  #--
33
34
  # people
34
- def find_user_by_email(email)
35
- response = client.find_user_by_email(email)
35
+ def find_user_by_email(email, params = {})
36
+ response = client.find_user_by_email(email, params)
36
37
  User.from_find(response.body['user'])
37
38
  end
38
39
 
39
- def find_user_by_username(username)
40
- response = client.find_user_by_username(username)
40
+ def find_user_by_username(username, params = {})
41
+ response = client.find_user_by_username(username, params)
41
42
  User.from_find(response.body['user'])
42
43
  end
43
44
 
44
- def get_user_info(user_nsid)
45
- response = client.get_user_info(user_nsid)
45
+ def get_user_info(user_nsid, params = {})
46
+ response = client.get_user_info(user_nsid, params)
46
47
  User.from_info(response.body['person'])
47
48
  end
48
49
 
@@ -61,14 +62,14 @@ module Flickrie
61
62
 
62
63
  #--
63
64
  # photos
64
- def add_media_tags(media_id, tags)
65
- client.add_media_tags(media_id, tags)
65
+ def add_media_tags(media_id, tags, params = {})
66
+ client.add_media_tags(media_id, tags, params)
66
67
  end
67
68
  alias add_photo_tags add_media_tags
68
69
  alias add_video_tags add_media_tags
69
70
 
70
- def delete_media(media_id)
71
- client.delete_media(media_id)
71
+ def delete_media(media_id, params = {})
72
+ client.delete_media(media_id, params)
72
73
  media_id
73
74
  end
74
75
  alias delete_photo delete_media
@@ -98,22 +99,16 @@ module Flickrie
98
99
  select { |media| media.is_a?(Photo) }
99
100
  end
100
101
 
101
- def get_media_context(media_id)
102
- response = client.get_media_context(media_id)
102
+ def get_media_context(media_id, params = {})
103
+ response = client.get_media_context(media_id, params)
103
104
  Media.from_context(response.body)
104
105
  end
105
106
  alias get_photo_context get_media_context
106
107
  alias get_video_context get_media_context
107
108
 
108
109
  def get_media_counts(params = {})
109
- response = client.get_media_counts(
110
- params.dup.tap do |hash|
111
- if hash[:taken_dates].is_a?(String)
112
- hash[:taken_dates] = hash[:taken_dates].split(',').
113
- map { |date| DateTime.parse(date) }.
114
- map(&:to_time).map(&:getutc).join(',')
115
- end
116
- end)
110
+ response = client.get_media_counts \
111
+ MediaCount.ensure_utc(params)
117
112
  response.body['photocounts']['photocount'].
118
113
  map { |info| MediaCount.new(info, params) }
119
114
  end
@@ -122,31 +117,31 @@ module Flickrie
122
117
 
123
118
  def get_photo_exif(photo_id, params = {})
124
119
  response = client.get_media_exif(photo_id, params)
125
- Photo.from_exif(response.body['photo'].merge('media' => 'photo'))
120
+ Photo.from_exif(response.body['photo'])
126
121
  end
127
122
  def get_video_exif(video_id, params = {})
128
123
  response = client.get_media_exif(video_id, params)
129
- Video.from_exif(response.body['photo'].merge('media' => 'video'))
124
+ Video.from_exif(response.body['photo'])
130
125
  end
131
126
 
132
- def get_media_info(media_id)
133
- response = client.get_media_info(media_id)
127
+ def get_media_info(media_id, params = {})
128
+ response = client.get_media_info(media_id, params)
134
129
  Media.from_info(response.body['photo'])
135
130
  end
136
131
  alias get_photo_info get_media_info
137
132
  alias get_video_info get_media_info
138
133
 
139
- def get_photo_sizes(photo_id)
140
- response = client.get_media_sizes(photo_id)
134
+ def get_photo_sizes(photo_id, params = {})
135
+ response = client.get_media_sizes(photo_id, params)
141
136
  Photo.from_sizes(response.body['sizes'])
142
137
  end
143
- def get_video_sizes(video_id)
144
- response = client.get_media_sizes(video_id)
138
+ def get_video_sizes(video_id, params = {})
139
+ response = client.get_media_sizes(video_id, params)
145
140
  Video.from_sizes(response.body['sizes'])
146
141
  end
147
142
 
148
- def remove_media_tag(tag_id)
149
- client.remove_media_tag(tag_id)
143
+ def remove_media_tag(tag_id, params = {})
144
+ client.remove_media_tag(tag_id, params)
150
145
  end
151
146
  alias remove_photo_tag remove_media_tag
152
147
  alias remove_video_tag remove_media_tag
@@ -164,29 +159,29 @@ module Flickrie
164
159
 
165
160
  #--
166
161
  # photos.upload
167
- def check_upload_tickets(tickets)
162
+ def check_upload_tickets(tickets, params = {})
168
163
  tickets = tickets.join(',') if tickets.respond_to?(:join)
169
- response = client.check_upload_tickets(tickets)
164
+ response = client.check_upload_tickets(tickets, params)
170
165
  response.body['uploader']['ticket'].
171
- map { |info| Media::Ticket.new(info) }
166
+ map { |info| Ticket.new(info) }
172
167
  end
173
168
 
174
169
  #--
175
170
  # licenses
176
- def get_licenses
177
- response = client.get_licenses
171
+ def get_licenses(params = {})
172
+ response = client.get_licenses(params)
178
173
  License.from_hash(response.body['licenses']['license'])
179
174
  end
180
175
 
181
176
  #--
182
177
  # photosets
183
- def get_set_info(set_id)
184
- response = client.get_set_info(set_id)
178
+ def get_set_info(set_id, params = {})
179
+ response = client.get_set_info(set_id, params)
185
180
  Set.from_info(response.body['photoset'])
186
181
  end
187
182
 
188
- def sets_from_user(user_nsid)
189
- response = client.sets_from_user(user_nsid)
183
+ def sets_from_user(user_nsid, params = {})
184
+ response = client.sets_from_user(user_nsid, params)
190
185
  Set.from_user(response.body['photosets']['photoset'], user_nsid)
191
186
  end
192
187
 
@@ -14,6 +14,7 @@ module Flickrie
14
14
  end
15
15
  end
16
16
 
17
+ # :doc:
17
18
  attr_accessor_with_client_reset :api_key, :shared_secret,
18
19
  :timeout, :open_timeout, :access_token, :access_secret
19
20
 
@@ -98,31 +99,36 @@ module Flickrie
98
99
 
99
100
  #--
100
101
  # people
101
- def find_user_by_email(email)
102
- get 'flickr.people.findByEmail', :find_email => email
102
+ def find_user_by_email(email, params = {})
103
+ get 'flickr.people.findByEmail',
104
+ {:find_email => email}.merge(params)
103
105
  end
104
106
 
105
- def find_user_by_username(username)
106
- get 'flickr.people.findByUsername', :username => username
107
+ def find_user_by_username(username, params = {})
108
+ get 'flickr.people.findByUsername',
109
+ {:username => username}.merge(params)
107
110
  end
108
111
 
109
- def get_user_info(user_nsid)
110
- get 'flickr.people.getInfo', :user_id => user_nsid
112
+ def get_user_info(user_nsid, params = {})
113
+ get 'flickr.people.getInfo',
114
+ {:user_id => user_nsid}.merge(params)
111
115
  end
112
116
 
113
117
  def public_media_from_user(user_nsid, params = {})
114
- params = {:user_id => user_nsid}.merge(params)
115
- get 'flickr.people.getPublicPhotos', ensure_media(params)
118
+ get 'flickr.people.getPublicPhotos',
119
+ ensure_media({:user_id => user_nsid}.merge(params))
116
120
  end
117
121
 
118
122
  #--
119
123
  # photos
120
- def add_media_tags(media_id, tags)
121
- post 'flickr.photos.addTags', :photo_id => media_id, :tags => tags
124
+ def add_media_tags(media_id, tags, params = {})
125
+ post 'flickr.photos.addTags',
126
+ {:photo_id => media_id, :tags => tags}.merge(params)
122
127
  end
123
128
 
124
- def delete_media(media_id)
125
- post 'flickr.photos.delete', :photo_id => media_id
129
+ def delete_media(media_id, params = {})
130
+ post 'flickr.photos.delete',
131
+ {:photo_id => media_id}.merge(params)
126
132
  end
127
133
 
128
134
  def media_from_contacts(params = {})
@@ -130,12 +136,13 @@ module Flickrie
130
136
  end
131
137
 
132
138
  def public_media_from_user_contacts(user_nsid, params = {})
133
- params = {:user_id => user_nsid}.merge(params)
134
- get 'flickr.photos.getContactsPublicPhotos', ensure_media(params)
139
+ get 'flickr.photos.getContactsPublicPhotos',
140
+ ensure_media({:user_id => user_nsid}.merge(params))
135
141
  end
136
142
 
137
- def get_media_context(media_id)
138
- get 'flickr.photos.getContext', :photo_id => media_id
143
+ def get_media_context(media_id, params = {})
144
+ get 'flickr.photos.getContext',
145
+ {:photo_id => media_id}.merge(params)
139
146
  end
140
147
 
141
148
  def get_media_counts(params = {})
@@ -143,19 +150,23 @@ module Flickrie
143
150
  end
144
151
 
145
152
  def get_media_exif(media_id, params = {})
146
- get 'flickr.photos.getExif', {:photo_id => media_id}.merge(params)
153
+ get 'flickr.photos.getExif',
154
+ {:photo_id => media_id}.merge(params)
147
155
  end
148
156
 
149
- def get_media_info(media_id)
150
- get 'flickr.photos.getInfo', :photo_id => media_id
157
+ def get_media_info(media_id, params = {})
158
+ get 'flickr.photos.getInfo',
159
+ {:photo_id => media_id}.merge(params)
151
160
  end
152
161
 
153
- def get_media_sizes(media_id)
154
- get 'flickr.photos.getSizes', :photo_id => media_id
162
+ def get_media_sizes(media_id, params = {})
163
+ get 'flickr.photos.getSizes',
164
+ {:photo_id => media_id}.merge(params)
155
165
  end
156
166
 
157
- def remove_media_tag(tag_id)
158
- post 'flickr.photos.removeTag', :tag_id => tag_id
167
+ def remove_media_tag(tag_id, params = {})
168
+ post 'flickr.photos.removeTag',
169
+ {:tag_id => tag_id}.merge(params)
159
170
  end
160
171
 
161
172
  def search_media(params = {})
@@ -164,29 +175,32 @@ module Flickrie
164
175
 
165
176
  #--
166
177
  # photos.upload
167
- def check_upload_tickets(tickets)
168
- get 'flickr.photos.upload.checkTickets', :tickets => tickets
178
+ def check_upload_tickets(tickets, params = {})
179
+ get 'flickr.photos.upload.checkTickets',
180
+ {:tickets => tickets}.merge(params)
169
181
  end
170
182
 
171
183
  #--
172
184
  # photos.licenses
173
- def get_licenses
174
- get 'flickr.photos.licenses.getInfo'
185
+ def get_licenses(params = {})
186
+ get 'flickr.photos.licenses.getInfo', params
175
187
  end
176
188
 
177
189
  #--
178
190
  # photosets
179
- def get_set_info(set_id)
180
- get 'flickr.photosets.getInfo', :photoset_id => set_id
191
+ def get_set_info(set_id, params = {})
192
+ get 'flickr.photosets.getInfo',
193
+ {:photoset_id => set_id}.merge(params)
181
194
  end
182
195
 
183
- def sets_from_user(user_nsid)
184
- get 'flickr.photosets.getList', :user_id => user_nsid
196
+ def sets_from_user(user_nsid, params = {})
197
+ get 'flickr.photosets.getList',
198
+ {:user_id => user_nsid}.merge(params)
185
199
  end
186
200
 
187
201
  def media_from_set(set_id, params = {})
188
- params = {:photoset_id => set_id}.merge(params)
189
- get 'flickr.photosets.getPhotos', ensure_media(params)
202
+ get 'flickr.photosets.getPhotos',
203
+ ensure_media({:photoset_id => set_id}.merge(params))
190
204
  end
191
205
 
192
206
  private
@@ -1,7 +1,6 @@
1
1
  require 'flickrie/media/visibility'
2
2
  require 'flickrie/media/note'
3
3
  require 'flickrie/media/tag'
4
- require 'flickrie/media/ticket'
5
4
  require 'flickrie/media/exif'
6
5
  require 'flickrie/location'
7
6
  require 'date'
@@ -187,8 +186,10 @@ module Flickrie
187
186
  end
188
187
 
189
188
  def from_user(hash)
190
- hash['owner'] = hash['photo'].first['owner']
191
- hash['ownername'] = hash['photo'].first['ownername']
189
+ if hash['photo'].first
190
+ hash['owner'] = hash['photo'].first['owner']
191
+ hash['ownername'] = hash['photo'].first['ownername']
192
+ end
192
193
  hash['photo'].each do |info|
193
194
  info['visibility'] = {
194
195
  'ispublic' => info.delete('ispublic'),
@@ -28,5 +28,15 @@ module Flickrie
28
28
  @info = info
29
29
  @dates_kind = (params[:dates].nil? ? "mysql timestamp" : "unix timestamp")
30
30
  end
31
+
32
+ def self.ensure_utc(params)
33
+ params.dup.tap do |hash|
34
+ if hash[:taken_dates].is_a?(String)
35
+ hash[:taken_dates] = hash[:taken_dates].split(',').
36
+ map { |date| DateTime.parse(date) }.
37
+ map(&:to_time).map(&:getutc).join(',')
38
+ end
39
+ end
40
+ end
31
41
  end
32
42
  end
@@ -0,0 +1,24 @@
1
+ module Flickrie
2
+ class Ticket
3
+ def id; @info['id'] end
4
+ def media_id; @info['photoid'] end
5
+ alias photo_id media_id
6
+ alias video_id media_id
7
+
8
+ def complete?
9
+ @info['complete'].to_i == 1
10
+ end
11
+
12
+ def imported_at
13
+ Time.at(@info['imported'].to_i)
14
+ end
15
+
16
+ def [](key)
17
+ @info[key]
18
+ end
19
+
20
+ def initialize(info)
21
+ @info = info
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.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: 0.6.0
4
+ version: 0.6.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-07 00:00:00.000000000 Z
12
+ date: 2012-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70306140464480 !ruby/object:Gem::Requirement
16
+ requirement: &70207108480240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70306140464480
24
+ version_requirements: *70207108480240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simple_oauth
27
- requirement: &70306157035920 !ruby/object:Gem::Requirement
27
+ requirement: &70207108479120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70306157035920
35
+ version_requirements: *70207108479120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_xml
38
- requirement: &70306157033800 !ruby/object:Gem::Requirement
38
+ requirement: &70207108476020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70306157033800
46
+ version_requirements: *70207108476020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
- requirement: &70306157033420 !ruby/object:Gem::Requirement
49
+ requirement: &70207108475000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70306157033420
57
+ version_requirements: *70207108475000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: turn
60
- requirement: &70306157032800 !ruby/object:Gem::Requirement
60
+ requirement: &70207108473020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70306157032800
68
+ version_requirements: *70207108473020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
- requirement: &70306157032160 !ruby/object:Gem::Requirement
71
+ requirement: &70207108571500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70306157032160
79
+ version_requirements: *70207108571500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: webmock
82
- requirement: &70306157031740 !ruby/object:Gem::Requirement
82
+ requirement: &70207108570600 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70306157031740
90
+ version_requirements: *70207108570600
91
91
  description: This gem is a nice wrapper for the Flickr API with an intuitive interface.
92
92
  email: janko.marohnic@gmail.com
93
93
  executables: []
@@ -112,12 +112,12 @@ files:
112
112
  - lib/flickrie/media/exif.rb
113
113
  - lib/flickrie/media/note.rb
114
114
  - lib/flickrie/media/tag.rb
115
- - lib/flickrie/media/ticket.rb
116
115
  - lib/flickrie/media/visibility.rb
117
116
  - lib/flickrie/media_count.rb
118
117
  - lib/flickrie/oauth.rb
119
118
  - lib/flickrie/photo.rb
120
119
  - lib/flickrie/set.rb
120
+ - lib/flickrie/ticket.rb
121
121
  - lib/flickrie/upload_client.rb
122
122
  - lib/flickrie/user.rb
123
123
  - lib/flickrie/version.rb
@@ -1,26 +0,0 @@
1
- module Flickrie
2
- module Media
3
- class Ticket
4
- def id; @info['id'] end
5
- def media_id; @info['photoid'] end
6
- alias photo_id media_id
7
- alias video_id media_id
8
-
9
- def complete?
10
- @info['complete'].to_i == 1
11
- end
12
-
13
- def imported_at
14
- Time.at(@info['imported'].to_i)
15
- end
16
-
17
- def [](key)
18
- @info[key]
19
- end
20
-
21
- def initialize(info)
22
- @info = info
23
- end
24
- end
25
- end
26
- end