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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c27162da2493ec3c5cb9c76efba6afdf19c1d3d6
4
- data.tar.gz: c6acc4f247e2ca65ac99fac7c0943b0181942e6e
3
+ metadata.gz: d981203f21af5347251dc4ada125fc9c8299e266
4
+ data.tar.gz: 51776e29d04a1fb92d2d3e97bec6596dbdbb6cad
5
5
  SHA512:
6
- metadata.gz: 48185fc4598fdb07d82c608ecf3f0c8f3346a1006d2b2e90c5e232f720740488d5d319c4d016401af9958d2b6fc04112ca8cbb821b5acd74756c3c1271216e32
7
- data.tar.gz: fe881555598c659e6d5dc0a10b39e74c9d6481def29d80efeb4bf09e9f757d24a1302a3e95f01a2e7d93ce3a2d989c075cd5da8f9ab367b88ed511111a6cc1e2
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
- PerfectAudit.books.create(name: 'Test book', is_public: 'false')
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
- Get book information:
77
+ Find book by ID
53
78
 
54
79
  ``` ruby
55
- PerfectAudit.books.find(book_id)
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.delete(book_or_id)
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
- PerfectAudit.documents.create(book_or_id, file_or_io)
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('book/upload',
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
- # id = book_or_id.is_a?(PerfectAudit::Book) ? book_or_id.id.to_s : book_or_id.to_s
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
- # response = connection.get('transaction',
85
- # params: {
86
- # book_pk: id
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
- # response_parser.parse(response.body.to_s)[:bank_accounts].map do |id, params|
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
@@ -1,3 +1,3 @@
1
1
  module PerfectAudit
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  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.1.5
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-22 00:00:00.000000000 Z
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: