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!, #as_size, #current_book, #digest, #executable, #execute, #in_book_directory?, #logged_in?, #mkdir, #path, #reset_current_book!, #rm, #silence, #source, #tmpify, #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
|
#get_screencast_upload_params(files) ⇒ Object
65
66
67
68
|
# File 'lib/softcover/client.rb', line 65
def get_screencast_upload_params(files)
JSON post path_for(:books, book.id, :screencasts), files: 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
|