Module: Lalamove::Helper
- Defined in:
- lib/lalamove/helper.rb
Class Method Summary collapse
- .generate_raw_signature(method, timestamp, path, payload) ⇒ Object
- .generate_signature(path, method, timestamp, payload) ⇒ Object
- .get_header(token, timestamp) ⇒ Object
- .get_timestamp ⇒ Object
- .get_token(key, timestamp, signature) ⇒ Object
- .request(path, payload, method) ⇒ Object
- .request_url(path) ⇒ Object
Class Method Details
.generate_raw_signature(method, timestamp, path, payload) ⇒ Object
27 28 29 |
# File 'lib/lalamove/helper.rb', line 27 def self.generate_raw_signature(method, ,path, payload) "#{}\r\n#{method}\r\n#{path}\r\n\r\n#{payload}" end |
.generate_signature(path, method, timestamp, payload) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/lalamove/helper.rb', line 20 def self.generate_signature(path, method, , payload) raw_signature = generate_raw_signature(method, , path, payload) puts "Key config" puts Lalamove.config.secret_key OpenSSL::HMAC.hexdigest('sha256', Lalamove.config.secret_key, raw_signature) end |
.get_header(token, timestamp) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/lalamove/helper.rb', line 35 def self.get_header(token, ) { "Authorization" => "hmac #{token}", "X-LLM-Country" => Lalamove.config.country_code, "X-Request-ID" => .to_s } end |
.get_timestamp ⇒ Object
31 32 33 |
# File 'lib/lalamove/helper.rb', line 31 def self. (Time.now.to_f * 1000).to_i end |
.get_token(key, timestamp, signature) ⇒ Object
43 44 45 |
# File 'lib/lalamove/helper.rb', line 43 def self.get_token(key, , signature) "#{key}:#{}:#{signature}" end |
.request(path, payload, method) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/lalamove/helper.rb', line 10 def self.request(path, payload, method) = puts signature = generate_signature(path, method, , payload) token = get_token(Lalamove.config.key, , signature) headers = get_header(token, .to_s) url = request_url(path) HTTParty.post(url, :headers => headers, :body => payload.to_json.to_s) end |