quickpress 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/bin/qp +91 -10
- data/lib/quickpress.rb +165 -65
- data/lib/quickpress/version.rb +1 -1
- data/lib/quickpress/wordpress.rb +48 -71
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6edfa1e92e412d704094506d439edc28591591
|
4
|
+
data.tar.gz: c4cac17e84ef4669867f4982482bebc4ac64f6fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7eb9fec72e5d5540d36231df0c0748a3b3d2f4c27ee4851e0e60901d518341d3a59c2872112b67822dc7bd04bee268bceb1f062b3338b7cb349e55e77d94aed
|
7
|
+
data.tar.gz: 8b00ca90979ff3caa1d59c1704fb2286df55534a297ab5aff5c554ef031aa3718475a46f620e0f4479d2f6a1cc8d219bf3cc816a429db5dc4ba58af96eb41f87
|
data/README.md
CHANGED
@@ -164,6 +164,12 @@ Here's how you can do it:
|
|
164
164
|
An easy way is to help on documentation. For that, simply head up
|
165
165
|
for [the wiki][wiki] and start editing things.
|
166
166
|
|
167
|
+
### Contributors
|
168
|
+
|
169
|
+
These are people who've added to the project, in order of arrival:
|
170
|
+
|
171
|
+
* **Hanmac** on *Freenode's #ruby*: Fixed issue #1.
|
172
|
+
|
167
173
|
## Contact
|
168
174
|
|
169
175
|
Hi, I'm Alexandre Dantas! Thanks for having interest in this project.
|
@@ -177,7 +183,7 @@ Please take the time to visit any of the links below.
|
|
177
183
|
[thor]:http://whatisthor.com/
|
178
184
|
[rubypress]:https://github.com/zachfeldman/rubypress
|
179
185
|
[wiki]:https://github.com/alexdantas/quickpress/wiki
|
180
|
-
[gem]:https://rubygems.org/
|
186
|
+
[gem]:https://rubygems.org/gems/quickpress/
|
181
187
|
[blogpost]:http://srackham.wordpress.com/blogpost-readme/
|
182
188
|
[versioning]:http://semver.org/
|
183
189
|
|
data/bin/qp
CHANGED
@@ -62,6 +62,17 @@ class QuickpressCLI < Thor
|
|
62
62
|
:aliases => "-c",
|
63
63
|
:type => :string)
|
64
64
|
|
65
|
+
option('date',
|
66
|
+
:banner => "\"date format (see below)\"",
|
67
|
+
:desc => "date to create post",
|
68
|
+
:aliases => "-d",
|
69
|
+
:type => :string)
|
70
|
+
|
71
|
+
option('status',
|
72
|
+
:desc => "status of the post",
|
73
|
+
:aliases => "-s",
|
74
|
+
:type => :string)
|
75
|
+
|
65
76
|
long_desc(<<-END).remove_starting!
|
66
77
|
If FILENAME is given, will post it to your Wordpress site.
|
67
78
|
|
@@ -74,6 +85,27 @@ class QuickpressCLI < Thor
|
|
74
85
|
|
75
86
|
$ qp new-post file.md -t "My Title" -c "cat1, cat2, cat3"
|
76
87
|
|
88
|
+
The --date option allows you to set a date on which the post
|
89
|
+
\x5will be created. It is a string with a format that MUST be
|
90
|
+
\x5one of the following:
|
91
|
+
|
92
|
+
\x5 1. "minute:hour"
|
93
|
+
\x5 2. "minute:hour day"
|
94
|
+
\x5 3. "minute:hour day-month"
|
95
|
+
\x5 4. "minute:hour day-month-year"
|
96
|
+
|
97
|
+
If one of the fields is not specified, will get the
|
98
|
+
\x5remaining ones from the current date. For example:
|
99
|
+
|
100
|
+
$ qp new-post file.adoc -d "15:24 22-4"
|
101
|
+
|
102
|
+
The --status option says how a post will behave when uploaded.
|
103
|
+
\x5Valid options are the following (case insensitive):
|
104
|
+
|
105
|
+
\x5 * draft: visible only on admin area
|
106
|
+
\x5 * publish: (default) post right away (or on --date)
|
107
|
+
\x5 * private: like "publish", but visible only to you
|
108
|
+
|
77
109
|
Notes:
|
78
110
|
|
79
111
|
* Set default text editor with the `EDITOR` environment variable.
|
@@ -171,6 +203,12 @@ class QuickpressCLI < Thor
|
|
171
203
|
:desc => "upload even if no changes were made",
|
172
204
|
:aliases => "-f")
|
173
205
|
|
206
|
+
option('date',
|
207
|
+
:banner => "\"date format (see below)\"",
|
208
|
+
:desc => "date to create post",
|
209
|
+
:aliases => "-d",
|
210
|
+
:type => :string)
|
211
|
+
|
174
212
|
long_desc(<<-END).remove_starting!
|
175
213
|
If FILENAME is given, will make the post with ID to
|
176
214
|
\x5have the contents of that file.
|
@@ -190,6 +228,9 @@ class QuickpressCLI < Thor
|
|
190
228
|
|
191
229
|
That would mantain the current title and categories.
|
192
230
|
|
231
|
+
The --date option allows you to set a new date for this post.
|
232
|
+
\x5See `qp new-post` for info on the string format.
|
233
|
+
|
193
234
|
See `qp new-post`, same notes apply here.
|
194
235
|
END
|
195
236
|
|
@@ -217,6 +258,17 @@ class QuickpressCLI < Thor
|
|
217
258
|
:aliases => "-t",
|
218
259
|
:type => :string)
|
219
260
|
|
261
|
+
option('date',
|
262
|
+
:banner => "\"date format (see below)\"",
|
263
|
+
:desc => "date to create post",
|
264
|
+
:aliases => "-d",
|
265
|
+
:type => :string)
|
266
|
+
|
267
|
+
option('status',
|
268
|
+
:desc => "status of the post",
|
269
|
+
:aliases => "-s",
|
270
|
+
:type => :string)
|
271
|
+
|
220
272
|
long_desc <<-END.remove_starting!
|
221
273
|
If FILENAME is given, will send it as a page to your
|
222
274
|
\x5Wordpress site.
|
@@ -225,6 +277,13 @@ class QuickpressCLI < Thor
|
|
225
277
|
\x5wait for you to write a page. After you save it, will send
|
226
278
|
\x5that.
|
227
279
|
|
280
|
+
The --date option allows you to set a date on which the page
|
281
|
+
\x5will be created. See help on `qp new-post` to know
|
282
|
+
\x5the format of the date string.
|
283
|
+
|
284
|
+
The --status option says how a post will behave when uploaded.
|
285
|
+
\x5See help on `qp new-post` to see valid options.
|
286
|
+
|
228
287
|
Notes:
|
229
288
|
|
230
289
|
* Set default text editor with the `EDITOR` environment variable.
|
@@ -315,6 +374,12 @@ class QuickpressCLI < Thor
|
|
315
374
|
:desc => "upload even if no changes were made",
|
316
375
|
:aliases => "-f")
|
317
376
|
|
377
|
+
option('date',
|
378
|
+
:banner => "\"date format (see below)\"",
|
379
|
+
:desc => "date to create post",
|
380
|
+
:aliases => "-d",
|
381
|
+
:type => :string)
|
382
|
+
|
318
383
|
long_desc(<<-END).remove_starting!
|
319
384
|
If FILENAME is given, will make the page with ID to
|
320
385
|
\x5have the contents of that file.
|
@@ -334,6 +399,9 @@ class QuickpressCLI < Thor
|
|
334
399
|
|
335
400
|
That would mantain the current title.
|
336
401
|
|
402
|
+
The --date option allows you to set a new date for this page.
|
403
|
+
\x5See help on `qp new-post` for info on the string format.
|
404
|
+
|
337
405
|
See `new-page`, same notes there apply here.
|
338
406
|
END
|
339
407
|
|
@@ -686,14 +754,6 @@ begin
|
|
686
754
|
# Well, at least I'm not polluting the whole code
|
687
755
|
# with this `rescue` stuff.
|
688
756
|
|
689
|
-
rescue Net::ReadTimeout
|
690
|
-
$stderr.puts <<-END.remove_starting!
|
691
|
-
|
692
|
-
* Connection took too long.
|
693
|
-
Check your internet settings and try again.
|
694
|
-
END
|
695
|
-
exit 666
|
696
|
-
|
697
757
|
rescue XMLRPC::FaultException => e
|
698
758
|
if e.message =~ /Incorrect username or password/
|
699
759
|
|
@@ -709,6 +769,15 @@ rescue XMLRPC::FaultException => e
|
|
709
769
|
end
|
710
770
|
exit 666
|
711
771
|
|
772
|
+
# Ruby 1.9.x don't have Net::ReadTimeout - spits out a NameError
|
773
|
+
rescue Net.const_defined?(:ReadTimeout) ? Net::ReadTimeout : EOFError
|
774
|
+
$stderr.puts <<-END.remove_starting!
|
775
|
+
|
776
|
+
* Connection took too long.
|
777
|
+
Check your internet settings and try again.
|
778
|
+
END
|
779
|
+
exit 666
|
780
|
+
|
712
781
|
rescue ArgumentError => arg
|
713
782
|
if arg.message =~ /Wrong protocol specified/
|
714
783
|
$stderr.puts <<-END.remove_starting!
|
@@ -716,6 +785,14 @@ rescue ArgumentError => arg
|
|
716
785
|
Please use `http` or `https`.
|
717
786
|
END
|
718
787
|
exit 666
|
788
|
+
|
789
|
+
elsif arg.message =~ /argument out of range/
|
790
|
+
$stderr.puts <<-END.remove_starting!
|
791
|
+
* Invalid date specified.
|
792
|
+
Check `qp new-post` for valid date format.
|
793
|
+
END
|
794
|
+
exit 666
|
795
|
+
|
719
796
|
else
|
720
797
|
$stderr.puts arg.backtrace if $options[:debug]
|
721
798
|
end
|
@@ -735,6 +812,10 @@ rescue LoadError => l
|
|
735
812
|
END
|
736
813
|
exit 666
|
737
814
|
|
815
|
+
rescue String => s
|
816
|
+
$stderr.puts s
|
817
|
+
exit 666
|
818
|
+
|
738
819
|
rescue StandardError => e
|
739
820
|
|
740
821
|
if e.message =~ /Wrong content-type/
|
@@ -748,8 +829,8 @@ rescue StandardError => e
|
|
748
829
|
$stderr.puts <<-END.remove_starting!
|
749
830
|
|
750
831
|
* Connection error!
|
751
|
-
Either site doesn't exist or there's
|
752
|
-
|
832
|
+
Either the site doesn't exist or there's something
|
833
|
+
wrong with your internet connection.
|
753
834
|
END
|
754
835
|
|
755
836
|
if Quickpress::CLI::ask("Wanna retry?")
|
data/lib/quickpress.rb
CHANGED
@@ -7,6 +7,7 @@ require 'quickpress/wordpress'
|
|
7
7
|
require 'quickpress/cli'
|
8
8
|
require 'quickpress/options'
|
9
9
|
require 'digest/md5'
|
10
|
+
require 'net/http'
|
10
11
|
|
11
12
|
class String
|
12
13
|
# Removes starting whitespace.
|
@@ -49,7 +50,9 @@ module Quickpress
|
|
49
50
|
|
50
51
|
@@username = nil
|
51
52
|
@@password = nil
|
52
|
-
|
53
|
+
|
54
|
+
# Actual Wordpress connection Object
|
55
|
+
@@wp = nil
|
53
56
|
|
54
57
|
# Supported templating languages and their file extensions.
|
55
58
|
@@supported_markup = [["markdown" , '.md'],
|
@@ -158,14 +161,14 @@ module Quickpress
|
|
158
161
|
# Will try to connect here.
|
159
162
|
# Might take a while.
|
160
163
|
CLI::with_status("Connecting...") do
|
161
|
-
@@
|
164
|
+
@@wp = Wordpress.new(address, @@username, @@password)
|
162
165
|
end
|
163
166
|
|
164
167
|
puts <<-END.remove_starting!
|
165
168
|
|
166
|
-
Title: #{@@
|
167
|
-
Tagline: #{@@
|
168
|
-
Url: #{@@
|
169
|
+
Title: #{@@wp.title}
|
170
|
+
Tagline: #{@@wp.tagline}
|
171
|
+
Url: #{@@wp.url}
|
169
172
|
END
|
170
173
|
|
171
174
|
answer = CLI::ask "Is that right?"
|
@@ -432,7 +435,7 @@ module Quickpress
|
|
432
435
|
|
433
436
|
# Will show categories in columns of n
|
434
437
|
columns = 5
|
435
|
-
table = @@
|
438
|
+
table = @@wp.categories.each_slice(columns).to_a
|
436
439
|
|
437
440
|
puts
|
438
441
|
Thor::Shell::Basic.new.print_table table
|
@@ -441,7 +444,7 @@ module Quickpress
|
|
441
444
|
# Pretty-prints all options of the Wordpress site.
|
442
445
|
def list_options
|
443
446
|
Quickpress::startup
|
444
|
-
options = @@
|
447
|
+
options = @@wp.get_options
|
445
448
|
|
446
449
|
puts
|
447
450
|
Thor::Shell::Basic.new.print_table options
|
@@ -450,7 +453,7 @@ module Quickpress
|
|
450
453
|
# Pretty-prints all users currently registered on the site.
|
451
454
|
def list_users
|
452
455
|
Quickpress::startup
|
453
|
-
users = @@
|
456
|
+
users = @@wp.get_users
|
454
457
|
|
455
458
|
users.each do |user|
|
456
459
|
puts
|
@@ -466,13 +469,15 @@ module Quickpress
|
|
466
469
|
# If successful, will store page id and link
|
467
470
|
id, link = nil, nil
|
468
471
|
|
469
|
-
|
472
|
+
title = $options[:title]
|
473
|
+
if title.nil?
|
474
|
+
title = CLI::get "Title:"
|
475
|
+
end
|
470
476
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
end
|
477
|
+
date = Quickpress::date $options[:date]
|
478
|
+
status = Quickpress::status $options[:status]
|
479
|
+
|
480
|
+
if what == :post
|
476
481
|
|
477
482
|
categories = $options[:category]
|
478
483
|
if categories.nil?
|
@@ -483,7 +488,7 @@ module Quickpress
|
|
483
488
|
puts "Tab-completion works."
|
484
489
|
puts "(will create non-existing categories automatically)"
|
485
490
|
|
486
|
-
categories = CLI::tab_complete("Post categories:", @@
|
491
|
+
categories = CLI::tab_complete("Post categories:", @@wp.categories)
|
487
492
|
end
|
488
493
|
|
489
494
|
cats = []
|
@@ -491,29 +496,27 @@ module Quickpress
|
|
491
496
|
|
492
497
|
CLI::with_status("Posting...") do
|
493
498
|
|
494
|
-
id, link = @@
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
499
|
+
id, link = @@wp.new_post(:post_status => 'publish',
|
500
|
+
:post_date => date,
|
501
|
+
:post_title => title,
|
502
|
+
:post_content => html,
|
503
|
+
:post_status => status,
|
504
|
+
:terms_names => {
|
505
|
+
:category => cats
|
506
|
+
})
|
501
507
|
end
|
502
508
|
puts "Post successful!"
|
503
509
|
|
504
510
|
elsif what == :page
|
505
|
-
title = $options[:title]
|
506
|
-
if title.nil?
|
507
|
-
title = CLI::get "Page title:"
|
508
|
-
end
|
509
511
|
|
510
512
|
CLI::with_status("Creating page...") do
|
511
513
|
|
512
|
-
id, link = @@
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
514
|
+
id, link = @@wp.new_post(:post_status => 'publish',
|
515
|
+
:post_date => [],
|
516
|
+
:post_title => title,
|
517
|
+
:post_content => html,
|
518
|
+
:post_status => status,
|
519
|
+
:post_type => 'page')
|
517
520
|
end
|
518
521
|
puts "Page created!"
|
519
522
|
end
|
@@ -524,6 +527,92 @@ module Quickpress
|
|
524
527
|
END
|
525
528
|
end
|
526
529
|
|
530
|
+
# Returns a Time Object according to String `format`.
|
531
|
+
#
|
532
|
+
# The acceptable date formats are:
|
533
|
+
#
|
534
|
+
# * `minute:hour`
|
535
|
+
# * `minute:hour day`
|
536
|
+
# * `minute:hour day-month`
|
537
|
+
# * `minute:hour day-month-year`
|
538
|
+
#
|
539
|
+
# Whenever there's a non-specified field
|
540
|
+
# (like year, for example) we'll get from the current
|
541
|
+
# date.
|
542
|
+
#
|
543
|
+
# So if you only provide `minute:hour`, it'll return
|
544
|
+
# a Time Object with the current day, month and year.
|
545
|
+
#
|
546
|
+
def date(format=nil)
|
547
|
+
|
548
|
+
# When sending [] as `:post_date` it tells Wordpress
|
549
|
+
# to post instantly.
|
550
|
+
return [] if format.nil?
|
551
|
+
|
552
|
+
# Allowed date formats
|
553
|
+
full_fmt = /(\d{1,2}):(\d{2}) (\d{1,2})-(\d{1,2})-(\d{4})/
|
554
|
+
month_fmt = /(\d{1,2}):(\d{2}) (\d{1,2})-(\d{1,2})/
|
555
|
+
day_fmt = /(\d{1,2}):(\d{2}) (\d{1,2})/
|
556
|
+
hours_fmt = /(\d{1,2}):(\d{2})/
|
557
|
+
|
558
|
+
time = nil
|
559
|
+
case format
|
560
|
+
when full_fmt
|
561
|
+
year = format[full_fmt, 5].to_i
|
562
|
+
month = format[full_fmt, 4].to_i
|
563
|
+
day = format[full_fmt, 3].to_i
|
564
|
+
minute = format[full_fmt, 2].to_i
|
565
|
+
hour = format[full_fmt, 1].to_i
|
566
|
+
|
567
|
+
time = Time.new(year, month, day, hour, minute)
|
568
|
+
|
569
|
+
when month_fmt then
|
570
|
+
month = format[month_fmt, 4].to_i
|
571
|
+
day = format[month_fmt, 3].to_i
|
572
|
+
minute = format[month_fmt, 2].to_i
|
573
|
+
hour = format[month_fmt, 1].to_i
|
574
|
+
|
575
|
+
time = Time.new(Time.now.year,
|
576
|
+
month, day, hour, minute)
|
577
|
+
|
578
|
+
when day_fmt then
|
579
|
+
day = format[day_fmt, 3].to_i
|
580
|
+
minute = format[day_fmt, 2].to_i
|
581
|
+
hour = format[day_fmt, 1].to_i
|
582
|
+
|
583
|
+
time = Time.new(Time.now.year, Time.now.month,
|
584
|
+
day, hour, minute)
|
585
|
+
|
586
|
+
when hours_fmt then
|
587
|
+
minute = format[hours_fmt, 2].to_i
|
588
|
+
hour = format[hours_fmt, 1].to_i
|
589
|
+
|
590
|
+
time = Time.new(Time.now.year, Time.now.month, Time.now.day,
|
591
|
+
hour, minute)
|
592
|
+
|
593
|
+
else
|
594
|
+
fail "* Invalid data format '#{format}'.\n"
|
595
|
+
"See `qp help new-post` for details."
|
596
|
+
end
|
597
|
+
|
598
|
+
time
|
599
|
+
end
|
600
|
+
|
601
|
+
# Checks if `string` is a valid status for a post.
|
602
|
+
#
|
603
|
+
# @note Falls back to `publish`.
|
604
|
+
def status(string=nil)
|
605
|
+
case string
|
606
|
+
when nil then return "publish"
|
607
|
+
when /draft/i then return string
|
608
|
+
when /publish/i then return string
|
609
|
+
when /private/i then return string
|
610
|
+
else
|
611
|
+
fail "* Invalid status format '#{format}'.\n"
|
612
|
+
"See `qp help new-post` for details."
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
527
616
|
# Entrance for when we're editing a page or a post
|
528
617
|
# with numerical `id` (`what` says so).
|
529
618
|
#
|
@@ -533,11 +622,11 @@ module Quickpress
|
|
533
622
|
# Get previous content
|
534
623
|
old_content = nil
|
535
624
|
if what == :post
|
536
|
-
post = @@
|
625
|
+
post = @@wp.get_post id
|
537
626
|
|
538
627
|
old_content = post["post_content"]
|
539
628
|
else
|
540
|
-
page = @@
|
629
|
+
page = @@wp.get_page id
|
541
630
|
|
542
631
|
old_content = page["post_content"]
|
543
632
|
end
|
@@ -603,13 +692,18 @@ module Quickpress
|
|
603
692
|
|
604
693
|
link = nil
|
605
694
|
|
606
|
-
|
695
|
+
title = $options[:title]
|
696
|
+
if title.nil?
|
697
|
+
title = CLI::get("New Title:", true)
|
698
|
+
end
|
607
699
|
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
700
|
+
date = Quickpress::date $options[:date]
|
701
|
+
status = Quickpress::status $options[:status]
|
702
|
+
|
703
|
+
case what
|
704
|
+
when :post
|
705
|
+
# Only thing that makes posts different from pages
|
706
|
+
# are categories.
|
613
707
|
|
614
708
|
categories = $options[:category]
|
615
709
|
if categories.nil?
|
@@ -621,24 +715,35 @@ module Quickpress
|
|
621
715
|
puts "(will create non-existing categories automatically)"
|
622
716
|
puts "(leave empty to keep current categories)"
|
623
717
|
|
624
|
-
categories = CLI::tab_complete("Post categories:", @@
|
718
|
+
categories = CLI::tab_complete("Post categories:", @@wp.categories)
|
625
719
|
end
|
626
720
|
|
627
721
|
cats = []
|
628
722
|
categories.split(',').each { |c| cats << c.lstrip.strip }
|
629
723
|
|
630
724
|
CLI::with_status("Editing post...") do
|
631
|
-
link = @@
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
725
|
+
link = @@wp.edit_post(:post_id => id,
|
726
|
+
:content => {
|
727
|
+
:post_content => html,
|
728
|
+
:post_title => title,
|
729
|
+
:post_status => status,
|
730
|
+
:terms_names => {
|
731
|
+
:category => categories
|
732
|
+
}
|
733
|
+
})
|
638
734
|
end
|
639
735
|
|
736
|
+
when :page
|
640
737
|
CLI::with_status("Editing Page...") do
|
641
|
-
link = @@
|
738
|
+
link = @@wp.edit_post(:post_id => id,
|
739
|
+
:filter => {
|
740
|
+
:post_type => 'page'
|
741
|
+
},
|
742
|
+
:content => {
|
743
|
+
:post_content => html,
|
744
|
+
:post_title => title,
|
745
|
+
:post_status => status
|
746
|
+
})
|
642
747
|
end
|
643
748
|
end
|
644
749
|
|
@@ -661,20 +766,15 @@ module Quickpress
|
|
661
766
|
CLI::with_status("Hold on a sec...") do
|
662
767
|
|
663
768
|
if what == :post
|
664
|
-
thing = @@
|
769
|
+
thing = @@wp.get_post id.to_i
|
665
770
|
elsif what == :page
|
666
|
-
thing = @@
|
771
|
+
thing = @@wp.get_page id.to_i
|
667
772
|
end
|
668
773
|
|
669
774
|
end
|
670
775
|
|
671
|
-
if what == :post
|
672
|
-
puts "Will delete the following post:"
|
673
|
-
elsif what == :page
|
674
|
-
puts "Will delete the following page:"
|
675
|
-
end
|
676
|
-
|
677
776
|
puts <<-END.remove_starting!
|
777
|
+
Will delete the following #{what}:
|
678
778
|
|
679
779
|
ID: #{thing["post_id"]}
|
680
780
|
Title: #{thing["post_title"]}
|
@@ -686,6 +786,7 @@ module Quickpress
|
|
686
786
|
|
687
787
|
if not $options[:force]
|
688
788
|
answer = CLI::ask("Is that right?")
|
789
|
+
|
689
790
|
if not answer
|
690
791
|
puts "Alright, then!"
|
691
792
|
next
|
@@ -693,10 +794,9 @@ module Quickpress
|
|
693
794
|
end
|
694
795
|
|
695
796
|
CLI::with_status("Deleting...") do
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
@@connection.delete_page id.to_i
|
797
|
+
case what
|
798
|
+
when :post then @@wp.delete_post id.to_i
|
799
|
+
when :page then @@wp.delete_page id.to_i
|
700
800
|
end
|
701
801
|
end
|
702
802
|
puts "Deleted!"
|
@@ -712,12 +812,12 @@ module Quickpress
|
|
712
812
|
elements = nil
|
713
813
|
if what == :post
|
714
814
|
CLI::with_status("Retrieving posts...") do
|
715
|
-
elements = @@
|
815
|
+
elements = @@wp.get_posts ammount
|
716
816
|
end
|
717
817
|
|
718
818
|
elsif what == :page
|
719
819
|
CLI::with_status("Retrieving pages...") do
|
720
|
-
elements = @@
|
820
|
+
elements = @@wp.get_pages ammount
|
721
821
|
end
|
722
822
|
end
|
723
823
|
|
@@ -746,7 +846,7 @@ module Quickpress
|
|
746
846
|
# Shows comment count according to their status.
|
747
847
|
def status_comments
|
748
848
|
Quickpress::startup
|
749
|
-
status = @@
|
849
|
+
status = @@wp.get_comment_status
|
750
850
|
|
751
851
|
puts
|
752
852
|
Thor::Shell::Basic.new.print_table status
|
@@ -754,7 +854,7 @@ module Quickpress
|
|
754
854
|
|
755
855
|
def status_categories
|
756
856
|
Quickpress::startup
|
757
|
-
status = @@
|
857
|
+
status = @@wp.get_category_status
|
758
858
|
|
759
859
|
if $options[:"non-empty"]
|
760
860
|
status.reject! { |s| s[1].zero? }
|
@@ -779,7 +879,7 @@ module Quickpress
|
|
779
879
|
Quickpress::authenticate
|
780
880
|
|
781
881
|
CLI::with_status("Connecting...") do
|
782
|
-
@@
|
882
|
+
@@wp ||= Wordpress.new(@@default_site, @@username, @@password)
|
783
883
|
end
|
784
884
|
@started = true
|
785
885
|
end
|
data/lib/quickpress/version.rb
CHANGED
data/lib/quickpress/wordpress.rb
CHANGED
@@ -2,20 +2,15 @@ require 'rubypress'
|
|
2
2
|
|
3
3
|
module Quickpress
|
4
4
|
|
5
|
-
#
|
5
|
+
# Represents an instance of a Wordpress connection.
|
6
|
+
# Handles direct calls to the Wordpress API.
|
6
7
|
#
|
7
8
|
class Wordpress
|
8
|
-
# Blog title.
|
9
|
-
attr_reader :title
|
10
9
|
|
11
|
-
# Blog
|
12
|
-
attr_reader :tagline
|
13
|
-
|
14
|
-
#
|
15
|
-
attr_reader :url
|
16
|
-
|
17
|
-
# All categories on blog
|
18
|
-
attr_reader :categories
|
10
|
+
attr_reader :title # Blog title.
|
11
|
+
attr_reader :tagline # Blog subtitle.
|
12
|
+
attr_reader :url # Blog address
|
13
|
+
attr_reader :categories # All categories on blog
|
19
14
|
|
20
15
|
# Blog's options in a Hash. Need to call `get_options` first.
|
21
16
|
attr_reader :options
|
@@ -63,74 +58,65 @@ module Quickpress
|
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
66
|
-
# Sends a post/page to the Wordpress site
|
67
|
-
|
68
|
-
|
61
|
+
# Sends a post/page to the Wordpress site with `options`.
|
62
|
+
#
|
63
|
+
# `options` is a Hash with the following fields:
|
64
|
+
#
|
65
|
+
# * :post_date => Ruby Time Object (or `[]` for Time.now)
|
66
|
+
# * :post_title => String
|
67
|
+
# * :post_content => String
|
68
|
+
# * :post_status => 'publish'/'draft'/'private'
|
69
|
+
# * :post_type => 'post'(default) / 'page'
|
70
|
+
#
|
71
|
+
# To Wordpress, Posts and Pages are the same thing.
|
72
|
+
# The only thing that makes them different is the
|
73
|
+
# option `:post_type`.
|
74
|
+
#
|
75
|
+
def new_post options
|
76
|
+
# Sending post
|
77
|
+
id = @client.newPost(:content => options)
|
69
78
|
|
79
|
+
# Getting link for it
|
70
80
|
info = @client.getPost(:post_id => id,
|
71
|
-
:fields
|
81
|
+
:fields => [:link])
|
72
82
|
link = info["link"]
|
73
83
|
|
74
84
|
return id, link
|
75
85
|
end
|
76
86
|
|
77
|
-
#
|
78
|
-
# It's a Hash with attributes/values.
|
79
|
-
#
|
80
|
-
def get_post id
|
81
|
-
@client.getPost(:post_id => id)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Edits post with numerical `id` to have `new_content`.
|
87
|
+
# Edits post/page on the Wordpress site with `options`.
|
85
88
|
#
|
86
|
-
#
|
87
|
-
#
|
89
|
+
# Format is the same as Wordpress#new_post.
|
90
|
+
# Check it out.
|
88
91
|
#
|
89
|
-
def edit_post
|
90
|
-
old_post = get_post id
|
91
|
-
|
92
|
-
new_content = old_post["post_content"] if new_content.empty?
|
93
|
-
new_title = old_post["post_title"] if new_title.empty?
|
92
|
+
def edit_post options
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
terms = old_post["terms"].select { |t| t["taxonomy"] == "category" }
|
99
|
-
|
100
|
-
# Getting category names
|
101
|
-
cats = terms.map { |c| c["name"] }
|
102
|
-
new_categories = cats
|
103
|
-
end
|
94
|
+
@client.editPost(options)
|
95
|
+
info = @client.getPost(:post_id => options[:post_id],
|
96
|
+
:fields => [:link])
|
104
97
|
|
105
|
-
|
106
|
-
:content => {
|
107
|
-
:post_content => new_content,
|
108
|
-
:post_title => new_title,
|
109
|
-
:terms_names => {
|
110
|
-
:category => new_categories
|
111
|
-
}
|
112
|
-
})
|
113
|
-
old_post["link"]
|
98
|
+
info["link"]
|
114
99
|
end
|
115
100
|
|
116
|
-
|
117
|
-
|
101
|
+
# Returns post with numerical `id`.
|
102
|
+
# It's a Hash with attributes/values.
|
103
|
+
#
|
104
|
+
def get_post id
|
105
|
+
@client.getPost(:post_id => id)
|
106
|
+
end
|
118
107
|
|
119
|
-
|
120
|
-
|
108
|
+
# Returns `ammount` posts.
|
109
|
+
# If `ammount` is zero, will return all posts.
|
110
|
+
# FIXME when getting by `ammount` it is ordered by the opposite
|
111
|
+
def get_posts(ammount=0)
|
112
|
+
ammount = VERY_LARGE_NUMBER if ammount.zero?
|
121
113
|
|
122
|
-
@client.
|
123
|
-
:filter => {
|
124
|
-
:post_type => 'page'
|
125
|
-
},
|
126
|
-
:content => {
|
127
|
-
:post_content => new_content,
|
128
|
-
:post_title => new_title
|
129
|
-
})
|
130
|
-
old_page["link"]
|
114
|
+
@client.getPosts(:filter => { :number => ammount })
|
131
115
|
end
|
132
116
|
|
133
117
|
# Returns page with numerical `id`.
|
118
|
+
# It's a Hash with attributes/values.
|
119
|
+
#
|
134
120
|
def get_page id
|
135
121
|
@client.getPost(:post_id => id,
|
136
122
|
:filter => {
|
@@ -138,15 +124,6 @@ module Quickpress
|
|
138
124
|
})
|
139
125
|
end
|
140
126
|
|
141
|
-
# Returns `ammount` posts.
|
142
|
-
# If `ammount` is zero, will return all posts.
|
143
|
-
# FIXME when getting by `ammount` it is ordered by the opposite
|
144
|
-
def get_posts(ammount=0)
|
145
|
-
ammount = VERY_LARGE_NUMBER if ammount.zero?
|
146
|
-
|
147
|
-
@client.getPosts(:filter => { :number => ammount })
|
148
|
-
end
|
149
|
-
|
150
127
|
# Returns `ammount` pages.
|
151
128
|
# If `ammount` is zero, will return all posts.
|
152
129
|
# FIXME when getting by `ammount` it is ordered by the opposite
|
@@ -161,7 +138,7 @@ module Quickpress
|
|
161
138
|
|
162
139
|
# Deletes post with numerical `id`.
|
163
140
|
def delete_post id
|
164
|
-
@client.
|
141
|
+
@client.delnetePost(:post_id => id)
|
165
142
|
end
|
166
143
|
|
167
144
|
# Deletes page with numerical `id`.
|
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.2.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: 2013-12-
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypress
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.2.0
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Manage your Wordpress site on the command line
|