-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.rb
41 lines (30 loc) · 960 Bytes
/
example.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
require 'curb'
require 'openssl'
require 'json'
api_key = "**** YOUR API KEY ****"
api_secret = "**** YOUR API SECRET ****"
# GET method exmaple
prefix = '/api/v3'
endpoint = '/[email protected]'
data = api_key + "GET" + prefix + endpoint
c = Curl::Easy.new('https://dev.safecrow.ru' + prefix + endpoint)
c.headers['Content-Type'] = 'application/json'
c.http_auth_types = :basic
c.username = api_key
c.password = OpenSSL::HMAC.hexdigest('SHA256', api_secret, data)
c.perform
puts c.status
puts c.body
# POST method exmaple
prefix = '/api/v3'
endpoint = '/users'
user = { email: '[email protected]' }
data = api_key + "POST" + prefix + endpoint + user.to_json
c = Curl::Easy.new('https://dev.safecrow.ru' + prefix + endpoint)
c.headers['Content-Type'] = 'application/json'
c.http_auth_types = :basic
c.username = api_key
c.password = OpenSSL::HMAC.hexdigest('SHA256', api_secret, data)
c.post(user.to_json)
puts c.status
puts c.body