thai_post_tracking 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/Rakefile +5 -0
- data/lib/thai_post_tracking.rb +6 -0
- data/lib/thai_post_tracking/configuration.rb +22 -0
- data/lib/thai_post_tracking/thailand_post.rb +8 -0
- data/lib/thai_post_tracking/thailand_post/get_items.rb +12 -0
- data/lib/thai_post_tracking/thailand_post/hook_items.rb +12 -0
- data/lib/thai_post_tracking/thailand_post/request.rb +61 -0
- data/lib/thai_post_tracking/version.rb +3 -0
- data/test/test_thailand_post.rb +25 -0
- data/thai_post_tracking.gemspec +27 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0b69c126543a18c419f0f9d339b9a8486c49f195ea99f932070fc2c45317525e
|
4
|
+
data.tar.gz: d1dae593ab24473683280262551bb5cba509bd1905f0a1f101fae15765529826
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85e055f4f7e978210cd64705a66cc99a12dc7dd5e39caffde23aea0c3aba8506645e3aa6ba336132daab9d5e763b87b461fc5c5d9945f9faed45f16e1c5344a1
|
7
|
+
data.tar.gz: aa1d36e373e52b583bdf5f74264303e44013b2255f9cdb72893b6ea5ca2abdaa475b3c84033357d117b9f4e1511e87fc10cdb4c46843246f3fcecf566d7d090e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ignitry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# thai_post_tracking Ruby gems
|
2
|
+
|
3
|
+
Simple implementation of Postal services API in Thailand.
|
4
|
+
Don't have a proper test/spec at the moment, use at your own risk.
|
5
|
+
|
6
|
+
## Configure
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
ThaiPostTracking.configure do |config|
|
10
|
+
config.thailand_post_token = 'TOKEN_FROM_THAILANDPOST_SERVICE'
|
11
|
+
# https://track.thailandpost.co.th
|
12
|
+
end
|
13
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
|
3
|
+
module ThaiPostTracking
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :thailand_post_token
|
15
|
+
attr_reader :version
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@version = VERSION
|
19
|
+
@thailand_post_token_key = "replace-with-your-token"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ThaiPostTracking
|
2
|
+
module ThailandPost
|
3
|
+
class HookItems < Request
|
4
|
+
base_uri 'https://trackwebhook.thailandpost.co.th'
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@token_url = "/post/api/v1/authenticate/token"
|
8
|
+
@request_url = "/post/api/v1/hook"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module ThaiPostTracking
|
4
|
+
module ThailandPost
|
5
|
+
class Request
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@token_key = ThaiPostTracking.configuration.thailand_post_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def response(trackings)
|
13
|
+
body = {
|
14
|
+
"status" => "all",
|
15
|
+
"language" => "TH",
|
16
|
+
"barcode" => trackings
|
17
|
+
}
|
18
|
+
|
19
|
+
options = {
|
20
|
+
headers: token_header,
|
21
|
+
body: body.to_json,
|
22
|
+
debug_output: STDOUT
|
23
|
+
}
|
24
|
+
|
25
|
+
response = self.class.post(@request_url, options)
|
26
|
+
|
27
|
+
if response&.code == 200
|
28
|
+
response.parsed_response["response"]["items"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def token_header
|
33
|
+
{
|
34
|
+
Authorization: token_string,
|
35
|
+
"Content-Type" => "application/json"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def token_string
|
40
|
+
"Token #{token}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def token
|
44
|
+
response = get_token
|
45
|
+
return if response&.code != 200
|
46
|
+
JSON.parse(response.body)["token"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_token
|
50
|
+
options = {
|
51
|
+
headers: {
|
52
|
+
Authorization: "Token #{ThaiPostTracking.configuration.thailand_post_token}",
|
53
|
+
"Content-Type" => "application/json"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
self.class.post(@token_url, options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require_relative "../lib/thai_post_tracking"
|
3
|
+
|
4
|
+
class TestThailandPost < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
ThaiPostTracking.configure do |config|
|
7
|
+
config.thailand_post_token = ENV["THAILANDPOST_TOKEN"]
|
8
|
+
end
|
9
|
+
@trackings = ["EG249704385TH"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_items
|
13
|
+
@get_items = ThaiPostTracking::ThailandPost::GetItems.new
|
14
|
+
items = @get_items.response(@trackings)
|
15
|
+
|
16
|
+
assert_not_nil(items)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_hook_items
|
20
|
+
@hook_items = ThaiPostTracking::ThailandPost::HookItems.new
|
21
|
+
hooks = @hook_items.response(@trackings)
|
22
|
+
|
23
|
+
assert_not_nil(hooks)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'thai_post_tracking/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "thai_post_tracking"
|
9
|
+
spec.version = ThaiPostTracking::VERSION
|
10
|
+
spec.authors = ["Wittawas Wisarnkanchana"]
|
11
|
+
spec.email = ["start@ignitry.com"]
|
12
|
+
spec.summary = %q{.}
|
13
|
+
spec.description = %q{.}
|
14
|
+
spec.homepage = "https://github.com/ignitry/thai_post_tracking"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", ">= 1.5"
|
23
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
24
|
+
spec.add_development_dependency "test-unit", "~> 3.3"
|
25
|
+
|
26
|
+
spec.add_dependency "httparty", "~> 0.16"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thai_post_tracking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wittawas Wisarnkanchana
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.16'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.16'
|
69
|
+
description: "."
|
70
|
+
email:
|
71
|
+
- start@ignitry.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/thai_post_tracking.rb
|
82
|
+
- lib/thai_post_tracking/configuration.rb
|
83
|
+
- lib/thai_post_tracking/thailand_post.rb
|
84
|
+
- lib/thai_post_tracking/thailand_post/get_items.rb
|
85
|
+
- lib/thai_post_tracking/thailand_post/hook_items.rb
|
86
|
+
- lib/thai_post_tracking/thailand_post/request.rb
|
87
|
+
- lib/thai_post_tracking/version.rb
|
88
|
+
- test/test_thailand_post.rb
|
89
|
+
- thai_post_tracking.gemspec
|
90
|
+
homepage: https://github.com/ignitry/thai_post_tracking
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.0.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: "."
|
113
|
+
test_files:
|
114
|
+
- test/test_thailand_post.rb
|