softcover 0.9.6 → 0.9.7
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/lib/softcover/cli.rb +8 -2
- data/lib/softcover/client.rb +4 -2
- data/lib/softcover/commands/publisher.rb +20 -1
- data/lib/softcover/version.rb +1 -1
- data/spec/commands/publisher_spec.rb +26 -0
- data/spec/webmock_helpers.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b633f70a9f7fedd5dc66e5dd26117a7326eb18d1
|
4
|
+
data.tar.gz: 47b778cd11c08dae63ae73187c0ba35106ab6087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef9d73de06e4e2bc90f8338ef1642fb6a5b4cc0dd1dae0a4380b5e5f9ab165d0c6a73ad94950274be7a13425cd35892591f5c9f47a7cba4ec6787abf233391e
|
7
|
+
data.tar.gz: 818b97a218b882bc69333f9f96e1ba03b57450f916d59cfd5cfc8a1ea2c98fdcccd27b9c0d5f83d74e02ab2086b2e1a6b7a06f99c7357c0567d63a065a96f402
|
data/lib/softcover/cli.rb
CHANGED
@@ -162,13 +162,19 @@ module Softcover
|
|
162
162
|
end
|
163
163
|
|
164
164
|
desc "unpublish", "Remove book from Softcover"
|
165
|
+
method_option :slug, aliases: '-s',
|
166
|
+
desc: "Specify slug", type: :string
|
167
|
+
|
168
|
+
method_option :force, aliases: '-f',
|
169
|
+
desc: "Force", type: :boolean
|
165
170
|
def unpublish
|
166
171
|
require 'softcover/commands/publisher'
|
167
172
|
|
168
173
|
invoke :login unless logged_in?
|
169
|
-
|
174
|
+
slug = options[:slug] || unpublish_slug
|
175
|
+
if options[:force] || ask("Type '#{slug}' to unpublish:") == slug
|
170
176
|
puts "Unpublishing..." unless options[:silent]
|
171
|
-
Softcover::Commands::Publisher.unpublish!
|
177
|
+
Softcover::Commands::Publisher.unpublish!(slug)
|
172
178
|
else
|
173
179
|
puts "Canceled."
|
174
180
|
end
|
data/lib/softcover/client.rb
CHANGED
@@ -61,6 +61,10 @@ module Softcover
|
|
61
61
|
delete path_for(:books, book.id)
|
62
62
|
end
|
63
63
|
|
64
|
+
def destroy_book_by_slug(slug)
|
65
|
+
delete path_for(:books, slug)
|
66
|
+
end
|
67
|
+
|
64
68
|
# ============ Screencasts ===========
|
65
69
|
def get_screencast_upload_params(files)
|
66
70
|
JSON post path_for(:books, book.id, :screencasts), files: files
|
@@ -105,8 +109,6 @@ module Softcover
|
|
105
109
|
end
|
106
110
|
|
107
111
|
def handle_422
|
108
|
-
require "softcover/config"
|
109
|
-
Softcover::Config['api_key'] = nil
|
110
112
|
return { "errors" => "You don't have access to that resource." }
|
111
113
|
end
|
112
114
|
end
|
@@ -89,7 +89,26 @@ module Softcover::Commands::Publisher
|
|
89
89
|
puts "Processed #{current_book.processed_screencasts.size} screencasts."
|
90
90
|
end
|
91
91
|
|
92
|
-
def unpublish!
|
92
|
+
def unpublish!(slug=nil)
|
93
|
+
require "rest_client"
|
94
|
+
require "softcover/client"
|
95
|
+
|
96
|
+
if slug.present?
|
97
|
+
begin
|
98
|
+
res = Softcover::Client.new.destroy_book_by_slug(slug)
|
99
|
+
if res["errors"]
|
100
|
+
puts "Errors: #{res.errors}"
|
101
|
+
return false
|
102
|
+
else
|
103
|
+
puts "Done!"
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
rescue RestClient::ResourceNotFound
|
107
|
+
puts "Book with slug='#{slug}' not found under this account."
|
108
|
+
return false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
93
112
|
return false unless current_book
|
94
113
|
if current_book.destroy
|
95
114
|
Softcover::BookConfig.remove
|
data/lib/softcover/version.rb
CHANGED
@@ -70,6 +70,32 @@ describe Softcover::Commands::Publisher do
|
|
70
70
|
expect(subject.unpublish!).to be_false
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context "unpublishing outside book directory" do
|
75
|
+
before do
|
76
|
+
chdir_to_book
|
77
|
+
stub_create_book book
|
78
|
+
subject.publish!
|
79
|
+
Dir.chdir(File.dirname(__FILE__))
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with valid slug option" do
|
83
|
+
before { stub_destroy_book_by_slug book }
|
84
|
+
|
85
|
+
it "unpublishes" do
|
86
|
+
expect(subject.unpublish!(book.slug)).to be_true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with invalid slug option" do
|
91
|
+
let(:slug) { "error" }
|
92
|
+
before { stub_destroy_book_by_invalid_slug slug }
|
93
|
+
|
94
|
+
it "does not unpublish" do
|
95
|
+
expect(subject.unpublish!(slug)).to be_false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
73
99
|
end
|
74
100
|
|
75
101
|
describe "#publish_screencasts" do
|
data/spec/webmock_helpers.rb
CHANGED
@@ -88,6 +88,18 @@ module WebmockHelpers
|
|
88
88
|
to_return(:status => 200, :body => "", :headers => {})
|
89
89
|
end
|
90
90
|
|
91
|
+
def stub_destroy_book_by_slug(book)
|
92
|
+
stub_request(:delete, "#{api_base_url}/books/#{book.slug}?api_key=").
|
93
|
+
with(:headers => headers(false)).
|
94
|
+
to_return(:status => 200, :body => "", :headers => {})
|
95
|
+
end
|
96
|
+
|
97
|
+
def stub_destroy_book_by_invalid_slug(slug)
|
98
|
+
stub_request(:delete, "#{api_base_url}/books/#{slug}?api_key=").
|
99
|
+
with(:headers => headers(false)).
|
100
|
+
to_return(:status => 404, :body => "", :headers => {})
|
101
|
+
end
|
102
|
+
|
91
103
|
def stub_destroy_book_not_found(book)
|
92
104
|
stub_request(:delete, "#{api_base_url}/books/#{book.id}?api_key=").
|
93
105
|
with(:headers => headers(false)).
|