safen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17a10cc0c9cfacaa50984aa85ca92507361975d1
4
+ data.tar.gz: faf894f100c853dbd9a72c32b7364fcbe7756f0b
5
+ SHA512:
6
+ metadata.gz: 188d2c54068b41b1a0d120b78c24db0e697e161b2893c43462294ca16d441a0cdb4c31d7a93de8619adbd70ba41815be5f31f40d8ceebc78eb1851ffab45f5c9
7
+ data.tar.gz: aa9e2d62f739dcea36baee8114c34c041327ad7e19a9914430995e271af3275caa844688b842c8165150dea2864791b2d8f616d79d8001290ce330f75b4beeb7
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # IntelliJ
15
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in safen.gemspec
4
+ gemspec
@@ -0,0 +1,109 @@
1
+ # Safen
2
+
3
+ SKT Safen 연동 API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'safen'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install safen
20
+
21
+ ## Usage
22
+
23
+ ### 매핑 요청
24
+
25
+ ```
26
+ Safen.new('xxxx', ['xxx.xxx.xxx.xxx:xxxx']).create old_tel_num, group_code
27
+ ```
28
+
29
+ **params**
30
+
31
+ - `old_tel_num`: 실제 사용중인 착신번호
32
+ - `group_code`: 그룹코드
33
+
34
+ **ret**
35
+
36
+ 연동 성공시 연동된 0504 전화번호, 실패시 결과 코드표 참고
37
+
38
+ ### 수정 요청
39
+
40
+ ```
41
+ Safen.new('xxxx', ['xxx.xxx.xxx.xxx:xxxx']).update old_tel_num, group_code, new_tel_num
42
+ ```
43
+
44
+ **params**
45
+
46
+ - `old_tel_num`: 실제 사용중인 착신번호
47
+ - `group_code`: 그룹코드
48
+ - `new_tel_num`: 맵핑할 번호
49
+
50
+ **ret**
51
+
52
+ 연동 성공시 0000, 실패시 결과 코드표 참고
53
+
54
+ ### 취소 요청
55
+
56
+ ```
57
+ Safen.new('xxxx', ['xxx.xxx.xxx.xxx:xxxx']).remove new_tel_num, group_code
58
+ ```
59
+
60
+ **params**
61
+
62
+ - `new_tel_num`: 0504 연동 번호
63
+ - `group_code`: 그룹코드
64
+
65
+ **ret**
66
+
67
+ 연동 성공시 0000, 실패시 결과 코드표 참고
68
+
69
+ ### 매핑 조회
70
+
71
+ ```
72
+ Safen.new('xxxx', ['xxx.xxx.xxx.xxx:xxxx']).show new_tel_num, group_code
73
+ ```
74
+
75
+ **params**
76
+
77
+ - `corp_code`: 업체코드
78
+ - `new_tel_num`: 0504 연동 번호
79
+
80
+ **ret**
81
+
82
+ 연동 성공시 연동된 착신번호, 해지된 안심번호 조회 요청시 E401
83
+
84
+ ### 결과 코드표
85
+
86
+ | 코드 | 확인 | 설명 |
87
+ |---|---|---|
88
+ | 0000 | 성공 처리 | 인증서버에서 요청 처리가 성공. |
89
+ | E101 | Network 장애 | 인증서버와 연결 실패. |
90
+ | E102 | System 장애. | 인증서버의 일시적 장애. 재시도 요망. |
91
+ | E201 | 제휴사 인증 실패. | 유효한 제휴사 코드가 아님. |
92
+ | E202 | 유효 기간 만료. | 제휴사와의 계약기간 만료. |
93
+ | E203 | 부가서비스 인증 실패 | 제휴사의 부가서비스 인증 실패. |
94
+ | E301 | 안심 번호 소진. | 유효한 안심번호 자원이 없슴. |
95
+ | E401 | Data Not Found | 요청한 Data와 일치하는 Data가 없슴. |
96
+ | E402 | Data Overlap | 요청한 Data가 이미 존재함. |
97
+ | E501 | 전문 오류 | 전문 공통부 혹은 본문의 Data가 비정상일 경우. |
98
+ | E502 | 전화 번호 오류 | 요청한 착신번호가 맵핑불가 번호일 경우 |
99
+ | E503 | 금칙어 오류 | 요청한 알림 내용이 금칙어를 포함한 경우 |
100
+
101
+ ## Development
102
+
103
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
+
105
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/subicura/safen.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "safen"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,127 @@
1
+ require 'socket'
2
+ require 'safen/version'
3
+ require 'safen/header'
4
+ require 'safen/body'
5
+ require 'safen/error'
6
+
7
+ class Safen
8
+ attr_reader :api_server_entpoints, :corp_code
9
+
10
+ # 고객코드와 api server endpoint 리스트로 초기화
11
+ # @param corp_code [String] 고객코드
12
+ # @param api_server_entpoints list[String] endpoint ip:port
13
+ def initialize(corp_code, api_server_entpoints)
14
+ @corp_code = corp_code
15
+ @api_server_entpoints = api_server_entpoints
16
+ end
17
+
18
+ def call_api(header, body)
19
+ ret = {}
20
+
21
+ @api_server_entpoints.each_with_index do |endpoint, idx|
22
+ ip, port = endpoint.split(':')
23
+
24
+ begin
25
+ socket = TCPSocket.new(ip, port.to_i)
26
+ socket.puts("#{header}#{body}")
27
+
28
+ ret[:size] = socket.read(4).to_i
29
+ ret[:code] = socket.read(4)
30
+ ret[:corp_code] = socket.read(4)
31
+
32
+ ret[:data] = socket.read(ret[:size])
33
+
34
+ break # 성공시 탈출
35
+ rescue => e
36
+ if idx == @api_server_entpoints.size - 1 # last
37
+ raise e
38
+ else
39
+ next # 실패시 다음 엔드포인드 진행
40
+ end
41
+ ensure
42
+ socket.close if socket
43
+ end
44
+ end
45
+
46
+ if ret[:code] == '2001' # 매핑 응답
47
+ return ret[:data][20...24], ret[:data][0...20].strip
48
+ elsif ret[:code] == '2002' # 해제 응답
49
+ return ret[:data][0...4], nil
50
+ elsif ret[:code] == '2003' # 수정 응답
51
+ return ret[:data][0...4], nil
52
+ elsif ret[:code] == '2004' # 조회 응답
53
+ return ret[:data][0...4], ret[:data][4...24].strip
54
+ end
55
+
56
+ return nil, nil
57
+ end
58
+
59
+ # 매핑 요청
60
+ # @param old_tel_num [String] 실제 사용중인 착신번호
61
+ # @param group_code [String] 그룹코드
62
+ # @return [String] 매핑된 전화 번호
63
+ def create(old_tel_num, group_code)
64
+ header = Header.mapping_request(@corp_code)
65
+ body = Body.mapping_request(old_tel_num, group_code)
66
+
67
+ code, data = call_api(header, body)
68
+
69
+ if code != '0000'
70
+ raise SafenError.new(code), "Safen API call error #{code}"
71
+ end
72
+
73
+ data
74
+ end
75
+
76
+ # 수정 요청
77
+ # @param old_tel_num [String] 실제 사용중인 착신번호
78
+ # @param group_code [String] 그룹코드
79
+ # @param new_tel_num [String] 매핑할 번호
80
+ # @return [bool] 성공여부
81
+ def update(old_tel_num, group_code, new_tel_num)
82
+ header = Header.mapping_update_request(@corp_code)
83
+ body = Body.mapping_update_request(old_tel_num, new_tel_num, group_code)
84
+
85
+ code, data = call_api(header, body)
86
+
87
+ if code != '0000'
88
+ raise SafenError.new(code), "Safen API call error #{code}"
89
+ end
90
+
91
+ true
92
+ end
93
+
94
+ # 취소 요청
95
+ # @param new_tel_num [String] 매핑할 번호
96
+ # @param group_code [String] 그룹코드
97
+ # @return [bool] 성공여부
98
+ def remove(new_tel_num, group_code)
99
+ header = Header.mapping_cancel_request(@corp_code)
100
+ body = Body.mapping_cancel_request(new_tel_num, group_code)
101
+
102
+ code, data = call_api(header, body)
103
+
104
+ if code != '0000'
105
+ raise SafenError.new(code), "Safen API call error #{code}"
106
+ end
107
+
108
+ true
109
+ end
110
+
111
+ # 매핑 조회 요청
112
+ # @param new_tel_num [String] 매핑된 번호
113
+ # @param group_code [String] 그룹 코드
114
+ # @return [bool] 매핑된 전화 번호
115
+ def show(new_tel_num, group_code)
116
+ header = Header.mapping_show_request(@corp_code)
117
+ body = Body.mapping_show_request( new_tel_num, group_code)
118
+
119
+ code, data = call_api(header, body)
120
+
121
+ if code != '0000'
122
+ raise SafenError.new(code), "Safen API call error #{code}"
123
+ end
124
+
125
+ data
126
+ end
127
+ end
@@ -0,0 +1,53 @@
1
+ class Safen
2
+ class Body
3
+ class << self
4
+ # 전화번호 매핑
5
+ #
6
+ # 설명 offset, length
7
+ # 착신번호1 0, 20 (연동할 전화번호)
8
+ # 착신번호2 20, 20 (현재는 착신번호1과 동일하게 사용)
9
+ # 그룹코드 40, 10 (수정할 그룹코드)
10
+ # Reserved1 50, 50 (예약필드)
11
+ # Reserved2 100, 10 (예약필드)
12
+ def mapping_request(old_tel_num, group_code)
13
+ tel_num = old_tel_num.gsub(/-/, '')
14
+ "#{tel_num.ljust(20, ' ')}#{tel_num.ljust(20, ' ')}#{group_code.ljust(10, ' ')}#{' ' * 50}#{' ' * 10}"
15
+ end
16
+
17
+ # 전화번호 매핑 수정
18
+ def mapping_update_request(old_tel_num, new_tel_num, group_code)
19
+ default_old_tel_num = '1234567890'
20
+ old_tel_num_nomalize = old_tel_num.gsub(/-/, '')
21
+ new_tel_num_nomalize = new_tel_num.gsub(/-/, '')
22
+
23
+ ret = ''
24
+ ret += "#{new_tel_num_nomalize.ljust(20, ' ')}"
25
+ ret += "#{default_old_tel_num.ljust(20, ' ')}#{old_tel_num_nomalize.ljust(20, ' ')}"
26
+ ret += "#{default_old_tel_num.ljust(20, ' ')}#{old_tel_num_nomalize.ljust(20, ' ')}"
27
+ ret += "#{group_code.ljust(10, ' ')}"
28
+ ret += "#{' ' * 50}#{' ' * 10}"
29
+
30
+ ret
31
+ end
32
+
33
+ # 전화번호 매핑 해제
34
+ #
35
+ # 설명 offset, length
36
+ # 0504 매핑번호 0, 20 (매핑된 전화번호)
37
+ # 그룹코드 20, 10 (수정할 그룹코드)
38
+ def mapping_cancel_request(new_tel_num, group_code)
39
+ tel_num = new_tel_num.gsub(/-/, '')
40
+ "#{tel_num.ljust(20, ' ')}#{group_code.ljust(10, ' ')}"
41
+ end
42
+
43
+ # 전화번호 매핑 조회
44
+ #
45
+ # 설명 offset, length
46
+ # 0504 매핑번호 0, 20 (매핑된 전화번호)
47
+ def mapping_show_request(new_tel_num, group_code)
48
+ tel_num = new_tel_num.gsub(/-/, '')
49
+ "#{tel_num.ljust(20, ' ')}"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ class Safen
2
+ class SafenError < StandardError
3
+ attr_reader :code
4
+
5
+ def initialize(code = nil)
6
+ @code = code
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ class Safen
2
+ class Header
3
+ class << self
4
+ # 전화번호 매핑
5
+ def mapping_request(corp_code)
6
+ create_header 110, '1001', corp_code
7
+ end
8
+
9
+ # 전화번호 매핑 수정
10
+ def mapping_update_request(corp_code)
11
+ create_header 170, '1003', corp_code
12
+ end
13
+
14
+ # 전화번호 매핑 해제
15
+ def mapping_cancel_request(corp_code)
16
+ create_header 30, '1002', corp_code
17
+ end
18
+
19
+ # 전화번호 매핑 조회
20
+ def mapping_show_request(corp_code)
21
+ create_header 20, '1004', corp_code
22
+ end
23
+
24
+ # 전문길이 (4byte) Header를 제외한 Body data size
25
+ # 업무구분코드 (4byte)
26
+ # 업체코드 (4byte) Telink 에서 부여.
27
+ def create_header(len, code, corp_code)
28
+ "#{len.to_s.rjust(4, '0')}#{code}#{corp_code}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class Safen
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'safen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'safen'
8
+ spec.version = Safen::VERSION
9
+ spec.authors = ['subicura']
10
+ spec.email = ['subicura@subicura.com']
11
+
12
+ spec.summary = %q{Ruby bindings for the SKT safen API}
13
+ spec.description = %q{SKT safen is 0504 tel service.}
14
+ spec.homepage = 'https://github.com/subicura/safen-ruby'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - subicura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-01 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: SKT safen is 0504 tel service.
56
+ email:
57
+ - subicura@subicura.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/safen.rb
71
+ - lib/safen/body.rb
72
+ - lib/safen/error.rb
73
+ - lib/safen/header.rb
74
+ - lib/safen/version.rb
75
+ - safen.gemspec
76
+ homepage: https://github.com/subicura/safen-ruby
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby bindings for the SKT safen API
99
+ test_files: []