@@ -162,6 +162,54 @@ Using the ruby bundler:
162162bundle exec ruby ./bin/mindee.rb invoice path/to/your/file.ext
163163```
164164
165+
166+ ### Enqueue and Parse a Webhook Response
167+ This is an optional way of handling asynchronous APIs.
168+
169+ ``` rb
170+ require ' mindee'
171+
172+ # Init a new client
173+ mindee_client = Mindee ::Client .new (api_key: ' my-api-key' )
174+
175+ # Load a file from disk
176+ input_source = mindee_client.source_from_path(' /path/to/the/file.ext' )
177+
178+
179+ # Parse the file
180+ enqueue_response = mindee_client.enqueue(
181+ input_source,
182+ Mindee ::Product ::InternationalId ::InternationalIdV2
183+ )
184+
185+ job_id = enqueue_response.job.id
186+
187+ # Load the JSON string sent by the Mindee webhook POST callback.
188+ # Reading the callback data will vary greatly depending on your HTTP server.
189+ # This is therefore beyond the scope of this example.
190+
191+ local_response = Mindee ::Input ::LocalResponse .new (request.body.string)
192+
193+ # You can also use a File object as the input.
194+ # FILE_PATH = File.join('path', 'to', 'file.json').freeze
195+ # local_response = Mindee::Input::LocalResponse.new(FILE_PATH);
196+
197+ # Optional: verify the HMAC signature.
198+ unless local_response.valid_hmac_signature?(my_secret_key, ' invalid signature' )
199+ raise " Invalid HMAC signature!"
200+ end
201+
202+
203+ # Deserialize the response:
204+ result = mindee_client.load_prediction(
205+ Mindee ::Product ::InternationalId ::InternationalIdV2 ,
206+ local_response
207+ )
208+
209+ # Print a full summary of the parsed data in RST format
210+ puts result.document
211+ ```
212+
165213## Further Reading
166214
167215There's more to it than that for those that need more features, or want to
0 commit comments