Class: PerfectAudit::BooksRepository
- Inherits:
-
Object
- Object
- PerfectAudit::BooksRepository
- Defined in:
- lib/perfect_audit/api/repositories.rb
Constant Summary collapse
- CREATE_PATH =
'book/add'
- ALL_PATH =
'books'
- FIND_PATH =
'book/info'
- DELETE_PATH =
'book/remove'
- EXCEL_EXPORT_PATH =
'book/export/xlsx/analytics'
Instance Method Summary collapse
-
#all ⇒ Array<PerfectAudit::Book>
Get all books from Perfect Audit for account.
-
#create(name, public = false) ⇒ PerfectAudit::Book
Create book in Perfect Audit.
-
#delete(book_or_id) ⇒ true
Delete book in Perfect Audit.
-
#find(id) ⇒ PerfectAudit::Book
Find book in Perfect Audit.
- #to_excel(book_or_id) ⇒ Object
Instance Method Details
#all ⇒ Array<PerfectAudit::Book>
Get all books from Perfect Audit for account
37 38 39 40 41 42 43 |
# File 'lib/perfect_audit/api/repositories.rb', line 37 def all response = connection.get(ALL_PATH) response_parser.parse(response.body.to_s).map { |item| PerfectAudit::Book.new(**item) } end |
#create(name, public = false) ⇒ PerfectAudit::Book
Create book in Perfect Audit
23 24 25 26 27 28 29 30 31 |
# File 'lib/perfect_audit/api/repositories.rb', line 23 def create(name, public = false) response = connection.post(CREATE_PATH, json: { name: name.to_s, is_public: public.to_s }) PerfectAudit::Book.new(**response_parser.parse(response.body.to_s)) end |
#delete(book_or_id) ⇒ true
Delete book in Perfect Audit
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/perfect_audit/api/repositories.rb', line 64 def delete(book_or_id) id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s response = connection.post(DELETE_PATH, json: { book_id: id }) response_parser.parse(response.body.to_s) true end |
#find(id) ⇒ PerfectAudit::Book
Find book in Perfect Audit
50 51 52 53 54 55 56 57 |
# File 'lib/perfect_audit/api/repositories.rb', line 50 def find(id) response = connection.get(FIND_PATH, params: { pk: id.to_s }) PerfectAudit::Book.new(**response_parser.parse(response.body.to_s)) end |
#to_excel(book_or_id) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/perfect_audit/api/repositories.rb', line 76 def to_excel(book_or_id) id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s response = connection.get(EXCEL_EXPORT_PATH, params: { pk: id.to_s }) response.body.to_s end |