forked from piplcom/piplapis-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive_examples.rb
55 lines (34 loc) · 1.08 KB
/
live_examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require_relative 'lib/pipl'
Pipl.configure do |c|
c.strict_validation = true
end
def print_response(resp)
if resp.key? :error
puts "Error: #{resp[:error].message}"
else
puts "Success: #{resp[:response].inspect}"
end
end
# Example for a simple call
resp = Pipl::client.search email: 'clark.kent@example.com'
puts resp.inspect
# Example for a simple call which returns an error
begin
resp = Pipl::client.search email: 'clark.kent@example.com', api_key: 'd'
puts resp.inspect
rescue Pipl::Client::APIError => e
puts e.status_code, e.message
end
# Example for an async call with callback
t = Pipl::client.search email: 'clark.kent@example.com', callback: Proc.new { |resp| print_response resp }
t.join
# Example for an async call with a block as callback
t = Pipl::client.search email: 'clark.kent@example.com', async: true do |resp|
print_response resp
end
t.join
# Example for an async call with a block as callback. Error (api key invalid)
t = Pipl::client.search email: 'clark.kent@example.com', api_key: 'd', async: true do |resp|
print_response resp
end
t.join