perfect_audit 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -11
- data/lib/perfect_audit/api/repositories.rb +28 -12
- data/lib/perfect_audit/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d981203f21af5347251dc4ada125fc9c8299e266
|
4
|
+
data.tar.gz: 51776e29d04a1fb92d2d3e97bec6596dbdbb6cad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2059caca09c3b243c7bd80d44f9a2afa02d88564a8701d3f0013820e59f769b9f1a79ae8c1bb756278954e849838407329198761c48b2e174b93b5a5112d288
|
7
|
+
data.tar.gz: e740c2a8df7e9e9b5ecfae22c0116eaf40e949c27a5f3ee99b23bc6bb61e8cf580534e853a81ef6bf1248c8713ec571e250e1ceea8cb218316604c9333cb56fd
|
data/README.md
CHANGED
@@ -33,40 +33,84 @@ Or install it yourself as:
|
|
33
33
|
end
|
34
34
|
```
|
35
35
|
|
36
|
+
## Exception Handling
|
37
|
+
|
38
|
+
If PerfectAudit will return anything different from 200 OK status code, `PerfectAudit::Error` will be raised. It contains `#message` and `#code` returned from API.
|
39
|
+
|
40
|
+
For example with invalid credentials you will receive:
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
PerfectAudit.books.all
|
44
|
+
#=> PerfectAudit::Error: Email and/or password not found [1306]
|
45
|
+
```
|
46
|
+
|
47
|
+
And if you will try to find a Book that does not exist, you will receive:
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
PerfectAudit.books.find(82087)
|
51
|
+
#=> PerfectAudit::Error: Book not found [1401]
|
52
|
+
```
|
53
|
+
|
36
54
|
## Usage
|
37
55
|
|
38
|
-
### Books
|
56
|
+
### Books Repository
|
39
57
|
|
40
|
-
Get books list for your account
|
58
|
+
Get books list for your account
|
41
59
|
|
42
60
|
``` ruby
|
43
61
|
PerfectAudit.books.all
|
62
|
+
#=> [#<PerfectAudit::Book:0x00007ff51bbfbe28>, ...]
|
44
63
|
```
|
45
64
|
|
46
|
-
Create a book
|
65
|
+
Create a book
|
47
66
|
|
48
67
|
``` ruby
|
49
|
-
|
68
|
+
# Create a book with name=Test
|
69
|
+
PerfectAudit.books.create('Test')
|
70
|
+
#=> #<PerfectAudit::Book:0x00007ff51c8e4248 @id=0, @created_at="2018-03-22T20:21:25Z", @name="Test", @public=false ...>
|
71
|
+
|
72
|
+
# Create a book with name=Test which is public
|
73
|
+
PerfectAudit.books.create('Test', true)
|
74
|
+
#=> #<PerfectAudit::Book:0x00007ff51c8e4248 @id=0, @created_at="2018-03-22T20:21:25Z", @name="Test", @public=true ...>
|
50
75
|
```
|
51
76
|
|
52
|
-
|
77
|
+
Find book by ID
|
53
78
|
|
54
79
|
``` ruby
|
55
|
-
PerfectAudit.books.find(
|
80
|
+
PerfectAudit.books.find(100)
|
81
|
+
#=> #<PerfectAudit::Book:0x00007ff51c89f828 @id=100, @created_at="2018-03-22T20:48:54Z", @name="Test", @public=false ...>
|
56
82
|
```
|
57
83
|
|
58
|
-
Delete a book
|
84
|
+
Delete a book
|
85
|
+
|
86
|
+
``` ruby
|
87
|
+
# To delete a book you can use either its ID or instance
|
88
|
+
PerfectAudit.books.delete(100)
|
89
|
+
#=> true
|
90
|
+
|
91
|
+
book = PerfectAudit.books.find(100)
|
92
|
+
PerfectAudit.books.delete(book)
|
93
|
+
#=> true
|
94
|
+
```
|
59
95
|
|
96
|
+
Export book to Excel
|
60
97
|
``` ruby
|
61
|
-
PerfectAudit.books.
|
98
|
+
book = PerfectAudit.books.find(100)
|
99
|
+
File.write('./book.xlsx', PerfectAudit.books.to_excel(book))
|
62
100
|
```
|
63
101
|
|
64
|
-
### Documents
|
102
|
+
### Documents Repository
|
65
103
|
|
66
|
-
Upload document to a book
|
104
|
+
Upload document to a book
|
67
105
|
|
68
106
|
``` ruby
|
69
|
-
|
107
|
+
# To upload documents to a book you can use book ID or its instance and File
|
108
|
+
PerfectAudit.documents.create(100, File.open('./document.pdf'))
|
109
|
+
#=> true
|
110
|
+
|
111
|
+
book = PerfectAudit.books.find(100)
|
112
|
+
PerfectAudit.documents.create(book, File.open('./document.pdf'))
|
113
|
+
#=> true
|
70
114
|
```
|
71
115
|
|
72
116
|
## Credits
|
@@ -10,6 +10,7 @@ module PerfectAudit
|
|
10
10
|
ALL_PATH = 'books'.freeze
|
11
11
|
FIND_PATH = 'book/info'.freeze
|
12
12
|
DELETE_PATH = 'book/remove'.freeze
|
13
|
+
EXCEL_EXPORT_PATH = 'book/export/xlsx/analytics'.freeze
|
13
14
|
|
14
15
|
def create(name, public = false)
|
15
16
|
response = connection.post(CREATE_PATH,
|
@@ -52,16 +53,29 @@ module PerfectAudit
|
|
52
53
|
|
53
54
|
true
|
54
55
|
end
|
56
|
+
|
57
|
+
def to_excel(book_or_id)
|
58
|
+
id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s
|
59
|
+
response = connection.get(EXCEL_EXPORT_PATH,
|
60
|
+
params: {
|
61
|
+
pk: id.to_s
|
62
|
+
}
|
63
|
+
)
|
64
|
+
|
65
|
+
response.body.to_s
|
66
|
+
end
|
55
67
|
end
|
56
68
|
|
57
69
|
class DocumentsRepository
|
58
70
|
include PerfectAudit::AutoInject[:connection]
|
59
71
|
include PerfectAudit::AutoInject[:response_parser]
|
60
72
|
|
73
|
+
CREATE_PATH = 'book/upload'.freeze
|
74
|
+
|
61
75
|
def create(book_or_id, file)
|
62
76
|
id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s
|
63
77
|
|
64
|
-
response = connection.post(
|
78
|
+
response = connection.post(CREATE_PATH,
|
65
79
|
form: {
|
66
80
|
pk: id,
|
67
81
|
upload: HTTP::FormData::File.new(file)
|
@@ -78,18 +92,20 @@ module PerfectAudit
|
|
78
92
|
# include PerfectAudit::AutoInject[:connection]
|
79
93
|
# include PerfectAudit::AutoInject[:response_parser]
|
80
94
|
|
81
|
-
# def find(book_or_id)
|
82
|
-
#
|
95
|
+
# # def find(book_or_id)
|
96
|
+
# # id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s
|
97
|
+
|
98
|
+
# # response = connection.get('transaction',
|
99
|
+
# # params: {
|
100
|
+
# # book_pk: id
|
101
|
+
# # }
|
102
|
+
# # )
|
83
103
|
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# )
|
104
|
+
# # response_parser.parse(response.body.to_s)[:bank_accounts].map do |id, params|
|
105
|
+
# # PerfectAudit::BankAccount.new(params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo})
|
106
|
+
# # end
|
107
|
+
# # end
|
89
108
|
|
90
|
-
#
|
91
|
-
# PerfectAudit::BankAccount.new(params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo})
|
92
|
-
# end
|
93
|
-
# end
|
109
|
+
# def
|
94
110
|
# end
|
95
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perfect_audit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-auto_inject
|
@@ -259,4 +259,3 @@ signing_key:
|
|
259
259
|
specification_version: 4
|
260
260
|
summary: Perfect Audit API wrapper.
|
261
261
|
test_files: []
|
262
|
-
has_rdoc:
|