sendgo 1.3.0 → 1.4.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: e838cbd6f30a61b781b74b37eb2a088710b8a6a41594b0fcbd6eb2a874dd2849
4
- data.tar.gz: ca411988c2a81bc7957a339690392a8de14b1b0e710332305787be9a65f23302
3
+ metadata.gz: 2b098fb0eec763f43b7d70391b8a7fa5840960adc8abdf0d75f7a88106741a67
4
+ data.tar.gz: '078319bc664b5d4cb9cef93db7ba02906e4125379d2a8f0775f9f9d39d9853e7'
5
5
  SHA512:
6
- metadata.gz: a1d58de2204cb3471c287a8f4485a54cf53100b8267585e7189632883d2542cc4a5a293cce5a33c9351bfd74fcf84066e27510caba6bb5d61e784f7592c03911
7
- data.tar.gz: 90d2b439c9f969a1d13bb302694cdc6b3f0a9b01466f2b7488aa25c286a0bada3b96c3f709cdad680296e2d6e1256a753e217e6ba875fd2f0f39f70e57b42ba7
6
+ metadata.gz: e90950557127c42fb44fd94c297d8e4cd5995ddc1e34da038d30ed95286985aa976a0f0c93b64364812d3866c8d713622d26b4b8d578e507ba2ace574b1648f1
7
+ data.tar.gz: a746896ca8b37b6e06507a5800b58372826531cb6ff26233e89111c5304ad3d28e2f1c91c0450542ce411cb602f8984378ad2d3aed8387ded7b4b03edf251f9c
data/README.md CHANGED
@@ -673,3 +673,28 @@ MIT License © 2026 [Sendgo](https://sendgo.io)
673
673
  ---
674
674
 
675
675
  *키워드: 카카오 알림톡 Ruby, 카카오 친구톡 Rails, SMS 발송 Ruby, 알림톡 Ruby gem, Ruby 카카오 API 연동, Sendgo Ruby SDK, Rails 알림 발송*
676
+
677
+ ## 계정·조직·API 키 관리 (1.4.0)
678
+
679
+ 발송용 `accessKey`/`secretKey`가 없는 단계에서 사용하는 **별도 계정 클라이언트**입니다.
680
+ 콘솔에서 발급받은 에이전트 토큰(`SENDGO_AGENT_TOKEN`)으로 `/api/v2/account`를 호출합니다.
681
+ 계정 조회에는 `account:read`, 키·허용 IP 변경에는 `keys:write` 권한이 필요합니다.
682
+ 토큰 만료나 권한 부족(401/403)은 그대로 예외로 반환하며 자동 갱신·재시도하지 않습니다.
683
+
684
+ 조직 선택은 서버에 저장되는 **사용자 계정의 현재 조직**을 바꿉니다. 같은 사용자로
685
+ 여러 조직의 설정을 동시에 변경하지 마세요. 개인 계정으로 돌아가려면 조직 ID에
686
+ `null`(Python `None`, Ruby `nil`, Go `nil`) 또는 `personal`을 전달합니다.
687
+ 키 발급 응답의 `data.apiKey.secretKey`는 한 번만 반환되므로 서버의 비밀 저장소에 보관하세요.
688
+ 허용 IP가 하나라도 등록되면 목록 밖의 IP는 차단됩니다.
689
+ 에이전트 토큰과 키는 브라우저·모바일 앱에 포함하거나 응답·로그에 출력하지 않습니다.
690
+
691
+ ```ruby
692
+ account = Sendgo::AccountClient.new(agent_token: ENV.fetch('SENDGO_AGENT_TOKEN'))
693
+ result = account.me
694
+ account.select_organization('team-uuid')
695
+ issued = account.create_api_key({ name: '서버 연동' })
696
+ ```
697
+
698
+ 지원 메서드: `me`, `organizations`, `select_organization`, `api_keys`, `create_api_key`, `api_key`, `update_api_key`, `delete_api_key`, `issue_token`, `allowed_ips`, `add_allowed_ip`, `delete_allowed_ip`.
699
+
700
+ 키 생성 인자는 `name`, 선택적 `ipAddresses: [{ip, description}]`이며, 허용 IP 추가 인자는 `ip`, 선택적 `description`입니다. 키·IP 식별자는 응답의 `id`(UUID)를 사용합니다.
@@ -0,0 +1,103 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "uri"
4
+ require_relative "error"
5
+
6
+ module Sendgo
7
+ # 서버 전용 계정 API. 에이전트 토큰은 자동 갱신하지 않는다.
8
+ class AccountClient
9
+ def initialize(agent_token:, base_url: "https://sendgo.io")
10
+ raise ArgumentError, "Sendgo: agent_token은 필수입니다." if agent_token.to_s.strip.empty?
11
+ @agent_token = agent_token
12
+ @base_url = base_url.sub(%r{/+$}, "")
13
+ end
14
+
15
+ # 계정 상태와 다음 단계 조회.
16
+ def me()
17
+ request("GET", "")
18
+ end
19
+
20
+ # 조직 목록 조회.
21
+ def organizations()
22
+ request("GET", "organizations")
23
+ end
24
+
25
+ # 조직 선택. null은 개인 계정.
26
+ def select_organization(organization_id)
27
+ request("POST", "organizations/select", {'organizationId' => organization_id})
28
+ end
29
+
30
+ # 현재 조직의 API 키 목록.
31
+ def api_keys()
32
+ request("GET", "api-keys")
33
+ end
34
+
35
+ # API 키 발급. secretKey는 이 응답에서만 반환.
36
+ def create_api_key(params)
37
+ request("POST", "api-keys", params)
38
+ end
39
+
40
+ # API 키 상세 조회.
41
+ def api_key(api_key_id)
42
+ request("GET", "api-keys/#{segment(api_key_id)}")
43
+ end
44
+
45
+ # API 키 이름 변경.
46
+ def update_api_key(api_key_id, name)
47
+ request("PATCH", "api-keys/#{segment(api_key_id)}", {'name' => name})
48
+ end
49
+
50
+ # API 키 폐기.
51
+ def delete_api_key(api_key_id)
52
+ request("DELETE", "api-keys/#{segment(api_key_id)}")
53
+ end
54
+
55
+ # 승인된 API 키의 발송용 토큰 발급.
56
+ def issue_token(api_key_id)
57
+ request("POST", "api-keys/#{segment(api_key_id)}/token", {})
58
+ end
59
+
60
+ # 허용 IP 목록과 호출자 IP 조회.
61
+ def allowed_ips(api_key_id)
62
+ request("GET", "api-keys/#{segment(api_key_id)}/allowed-ips")
63
+ end
64
+
65
+ # 허용 IP 추가. ip와 선택적 description 사용.
66
+ def add_allowed_ip(api_key_id, params)
67
+ request("POST", "api-keys/#{segment(api_key_id)}/allowed-ips", params)
68
+ end
69
+
70
+ # 허용 IP 삭제.
71
+ def delete_allowed_ip(api_key_id, ip_id)
72
+ request("DELETE", "api-keys/#{segment(api_key_id)}/allowed-ips/#{segment(ip_id)}")
73
+ end
74
+
75
+ private
76
+
77
+ def segment(value)
78
+ URI.encode_www_form_component(value).gsub("+", "%20")
79
+ end
80
+
81
+ def request(method, path, body = nil)
82
+ uri = URI("#{@base_url}/api/v2/account#{path.empty? ? '' : '/' + path}")
83
+ req = Net::HTTP.const_get(method.capitalize).new(uri)
84
+ req["Authorization"] = "Bearer #{@agent_token}"
85
+ req["Accept"] = "application/json"
86
+ unless body.nil?
87
+ req["Content-Type"] = "application/json"
88
+ req.body = JSON.generate(body)
89
+ end
90
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https",
91
+ open_timeout: 10, read_timeout: 15) { |http| http.request(req) }
92
+ data = begin
93
+ JSON.parse(response.body)
94
+ rescue JSON::ParserError
95
+ {}
96
+ end
97
+ unless response.is_a?(Net::HTTPSuccess)
98
+ raise SendgoError.from_response(response.code.to_i, data, path.empty? ? "account" : path, "v2")
99
+ end
100
+ data
101
+ end
102
+ end
103
+ end
data/lib/sendgo/client.rb CHANGED
@@ -16,8 +16,12 @@ module Sendgo
16
16
 
17
17
  # 관리 API (v2 전용) — 콘솔에서만 되던 등록·심사.
18
18
  # 발송과 달리 대부분 즉시 완료되지 않는다 — 등록 성공은 "접수됨"이지
19
- # "사용 가능"이 아니다. 카카오 채널 등록의 인증번호와 휴대폰 발신번호의
20
- # 본인인증은 사람이 개입해야 하므로 API 로 대체되지 않는다.
19
+ # "사용 가능"이 아니다. 결과는 웹훅으로 받는다.
20
+ #
21
+ # 사람이 개입하는 지점은 카카오 채널 인증번호 하나뿐이고, 그마저도 여러분
22
+ # 화면에서 끝난다 — request_token 이 채널 관리자 휴대폰으로 SMS 를 보내고,
23
+ # 사용자가 입력한 코드를 create 가 받는다. 휴대폰 발신번호는 PASS 대신
24
+ # 신분증 사본을 첨부해 접수하면 sendgo 가 대신 심사한다.
21
25
  attr_reader :kakao_senders, :notice_templates, :brand_templates,
22
26
  :sender_registration, :message_templates,
23
27
  :kakao_images, :rejected_numbers, :webhook
@@ -1,3 +1,3 @@
1
1
  module Sendgo
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/sendgo.rb CHANGED
@@ -27,3 +27,5 @@ require_relative "sendgo/client"
27
27
  # )
28
28
  module Sendgo
29
29
  end
30
+
31
+ require_relative "sendgo/account"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sendgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-11 00:00:00.000000000 Z
11
+ date: 2026-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Sendgo API를 Ruby에서 간편하게 사용하기 위한 공식 SDK
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - lib/sendgo.rb
22
+ - lib/sendgo/account.rb
22
23
  - lib/sendgo/alimtalk.rb
23
24
  - lib/sendgo/brand_message.rb
24
25
  - lib/sendgo/client.rb