Class: PartyBus::Client
- Inherits:
-
Object
- Object
- PartyBus::Client
- Defined in:
- lib/party_bus/client.rb
Class Method Summary collapse
- .headers(timestamp, body) ⇒ Object
- .parse_response(response) ⇒ Object
- .post(body:, path:, timestamp: Time.now) ⇒ Object
Class Method Details
.headers(timestamp, body) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/party_bus/client.rb', line 34 def self.headers(, body) { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Party-Signature': { t: .to_i, v1: OpenSSL::HMAC.hexdigest( "SHA256", PartyBus.configuration.secret, "#{.to_i}.#{body.to_json}" ) }.map { |key| key.join('=') }.join(',') } end |
.parse_response(response) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/party_bus/client.rb', line 20 def self.parse_response(response) if response.success? { success: true, serialized_result: response.parsed_response } else { success: false, errors: [response.parsed_response] } end end |
.post(body:, path:, timestamp: Time.now) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/party_bus/client.rb', line 3 def self.post( body:, path:, timestamp: Time.now ) return { success: true } unless PartyBus.configuration.enabled response = HTTParty.post( "#{PartyBus.configuration.api_url}#{path}", body: body.to_json, default_timeout: 30, headers: headers(, body) ) parse_response(response) end |