imagevenue 0.0.1 → 0.0.2

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.
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+
5
+ require 'getoptlong'
6
+ #require 'rubygems'
7
+ require 'image_venue'
8
+
9
+
10
+ options = GetoptLong.new(
11
+ ['-c', '--cookie', GetoptLong::OPTIONAL_ARGUMENT],
12
+ ['-p', '--password', GetoptLong::REQUIRED_ARGUMENT],
13
+ ['-u', '--username', GetoptLong::REQUIRED_ARGUMENT]
14
+ )
15
+ options_hash = {}
16
+ options.each do |option, argument|
17
+ options_hash[option] = argument
18
+ end
19
+ command = ARGV.shift
20
+ cookie = nil
21
+
22
+ if command == 'list'
23
+ ImageVenue.authenticate(options_hash['-u'], options_hash['-p'], cookie)
24
+ if ImageVenue.authenticate.login
25
+ ImageVenue.directory.list.each do |directory|
26
+ puts directory
27
+ end
28
+ exit(0)
29
+ else
30
+ exit(-10)
31
+ end
32
+
33
+ elsif command == 'files'
34
+ directory = ARGV.shift
35
+ unless directory.nil? or directory.empty?
36
+ ImageVenue.authenticate(options_hash['-u'], options_hash['-p'], cookie)
37
+ if ImageVenue.authenticate.login
38
+ ImageVenue.directory.files(directory).each do |file|
39
+ puts file.basename
40
+ end
41
+ exit(0)
42
+ else
43
+ exit(-10)
44
+ end
45
+ else
46
+ exit(-20)
47
+ end
48
+
49
+ elsif command == 'create'
50
+ directory = ARGV.shift
51
+ unless directory.nil? or directory.empty?
52
+ ImageVenue.authenticate(options_hash['-u'], options_hash['-p'], cookie)
53
+ if ImageVenue.authenticate.login
54
+ if ImageVenue.directory.create(directory)
55
+ exit(0)
56
+ else
57
+ exit(-30)
58
+ end
59
+ else
60
+ exit(-10)
61
+ end
62
+ else
63
+ exit(-20)
64
+ end
65
+
66
+ elsif command == 'upload'
67
+ directory = ARGV.shift
68
+ files = ARGV.clone
69
+ unless directory.nil? or directory.empty? or files.nil? or files.empty?
70
+ ImageVenue.authenticate(options_hash['-u'], options_hash['-p'], cookie)
71
+ if ImageVenue.authenticate.login
72
+ if ImageVenue.directory.select_or_create(directory)
73
+ upload = ImageVenue::Upload.new
74
+ files.each do |file|
75
+ upload_file = ImageVenue::UploadFile.from_local_path(file)
76
+ upload.add(upload_file)
77
+ end
78
+ upload.debug = true
79
+ upload.process
80
+ exit(0)
81
+ else
82
+ exit(-30)
83
+ end
84
+ else
85
+ exit(-10)
86
+ end
87
+ else
88
+ exit(-20)
89
+ end
90
+
91
+ elsif command == 'delete'
92
+ directory = ARGV.shift
93
+ unless directory.nil? or directory.empty?
94
+ ImageVenue.authenticate(options_hash['-u'], options_hash['-p'], cookie)
95
+ if ImageVenue.authenticate.login
96
+ if ImageVenue.directory.delete(directory)
97
+ exit(0)
98
+ else
99
+ exit(-30)
100
+ end
101
+ else
102
+ exit(-10)
103
+ end
104
+ else
105
+ exit(-20)
106
+ end
107
+
108
+ else
109
+ puts "USAGE: #{$0} -u <USERNAME> -p <PASSWORD> <COMMAND> [<ARGUMENT>]"
110
+ exit(-1)
111
+ end
@@ -7,6 +7,11 @@ require 'uri' unless defined?(URI)
7
7
  require 'rubygems' unless defined?(Gem)
8
8
  require 'hpricot' unless defined?(Hpricot)
9
9
 
10
+ module Kernel
11
+ class File < File
12
+ end
13
+ end
14
+
10
15
  module ImageVenue
11
16
  def self.base_url
12
17
  @base_url ||= 'http://users.imagevenue.com'
@@ -17,7 +22,7 @@ module ImageVenue
17
22
  end
18
23
 
19
24
  def self.version
20
- @version ||= [0, 0, 1]
25
+ @version ||= [0, 0, 2]
21
26
  end
22
27
 
23
28
  def self.debug
@@ -46,6 +51,3 @@ require 'image_venue/directory'
46
51
  require 'image_venue/file'
47
52
  require 'image_venue/upload'
48
53
  require 'image_venue/upload_file'
49
-
50
- if $0 == __FILE__
51
- end
@@ -64,12 +64,12 @@ module ImageVenue
64
64
  def login
65
65
  puts_debug "Trying to login ..."
66
66
  response = Net::HTTP.post_form(self.class.login_uri, self.login_params)
67
- unless response.header['Set-Cookie'].blank?
67
+ unless response.header['Set-Cookie'].nil? or response.header['Set-Cookie'].empty?
68
68
  self.cookie = {}
69
69
  self.cookie[self.class.cookie_user_key] = $1 if response.header['Set-Cookie'] =~ /#{Regexp.escape(self.class.cookie_user_key)}=(.+?)[,;]/
70
70
  self.cookie[self.class.cookie_root_key] = $1 if response.header['Set-Cookie'] =~ /#{Regexp.escape(self.class.cookie_root_key)}=(\d+)/
71
71
  response_timestamp = Net::HTTP.get_response(ImageVenue.base_uri)
72
- unless response_timestamp.header['Set-Cookie'].blank?
72
+ unless response_timestamp.header['Set-Cookie'].nil? or response_timestamp.header['Set-Cookie'].empty?
73
73
  self.cookie[self.class.cookie_timestamp_key] = $1 if response_timestamp.header['Set-Cookie'] =~ /#{Regexp.escape(self.class.cookie_timestamp_key)}=(.+?)[,;]/
74
74
  puts_debug "Login successfull!"
75
75
  return true
@@ -143,7 +143,7 @@ module ImageVenue
143
143
  response = Net::HTTP.start(self.class.select_uri.host, self.class.select_uri.port) do |http|
144
144
  http.request(request)
145
145
  end
146
- if response.is_a?(Net::HTTPFound) and not response.header['Set-Cookie'].blank?
146
+ if response.is_a?(Net::HTTPFound) and not (response.header['Set-Cookie'].nil? or response.header['Set-Cookie'].empty?)
147
147
  self.selected_directory = directory
148
148
  ImageVenue.authenticate.cookie[self.class.cookie_directory_key] = directory
149
149
  puts_debug "Directory successfully selected!"
@@ -173,7 +173,7 @@ module ImageVenue
173
173
  response = Net::HTTP.start(self.class.create_uri.host, self.class.create_uri.port) do |http|
174
174
  http.request(request)
175
175
  end
176
- if response.is_a?(Net::HTTPSuccess) and not response.header['Set-Cookie'].blank?
176
+ if response.is_a?(Net::HTTPSuccess) and not (response.header['Set-Cookie'].nil? or response.header['Set-Cookie'].empty?)
177
177
  self.selected_directory = directory
178
178
  self.directories.insert(0, directory)
179
179
  ImageVenue.authenticate.cookie[self.class.cookie_directory_key] = directory
File without changes
@@ -73,9 +73,9 @@ module ImageVenue
73
73
  end
74
74
  end
75
75
 
76
- def add(image_venue_file)
77
- if image_venue_file.is_a?(ImageVenue::UploadFile)
78
- self.files.push(image_venue_file)
76
+ def add(upload_file)
77
+ if upload_file.is_a?(ImageVenue::UploadFile)
78
+ self.files.push(upload_file)
79
79
  return true
80
80
  else
81
81
  return false
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nowak
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-16 00:00:00 +01:00
13
- default_executable:
12
+ date: 2009-02-20 00:00:00 +01:00
13
+ default_executable: image_venue
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hpricot
@@ -24,28 +24,29 @@ dependencies:
24
24
  version:
25
25
  description: Accessing your ImageVenue account via a Ruby-Library. With support for listing, creating, deleting directories and listing, uploading and deleting files. Generates BB-Code or HTML-Code four you, too.
26
26
  email: michael.nowak@thexsystem.de
27
- executables: []
28
-
27
+ executables:
28
+ - image_venue
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
- - image_venue.rb
35
- - image_venue/authenticate.rb
36
- - image_venue/directory.rb
37
- - image_venue/file.rb
38
- - image_venue/net_http_get_extensions.rb
39
- - image_venue/net_http_post_extensions.rb
40
- - image_venue/upload.rb
41
- - image_venue/upload_file.rb
34
+ - bin/image_venue
35
+ - lib/image_venue/authenticate.rb
36
+ - lib/image_venue/directory.rb
37
+ - lib/image_venue/file.rb
38
+ - lib/image_venue/net_http_get_extensions.rb
39
+ - lib/image_venue/net_http_post_extensions.rb
40
+ - lib/image_venue/upload.rb
41
+ - lib/image_venue/upload_file.rb
42
+ - lib/image_venue.rb
42
43
  has_rdoc: false
43
- homepage:
44
+ homepage: http://imagevenue.rubyforge.org/
44
45
  post_install_message:
45
46
  rdoc_options: []
46
47
 
47
48
  require_paths:
48
- - .
49
+ - lib
49
50
  required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="