class Softcover::Client
Constants
- ApiPrefix
- ApiVersion
- Paths
Attributes
book[RW]
host[RW]
Public Class Methods
new(email=nil,password=nil,book=nil)
click to toggle source
# File lib/softcover/client.rb, line 17 def initialize(email=nil,password=nil,book=nil) require 'json' require 'rest_client' require "softcover/config" @email = email @password = password @book = book @api_key = Softcover::Config['api_key'] @host = Softcover::Config['host'] end
new_with_book(book)
click to toggle source
# File lib/softcover/client.rb, line 29 def self.new_with_book(book) new nil, nil, book end
Public Instance Methods
create_or_update_book(params)
click to toggle source
Publishing ===========¶ ↑
# File lib/softcover/client.rb, line 43 def create_or_update_book(params) JSON post path_for(:books), params rescue RestClient::ResourceNotFound { "errors" => "Book ID #{params[:id]} not found for this account. "+ "Either login again or delete this file: .softcover-book" } end
destroy()
click to toggle source
# File lib/softcover/client.rb, line 60 def destroy delete path_for(:books, book.id) end
destroy_book_by_slug(slug)
click to toggle source
# File lib/softcover/client.rb, line 64 def destroy_book_by_slug(slug) delete path_for(:books, slug) end
get_media_upload_params(path, files, manifest=nil, options={})
click to toggle source
Media ===========¶ ↑
# File lib/softcover/client.rb, line 69 def get_media_upload_params(path, files, manifest=nil, options={}) JSON post path_for(:books, book.id, :media), path: path, files: files, manifest: manifest, remove_unused_media_files: options[:remove_unused_media_files] # TODO: handle errors end
login!()
click to toggle source
notify_file_upload(params)
click to toggle source
# File lib/softcover/client.rb, line 52 def notify_file_upload(params) JSON post path_for(:books, book.id, :notify_file_upload), params end
notify_upload_complete()
click to toggle source
# File lib/softcover/client.rb, line 56 def notify_upload_complete JSON put path_for(:books, book.id), upload_complete: true end
Private Instance Methods
formatted_headers(headers={})
click to toggle source
# File lib/softcover/client.rb, line 107 def formatted_headers(headers={}) headers.merge accept: :json, content_type: :json end
handle_422()
click to toggle source
# File lib/softcover/client.rb, line 115 def handle_422 return { "errors" => "You don't have access to that resource." } end
params_with_key(params)
click to toggle source
# File lib/softcover/client.rb, line 103 def params_with_key(params) @api_key.present? ? params.merge({api_key: @api_key}) : params end
path_for(action, *args)
click to toggle source
# File lib/softcover/client.rb, line 111 def path_for(action, *args) File.join ApiPrefix, Paths[action], *(args.map &:to_s) end