quickpress 0.2.1 → 0.3.0
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.
- checksums.yaml +4 -4
- data/bin/qp +47 -17
- data/lib/quickpress.rb +43 -0
- data/lib/quickpress/version.rb +1 -1
- data/lib/quickpress/wordpress.rb +41 -0
- data/quickpress.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23e44d958f23a9ce6ef0fa856b1562a0a2e884fd
|
|
4
|
+
data.tar.gz: 783ecebf3b8e3bde3ce30507b1ba45dcaf6d2a1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5ba2ac62489a26905b90addd46deec8fc267df161d5a665de9a61402f50c951dd7a83a2203f6af86ff1a60fb2da8ddd46afdfec2a5f37f011086b1a80f4cecb
|
|
7
|
+
data.tar.gz: 0f0d9b2159373fec701a8ac7f8396be99241b0de98afd7752cb4c44e4daee31a3ebbc8ef1b4408ae6d2524c8a6eca814353933bf3eb7cc17c8a10724b2943ec6
|
data/bin/qp
CHANGED
|
@@ -514,32 +514,62 @@ class QuickpressCLI < Thor
|
|
|
514
514
|
Quickpress::use_site(id.to_i)
|
|
515
515
|
end
|
|
516
516
|
|
|
517
|
-
# _
|
|
518
|
-
# | |
|
|
519
|
-
# |_|
|
|
517
|
+
# _ ____ _ ____ _ _ ____
|
|
518
|
+
# | |\ | | |_ \ \ / | |_ | | | | | |_
|
|
519
|
+
# |_| \| |_|__ \_\/\/ |_| |_| |_|__ |_|__
|
|
520
520
|
#
|
|
521
|
-
desc('
|
|
522
|
-
'
|
|
521
|
+
desc('new-file [FILENAME]',
|
|
522
|
+
'Uploads a file to your Wordpress site')
|
|
523
|
+
|
|
524
|
+
option('overwrite',
|
|
525
|
+
:desc => "overwrites existing file",
|
|
526
|
+
:aliases => "-o",
|
|
527
|
+
:type => :boolean)
|
|
523
528
|
|
|
524
529
|
long_desc(<<-END).remove_starting!
|
|
525
|
-
|
|
526
|
-
\
|
|
530
|
+
Will upload FILENAME to your Wordpress site, showing it's
|
|
531
|
+
\x5name and link when finished.
|
|
527
532
|
|
|
528
|
-
|
|
529
|
-
\
|
|
533
|
+
This way, you may use it within your posts by using
|
|
534
|
+
\5it's unique name or linking it directly.
|
|
530
535
|
|
|
531
|
-
|
|
536
|
+
Note that Wordpress supports only the following file types:
|
|
532
537
|
|
|
538
|
+
Images: .jpg .jpeg .png .gif
|
|
533
539
|
|
|
534
|
-
|
|
540
|
+
Documents: .pdf .doc .docx .ppt .pptx .pps .ppsx .odt
|
|
541
|
+
\x5.xls .xlsx
|
|
542
|
+
|
|
543
|
+
Audio: .mp3 .m4a .ogg .wav
|
|
544
|
+
|
|
545
|
+
Video: .mp4 .m4v .mov .wmv .avi .mpg .ogv .3gp .3g2
|
|
546
|
+
END
|
|
547
|
+
|
|
548
|
+
def new_file(filename)
|
|
549
|
+
$options.merge! options
|
|
550
|
+
|
|
551
|
+
Quickpress::new_media filename
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
# _ _ __ _____ ____ _ _ ____ __
|
|
555
|
+
# | | | | ( (` | | | |_ | | | | | |_ ( (`
|
|
556
|
+
# |_|__ |_| _)_) |_| |_| |_| |_|__ |_|__ _)_)
|
|
557
|
+
#
|
|
558
|
+
desc('list-files',
|
|
559
|
+
'Show all files uploaded on the Wordpress site.')
|
|
560
|
+
|
|
561
|
+
long_desc(<<-END).remove_starting!
|
|
562
|
+
Lists all files that were uploaded and still remain on
|
|
563
|
+
\x5the Wordpress site.
|
|
535
564
|
|
|
536
|
-
|
|
565
|
+
Note that if you're making a post that links to a file,
|
|
566
|
+
\x5you can omit your domain.
|
|
537
567
|
END
|
|
538
568
|
|
|
539
|
-
def
|
|
569
|
+
def list_files
|
|
540
570
|
$options.merge! options
|
|
541
571
|
|
|
542
|
-
Quickpress::
|
|
572
|
+
Quickpress::list_media
|
|
543
573
|
end
|
|
544
574
|
|
|
545
575
|
# _ _ __ _____ __ __ _____ ____ __
|
|
@@ -840,9 +870,9 @@ rescue StandardError => e
|
|
|
840
870
|
exit 666
|
|
841
871
|
end
|
|
842
872
|
|
|
843
|
-
$stderr.puts e
|
|
844
|
-
$stderr.puts e.message
|
|
845
|
-
$stderr.puts e.backtrace if $options[:debug]
|
|
873
|
+
$stderr.puts "Error: \"#{e}\""
|
|
874
|
+
$stderr.puts "Message: #{e.message}" if $options[:debug]
|
|
875
|
+
$stderr.puts "Backtrace: #{e.backtrace}" if $options[:debug]
|
|
846
876
|
exit 666
|
|
847
877
|
end
|
|
848
878
|
|
data/lib/quickpress.rb
CHANGED
|
@@ -527,6 +527,49 @@ module Quickpress
|
|
|
527
527
|
END
|
|
528
528
|
end
|
|
529
529
|
|
|
530
|
+
# Uploads `filename` to the blog.
|
|
531
|
+
#
|
|
532
|
+
def new_media filename
|
|
533
|
+
|
|
534
|
+
if not File.exists? filename
|
|
535
|
+
fail "File '#{filename}' doesn't exist"
|
|
536
|
+
end
|
|
537
|
+
if File.directory? filename
|
|
538
|
+
fail "Are you nuts? '#{filename}' is a directory"
|
|
539
|
+
end
|
|
540
|
+
if File.stat(filename).size.zero?
|
|
541
|
+
fail "File '#{filename}' is empty"
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
Quickpress::startup
|
|
545
|
+
|
|
546
|
+
id, link, name = nil, nil
|
|
547
|
+
|
|
548
|
+
CLI::with_status("Uploading '#{filename}'...") do
|
|
549
|
+
id, link, name = @@wp.new_media filename
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
puts <<-END.remove_starting!
|
|
553
|
+
File uploaded!
|
|
554
|
+
id: #{id}
|
|
555
|
+
link: #{link}
|
|
556
|
+
name: #{name}
|
|
557
|
+
END
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
# Shows all uploaded items.
|
|
561
|
+
def list_media
|
|
562
|
+
Quickpress::startup
|
|
563
|
+
media = @@wp.get_all_media
|
|
564
|
+
if media.empty?
|
|
565
|
+
puts "No items uploaded 'til now."
|
|
566
|
+
return
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
table = [["ID", "Filename", "Link"]] + media
|
|
570
|
+
Thor::Shell::Basic.new.print_table table
|
|
571
|
+
end
|
|
572
|
+
|
|
530
573
|
# Returns a Time Object according to String `format`.
|
|
531
574
|
#
|
|
532
575
|
# The acceptable date formats are:
|
data/lib/quickpress/version.rb
CHANGED
data/lib/quickpress/wordpress.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'rubypress'
|
|
2
|
+
require 'mimemagic'
|
|
2
3
|
|
|
3
4
|
module Quickpress
|
|
4
5
|
|
|
@@ -226,6 +227,46 @@ module Quickpress
|
|
|
226
227
|
|
|
227
228
|
status.map { |s| [s["name"], s["count"]] } # all we need
|
|
228
229
|
end
|
|
230
|
+
|
|
231
|
+
# Uploads `filename` to Wordpress, returning
|
|
232
|
+
# it's ID, URL and unique filename inside Wordpress.
|
|
233
|
+
#
|
|
234
|
+
def new_media filename
|
|
235
|
+
|
|
236
|
+
content = XMLRPC::Base64.new(File.read(filename))
|
|
237
|
+
if content.encoded.empty?
|
|
238
|
+
fail "File '#{filename}' is empty"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
mime = MimeMagic.by_path filename
|
|
242
|
+
if mime.nil?
|
|
243
|
+
fail "Unknown MIME type for '#{filename}'"
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
file = @client.uploadFile(:data => {
|
|
247
|
+
:name => File.basename(filename),
|
|
248
|
+
:bits => content,
|
|
249
|
+
:type => mime.type
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
return file['id'], file['url'], file['file']
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# Returns all media items on the blog
|
|
256
|
+
def get_all_media
|
|
257
|
+
lib = @client.getMediaLibrary
|
|
258
|
+
return [] if lib.empty?
|
|
259
|
+
|
|
260
|
+
# Getting only the fields we're interested on
|
|
261
|
+
lib.map do |m|
|
|
262
|
+
[m["attachment_id"], m["title"], m["link"]]
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def get_media id
|
|
267
|
+
@client.getMediaItem(:attachment_id => id)
|
|
268
|
+
end
|
|
269
|
+
|
|
229
270
|
end
|
|
230
271
|
end
|
|
231
272
|
|
data/quickpress.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quickpress
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandre Dantas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubypress
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: mimemagic
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: rdoc
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|