imagevenue 0.0.2 → 0.0.3

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.
@@ -102,19 +102,12 @@ module ImageVenue
102
102
  if name.to_s =~ /\[\]$/
103
103
  files.each do |file|
104
104
  body.write "\r\n--#{boundary1}\r\n"
105
- body.write "content-disposition: form-data; name=\"#{name}\""
105
+ body.write "content-disposition: form-data; name=\"#{name}\"; filename=\"#{file.base_name}\"\r\n"
106
106
  # single-file multipart is different
107
- if file.filename
108
- # right in content-dispo line
109
- body.write "; filename=\"#{file.filename}\"\r\n"
110
- else
111
- body.write "\r\n"
112
- end
113
-
114
107
  body.write "Content-Type: #{file.content_type}\r\n"
115
108
  body.write "Content-Transfer-Encoding: binary\r\n"
116
109
  body.write "\r\n"
117
- FileUtils.copy_stream(file, body)
110
+ FileUtils.copy_stream(Kernel::File.open(file.name, 'rb'), body)
118
111
  end
119
112
  else
120
113
  body.write "\r\n--#{boundary1}\r\n"
@@ -126,18 +119,12 @@ module ImageVenue
126
119
 
127
120
  files.each do |file|
128
121
  body.write "\r\n--#{boundary2}\r\n"
129
-
130
122
  body.write "Content-disposition: attachment"
131
- if file.filename
132
- body.write "; filename=\"#{file.filename}\"\r\n"
133
- else
134
- body.write "\r\n"
135
- end
136
-
137
- body.write "Content-Type: #{file.mimetype}\r\n"
123
+ body.write "; filename=\"#{file.base_name}\"\r\n"
124
+ body.write "Content-Type: #{file.content_type}\r\n"
138
125
  body.write "Content-Transfer-Encoding: binary\r\n"
139
126
  body.write "\r\n"
140
- FileUtils.copy_stream(file, body)
127
+ FileUtils.copy_stream(Kernel::File.open(file.name, 'rb'), body)
141
128
  end
142
129
  body.write "\r\n--#{boundary2}--\r\n"
143
130
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagevenue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nowak
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-20 00:00:00 +01:00
12
+ date: 2009-10-27 00:00:00 +01:00
13
13
  default_executable: image_venue
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,13 +32,12 @@ extra_rdoc_files: []
32
32
 
33
33
  files:
34
34
  - bin/image_venue
35
- - lib/image_venue/authenticate.rb
35
+ - lib/image_venue/cli.rb
36
+ - lib/image_venue/connection.rb
36
37
  - lib/image_venue/directory.rb
37
38
  - lib/image_venue/file.rb
38
39
  - lib/image_venue/net_http_get_extensions.rb
39
40
  - lib/image_venue/net_http_post_extensions.rb
40
- - lib/image_venue/upload.rb
41
- - lib/image_venue/upload_file.rb
42
41
  - lib/image_venue.rb
43
42
  has_rdoc: false
44
43
  homepage: http://imagevenue.rubyforge.org/
@@ -1,137 +0,0 @@
1
- module ImageVenue
2
- class Upload
3
- class << self
4
- def upload_uri
5
- @upload_uri ||= URI.parse(ImageVenue.base_url + '/upload.php')
6
- end
7
-
8
- def upload_action_key
9
- @upload_action_key ||= 'action'
10
- end
11
-
12
- def upload_user_key
13
- @upload_user_key ||= 'user_id'
14
- end
15
-
16
- def upload_file_key
17
- @upload_file_key ||= 'userfile[]'
18
- end
19
-
20
- def upload_directory_key
21
- @upload_directory_key ||= 'upload_dir'
22
- end
23
-
24
- def upload_content_key
25
- @upload_content_key ||= 'imgcontent'
26
- end
27
-
28
- def upload_content_safe
29
- @upload_content_safe ||= 'safe'
30
- end
31
- alias :upload_content_family :upload_content_safe
32
-
33
- def upload_content_notsafe
34
- @upload_content_notsafe ||= 'notsafe'
35
- end
36
- alias :upload_content_adult :upload_content_notsafe
37
-
38
- def upload_resize_key
39
- @upload_resize_key ||= 'img_resize'
40
- end
41
-
42
- def upload_maximum_files
43
- @upload_maximum_files ||= 10
44
- end
45
-
46
- def upload_maximum_size
47
- @upload_maximum_size ||= 3 * 1024 * 1024 # 3 MByte
48
- end
49
-
50
- def upload_image_types
51
- @upload_image_types ||= ['jpeg', 'jpg']
52
- end
53
- end
54
-
55
- attr_accessor :files
56
- attr_accessor :debug
57
-
58
- def initialize
59
- self.files = []
60
- return nil
61
- end
62
-
63
- def debug?
64
- (ImageVenue.debug or self.debug) ? true : false
65
- end
66
-
67
- def puts_debug(*args)
68
- if self.debug?
69
- puts(*args)
70
- return true
71
- else
72
- return false
73
- end
74
- end
75
-
76
- def add(upload_file)
77
- if upload_file.is_a?(ImageVenue::UploadFile)
78
- self.files.push(upload_file)
79
- return true
80
- else
81
- return false
82
- end
83
- end
84
-
85
- def upload
86
- files = []
87
- self.files.each do |file|
88
- puts_debug "Trying to upload file `#{file.filename}` to directory `#{file.directory}` ..."
89
- request = Net::HTTP::Post.new(self.class.upload_uri.path)
90
- request.set_multipart_data(self.upload_file_params(file), self.upload_form_params(file.directory))
91
- request.header['cookie'] = [ImageVenue.authenticate.cookie_as_string]
92
- response = Net::HTTP.start(self.class.upload_uri.host, self.class.upload_uri.port) do |http|
93
- http.request(request)
94
- end
95
- if response.is_a?(Net::HTTPSuccess)
96
- file = ImageVenue::File.parse_upload(response.body)
97
- puts_debug "File successfully uploaded!"
98
- else
99
- file = false
100
- puts_debug "File upload failed!"
101
- end
102
- files.push(file)
103
- end
104
- return files
105
- end
106
- alias :process :upload
107
-
108
- def upload_file_params(file_or_files=nil)
109
- {
110
- self.class.upload_file_key => file_or_files
111
- }
112
- end
113
-
114
- def upload_form_params(directory=nil, content_safe=false, resize=nil)
115
- unless directory.nil?
116
- ImageVenue.directory.select_or_create(directory)
117
- end
118
- params = {
119
- self.class.upload_action_key => '1',
120
- self.class.upload_directory_key => ImageVenue.directory.selected,
121
- self.class.upload_user_key => ImageVenue.authenticate.cookie[ImageVenue::Authenticate.cookie_user_key],
122
- self.class.upload_content_key => (content_safe) ? self.class.upload_content_safe : self.class.upload_content_notsafe,
123
- self.class.upload_resize_key => resize || ''
124
- }
125
- return params
126
- end
127
-
128
- def status
129
- return nil
130
- end
131
-
132
- def reset
133
- self.files = []
134
- return self
135
- end
136
- end
137
- end
@@ -1,84 +0,0 @@
1
- module ImageVenue
2
- class UploadFile
3
- class << self
4
- def content_types
5
- @content_types ||= ['jpeg', 'jpg']
6
- end
7
-
8
- def from_local_path(path)
9
- file = Kernel::File.open(path, 'rb')
10
- content_type = `file --mime --brief #{file.path}`.strip
11
- filename = Kernel::File.basename(file.path)
12
- data = file.read
13
- new = self.new(content_type, filename, data)
14
- return new
15
- end
16
- alias :from_path :from_local_path
17
-
18
- def from_files(files, directory)
19
- news = []
20
- files.each do |file|
21
- new = self.new(file.content_type, file.original_filename, file, directory)
22
- news.push(new)
23
- end
24
- return news
25
- end
26
-
27
- def upload_file_test
28
- @upload_file_test ||= self.from_local_path(Kernel::File.join(Kernel::File.dirname(__FILE__), 'test.jpg'))
29
- end
30
- end
31
-
32
- attr_accessor :content_type
33
- attr_accessor :filename
34
- attr_accessor :data
35
- attr_accessor :directory
36
- attr_accessor :debug
37
-
38
- def initialize(content_type, filename, data, directory=nil)
39
- self.content_type = content_type
40
- self.filename = filename
41
- self.data = data
42
- self.directory = directory
43
- return nil
44
- end
45
-
46
- def debug?
47
- (ImageVenue.debug or self.debug) ? true : false
48
- end
49
-
50
- def puts_debug(*args)
51
- if self.debug?
52
- puts(*args)
53
- return true
54
- else
55
- return false
56
- end
57
- end
58
-
59
- def data_io
60
- @data_io ||= StringIO.new(self.data) if self.data.is_a?(String)
61
- @data_io ||= self.data
62
- return @data_io
63
- end
64
-
65
- def read(bytes=nil)
66
- self.data_io.read(bytes)
67
- end
68
-
69
- def rewind
70
- self.data_io.rewind
71
- end
72
-
73
- def size
74
- if self.data.is_a?(String)
75
- @size ||= self.data.length
76
- elsif self.data.respond_to?(:size)
77
- @size ||= self.data.size
78
- elsif self.data.respond_to?(:length)
79
- @size ||= self.data.length
80
- end
81
- return @size
82
- end
83
- end
84
- end