Class: HashAuth::WebRequest
- Inherits:
-
Object
- Object
- HashAuth::WebRequest
- Defined in:
- lib/hash-auth/web_request.rb
Class Method Summary collapse
- .add_client_to_params(client, params) ⇒ Object
- .add_signature_to_params(client, verb, params) ⇒ Object
- .delegate_to_rest_client_active(action, client, url, payload, headers, &block) ⇒ Object
- .delegate_to_rest_client_passive(action, client, url, headers, &block) ⇒ Object
- .delete(client, url, headers = {}, &block) ⇒ Object
- .get(client, url, headers = {}, &block) ⇒ Object
- .head(client, url, headers = {}, &block) ⇒ Object
- .options(client, url, headers = {}, &block) ⇒ Object
- .patch(client, url, payload, headers = {}, &block) ⇒ Object
- .post(client, url, payload, headers = {}, &block) ⇒ Object
- .put(client, url, payload, headers = {}, &block) ⇒ Object
- .sign_and_identify(client, verb, params) ⇒ Object
Class Method Details
.add_client_to_params(client, params) ⇒ Object
54 55 56 57 |
# File 'lib/hash-auth/web_request.rb', line 54 def self.add_client_to_params(client, params) params[client.customer_identifier_param.to_sym] = client.customer_identifier params end |
.add_signature_to_params(client, verb, params) ⇒ Object
59 60 61 62 |
# File 'lib/hash-auth/web_request.rb', line 59 def self.add_signature_to_params(client, verb, params) params[client.signature_param.to_sym] = client.strategy.sign_request(client, verb, params) params end |
.delegate_to_rest_client_active(action, client, url, payload, headers, &block) ⇒ Object
39 40 41 42 |
# File 'lib/hash-auth/web_request.rb', line 39 def self.delegate_to_rest_client_active(action, client, url, payload, headers, &block) payload = self.sign_and_identify client, action, payload RestClient.send action, url, payload, headers, &block end |
.delegate_to_rest_client_passive(action, client, url, headers, &block) ⇒ Object
34 35 36 37 |
# File 'lib/hash-auth/web_request.rb', line 34 def self.delegate_to_rest_client_passive(action, client, url, headers, &block) headers = self.sign_and_identify client, action, headers RestClient.send action, url, headers, &block end |
.delete(client, url, headers = {}, &block) ⇒ Object
22 23 24 |
# File 'lib/hash-auth/web_request.rb', line 22 def self.delete(client, url, headers = {}, &block) self.delegate_to_rest_client_passive :delete, client, url, headers, &block end |
.get(client, url, headers = {}, &block) ⇒ Object
6 7 8 |
# File 'lib/hash-auth/web_request.rb', line 6 def self.get(client, url, headers = {}, &block) self.delegate_to_rest_client_passive :get, client, url, headers, &block end |
.head(client, url, headers = {}, &block) ⇒ Object
26 27 28 |
# File 'lib/hash-auth/web_request.rb', line 26 def self.head(client, url, headers = {}, &block) self.delegate_to_rest_client_passive :head, client, url, headers, &block end |
.options(client, url, headers = {}, &block) ⇒ Object
30 31 32 |
# File 'lib/hash-auth/web_request.rb', line 30 def self.(client, url, headers = {}, &block) self.delegate_to_rest_client_passive :options, client, url, headers, &block end |
.patch(client, url, payload, headers = {}, &block) ⇒ Object
14 15 16 |
# File 'lib/hash-auth/web_request.rb', line 14 def self.patch(client, url, payload, headers = {}, &block) self.delegate_to_rest_client_active :post, client, url, payload, headers, &block end |
.post(client, url, payload, headers = {}, &block) ⇒ Object
10 11 12 |
# File 'lib/hash-auth/web_request.rb', line 10 def self.post(client, url, payload, headers = {}, &block) self.delegate_to_rest_client_active :post, client, url, payload, headers, &block end |
.put(client, url, payload, headers = {}, &block) ⇒ Object
18 19 20 |
# File 'lib/hash-auth/web_request.rb', line 18 def self.put(client, url, payload, headers = {}, &block) self.delegate_to_rest_client_active :post, client, url, payload, headers, &block end |
.sign_and_identify(client, verb, params) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/hash-auth/web_request.rb', line 44 def self.sign_and_identify(client, verb, params) params = self.add_client_to_params(client, params) params = self.add_signature_to_params(client, verb, params) if [:get, :delete, :head, :options].include? verb {:params => params} else params end end |