This repository was archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_client.rb
More file actions
57 lines (45 loc) · 1.64 KB
/
Copy pathtest_client.rb
File metadata and controls
57 lines (45 loc) · 1.64 KB
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
55
56
# This script requires a Lockbox partner to be created as follows in script/console:
# p = Partner.createi!{ "password" => "password", "password_confirmation" => "password", "name"=>"user", "phone_number"=>"5555555555", "organization"=>"test", "email"=>"a@a.com" }
# p.confirmed = true; p.api_key = 12345; p.max_requests = nil; p.save!
require 'rubygems'
gem 'dnclabs-auth-hmac'
require 'httpotato'
require 'auth-hmac'
class HmacRequest
def self.config
{'host' => 'localhost:4567', 'hmac_id' => 'test-user', 'hmac_secret' => '12345'}
end
include HTTPotato
format :html
base_uri self.config['host']
def self.test_get
authenticated_get("/test")
end
def self.test_post
authenticated_post("/test", :body => "some post body data")
end
def self.authenticated_post(url, options = {})
options_merged = options.merge({:headers => {"CONTENT-TYPE" => "application/x-www-form-urlencoded"}, :hmac => {:id => config['hmac_id'], :secret => config['hmac_secret']}})
begin
post url, options_merged
rescue HTTPotato::ParseError
return {}
end
end
def self.authenticated_put(url, options = {})
begin
put url, options.merge({:headers => {"CONTENT-TYPE" => "application/x-www-form-urlencoded"}, :hmac => {:id => config['hmac_id'], :secret => config['hmac_secret']}})
rescue HTTPotato::ParseError
return {}
end
end
def self.authenticated_get(url, options = {})
begin
get url, options.merge({:hmac => {:id => config['hmac_id'], :secret => config['hmac_secret']}})
rescue HTTPotato::ParseError
return {}
end
end
end
puts HmacRequest.test_get
puts HmacRequest.test_post