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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4dfd43d360ce2e5fb73f9ef560fddcb1e52fe0d
4
- data.tar.gz: 9cc10d4ad3b1e58ec96037e9e23dd048cc76721a
3
+ metadata.gz: b633f70a9f7fedd5dc66e5dd26117a7326eb18d1
4
+ data.tar.gz: 47b778cd11c08dae63ae73187c0ba35106ab6087
5
5
  SHA512:
6
- metadata.gz: 53275a23f95789f065d67e84805bce54e0122663dfb1de8939261daffa638044a6aea2e06c1d586f4b782e432adfbac94c8fe1f96c9902cd171cce5fdb1c3fa0
7
- data.tar.gz: 5d7cf763ed7fac74e4847c33b30dd0aeb68c22938f355fb4058907b47911d3fccb5fc49968eb1f685e7fabcdb2cd58bca131ea5b75f1ab888930f0d91be3d2c5
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
- if ask("Type '#{unpublish_slug}' to unpublish:") == unpublish_slug
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -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
@@ -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)).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softcover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl