lalamove 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24d1e37da725bf91bcf6365a99d3ffcfa4484ca1bdf5787cbacb591d60c62549
4
- data.tar.gz: 47280e665b8856d3adf2b0caab1d89091812ddd4aa038107d7af29a4b7747427
3
+ metadata.gz: 9503550a872c14c7b872c9eebae61e8095d1e6eb763531ab14ca52e96ffefc18
4
+ data.tar.gz: c6c9209681e84a41d494e80ebeef8ec95f78e7f813a301d10a49b80970db1ecd
5
5
  SHA512:
6
- metadata.gz: 8661f5d686217f96c15c15ca58de3e94df1c38cfc00e0722b5bbed84c99d0f70459cac41fc3d7c390ef03bada07eb963c2bb86bfc1d85d31fe66539acf7641ab
7
- data.tar.gz: 70df362ea8ad27e3e12db46365de258ac77d662424e87b2a9e0f91cce48130a827370468ffadac799457f7aa6c554a7f31d5478f737313533f00499eaede1bfb
6
+ metadata.gz: f9125682fb358560801cdf77e152562c76eadb1fa220b2c94311fdcd27c0044a6bfe3d784e9247a15ed5f01ad600f578d8cf971f22aac63c3f8468bb384ecb90
7
+ data.tar.gz: ae416654049122ce823ca511b290960904960c8806d39037da2b21c460a11bdf2fa4e61c64ca7a02cf32d718013ef2bec22b2d242f1ad97270aa44f48ef946ef
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lalamove (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.13.0)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 2.0)
17
+ lalamove!
18
+ minitest (~> 5.0)
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 2.0.2
data/README.md CHANGED
@@ -27,6 +27,7 @@ Or install it yourself as:
27
27
  config.mode = :sandbox
28
28
  config.key = 'your_key'
29
29
  config.secret_key = 'your_secret_key'
30
+ config.country_code = [Check all available countries here](https://developers.lalamove.com/?plaintext--sandbox#available-countries)
30
31
  end
31
32
 
32
33
  Set config.mode to either :sandbox or :prod to switch between the sandbox and prod endpoints, keys to the corresponding keys provided by Lalamove.
data/lib/lalamove.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "lalamove/version"
2
2
  require "lalamove/configuration"
3
+ require "lalamove/service"
3
4
 
4
5
  module Lalamove
5
6
  class Error < StandardError; end
@@ -14,5 +15,4 @@ module Lalamove
14
15
  def self.configure
15
16
  yield(config)
16
17
  end
17
-
18
18
  end
@@ -4,11 +4,6 @@ module Lalamove
4
4
  attr_writer :base_url, :mode
5
5
  end
6
6
 
7
- def initialize
8
- @key
9
- @secret_key
10
- end
11
-
12
7
  SANDBOX_BASE_URL = 'https://sandbox-rest.lalamove.com'.freeze
13
8
  PROD_BASE_URL = 'https://rest.lalamove.com'.freeze
14
9
 
@@ -22,6 +17,4 @@ module Lalamove
22
17
  return @mode unless @mode.nil?
23
18
  :sandbox
24
19
  end
25
-
26
-
27
20
  end
@@ -0,0 +1,47 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'net/http'
4
+ require 'httparty'
5
+
6
+ module Lalamove
7
+ module Helper
8
+ def self.request(path, payload, method)
9
+ timestamp = get_timestamp
10
+ signature = generate_signature(path, method, timestamp, payload)
11
+ token = get_token(key, timestamp, signature)
12
+ headers = get_header(token, timestamp.to_s)
13
+ request_url = request_url(path)
14
+
15
+ HTTParty.post(request_url, :headers => headers, :body => payload.to_json.to_s)
16
+ end
17
+
18
+ def self.generate_signature(path, method, timestamp, payload)
19
+ generate_raw_signature(method, timestamp, path, payload)
20
+ OpenSSL::HMAC.hexdigest('sha256', @secret, raw_signature)
21
+ end
22
+
23
+ def self.generate_raw_signature(method, timestamp,path, payload)
24
+ "#{timestamp}\r\n#{method}\r\n#{path}\r\n\r\n#{payload}"
25
+ end
26
+
27
+ def self.get_timestamp
28
+ (Time.now.to_f * 1000).to_i
29
+ end
30
+
31
+ def self.get_header(token, timestamp)
32
+ {
33
+ "Authorization" => "hmac #{token}",
34
+ "X-LLM-Country" => Lalamove.config.country_code,
35
+ "X-Request-ID" => timestamp.to_s
36
+ }
37
+ end
38
+
39
+ def self.get_token(key, timestamp, signature)
40
+ "#{key}:#{timestamp}:#{signature}"
41
+ end
42
+
43
+ def self.request_url(path)
44
+ Lalamove.config.base_url + path
45
+ end
46
+ end
47
+ end
@@ -1,7 +1,9 @@
1
+ require 'lalamove/helper'
2
+
1
3
  module Lalamove
2
4
  class Service
3
- def generate
4
- puts 'hello world'
5
+ def quotation(payload)
6
+ Helper.request('/v2/quotations', payload, "POST")
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module Lalamove
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lalamove
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Arevalo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ files:
63
63
  - ".travis.yml"
64
64
  - CODE_OF_CONDUCT.md
65
65
  - Gemfile
66
+ - Gemfile.lock
66
67
  - LICENSE.txt
67
68
  - README.md
68
69
  - Rakefile
@@ -71,6 +72,7 @@ files:
71
72
  - lalamove.gemspec
72
73
  - lib/lalamove.rb
73
74
  - lib/lalamove/configuration.rb
75
+ - lib/lalamove/helper.rb
74
76
  - lib/lalamove/service.rb
75
77
  - lib/lalamove/version.rb
76
78
  homepage: https://developers.lalamove.com/