flickrie 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Flickrie changelog
2
2
 
3
+ ## Version 0.4.1
4
+
5
+ - handle file uploads for Rails and Sinatra smarter (see [this wiki](https://github.com/janko-m/flickrie/wiki/Some-tips.md), tip #7)
6
+
3
7
  ## Version 0.4.0
4
8
 
5
9
  - covered `flickr.photos.getContactsPhotos`
data/README.md CHANGED
@@ -247,7 +247,7 @@ basis of this gem.
247
247
 
248
248
  ## Changelog
249
249
 
250
- You can see the changelog [here]((https://github.com/janko-m/flickrie/blob/master/CHANGELOG.md).
250
+ You can see the changelog [here](https://github.com/janko-m/flickrie/blob/master/CHANGELOG.md).
251
251
 
252
252
  ## License
253
253
 
@@ -39,13 +39,16 @@ module Flickrie
39
39
  class UploadClient < Faraday::Connection
40
40
  def upload(media, params = {})
41
41
  media_file = get_file(media, params[:mime_type])
42
- post "upload", {:photo => media_file}.merge(params)
42
+ media_title = get_title(media)
43
+ post "upload", {:photo => media_file,
44
+ :title => media_title}.merge(params)
43
45
  end
44
46
 
45
47
  def replace(media, media_id, params = {})
46
- media_file = get_file(media)
48
+ media_file = get_file(media, params[:mime_type])
49
+ media_title = get_title(media)
47
50
  post "replace", {:photo => media_file,
48
- :photo_id => media_id}.merge(params)
51
+ :photo_id => media_id, :title => media_title}.merge(params)
49
52
  end
50
53
 
51
54
  private
@@ -70,11 +73,21 @@ module Flickrie
70
73
  }.freeze
71
74
 
72
75
  def get_file(object, mime_type = nil)
73
- if object.is_a?(String)
74
- Faraday::UploadIO.new(object, mime_type || get_mime_type(object))
75
- else
76
- object
76
+ if object.class.name == "String"
77
+ # file path
78
+ file_path = object
79
+ mime_type ||= get_mime_type(file_path)
80
+ elsif object.class.name == "ActionDispatch::Http::UploadedFile"
81
+ # Rails
82
+ file_path = object.tempfile
83
+ mime_type ||= object.content_type
84
+ elsif object.class.name == "Hash"
85
+ # Sinatra
86
+ file_path = object[:tempfile].path
87
+ mime_type ||= object[:type]
77
88
  end
89
+
90
+ Faraday::UploadIO.new(file_path, mime_type)
78
91
  end
79
92
 
80
93
  def get_mime_type(file_path)
@@ -84,5 +97,18 @@ module Flickrie
84
97
  rescue NoMethodError
85
98
  raise Error, "Don't know mime type for this extension (#{extension})"
86
99
  end
100
+
101
+ def get_title(object)
102
+ filename =
103
+ if object.class.name == "String"
104
+ File.basename(object)
105
+ elsif object.class.name == "ActionDispatch::Http::UploadedFile"
106
+ object.original_filename
107
+ elsif object.class.name == "Hash"
108
+ object[:filename]
109
+ end
110
+
111
+ filename.match(/\.\w{3,4}$/).pre_match
112
+ end
87
113
  end
88
114
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.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.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70095977665920 !ruby/object:Gem::Requirement
16
+ requirement: &70287090746520 !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: *70095977665920
24
+ version_requirements: *70287090746520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simple_oauth
27
- requirement: &70095977665300 !ruby/object:Gem::Requirement
27
+ requirement: &70287090746080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70095977665300
35
+ version_requirements: *70287090746080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_xml
38
- requirement: &70095977664520 !ruby/object:Gem::Requirement
38
+ requirement: &70287090745640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70095977664520
46
+ version_requirements: *70287090745640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
- requirement: &70095977662960 !ruby/object:Gem::Requirement
49
+ requirement: &70287090745060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70095977662960
57
+ version_requirements: *70287090745060
58
58
  description: This gem is a nice wrapper for the Flickr API with an intuitive interface.
59
59
  email:
60
60
  - janko.marohnic@gmail.com