Class: Softcover::Client
- Inherits:
-
Object
show all
- Includes:
- Utils
- Defined in:
- lib/softcover/client.rb
Constant Summary
collapse
- ApiVersion =
1
- ApiPrefix =
"/api/v#{ApiVersion}"
- Paths =
{
login: 'login',
books: 'books'
}
Constants included
from Utils
Utils::UNITS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
#add_highlight_class!, #article?, #as_size, #book_file_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #filename_or_default, #first_path, #get_filename, #html_extension, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #non_comment_lines, #os_x?, #path, #polytexnic_html, #raw_lines, #reset_current_book!, #rm, #rm_r, #silence, #silence_stream, #source, #template_dir, #tmpify, #unpublish_slug, #write_master_latex_file, #write_pygments_file
Constructor Details
#initialize(email = nil, password = nil, book = nil) ⇒ Client
Returns a new instance of Client.
17
18
19
20
21
22
23
24
25
26
27
|
# 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
|
Instance Attribute Details
#book ⇒ Object
Returns the value of attribute book.
15
16
17
|
# File 'lib/softcover/client.rb', line 15
def book
@book
end
|
#host ⇒ Object
Returns the value of attribute host.
15
16
17
|
# File 'lib/softcover/client.rb', line 15
def host
@host
end
|
Class Method Details
.new_with_book(book) ⇒ Object
29
30
31
|
# File 'lib/softcover/client.rb', line 29
def self.new_with_book(book)
new nil, nil, book
end
|
Instance Method Details
#create_or_update_book(params) ⇒ Object
43
44
45
46
47
48
49
50
|
# 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 ⇒ Object
60
61
62
|
# File 'lib/softcover/client.rb', line 60
def destroy
delete path_for(:books, book.id)
end
|
#destroy_book_by_slug(slug) ⇒ Object
64
65
66
|
# File 'lib/softcover/client.rb', line 64
def destroy_book_by_slug(slug)
delete path_for(:books, slug)
end
|
69
70
71
72
73
74
75
76
|
# 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]
end
|
#login! ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/softcover/client.rb', line 34
def login!
require "softcover/config"
response = post path_for(:login), email: @email, password: @password
json = JSON response
Softcover::Config['api_key'] = @api_key = json['api_key']
end
|
#notify_file_upload(params) ⇒ Object
52
53
54
|
# 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 ⇒ Object
56
57
58
|
# File 'lib/softcover/client.rb', line 56
def notify_upload_complete
JSON put path_for(:books, book.id), upload_complete: true
end
|