kakao_rest_api 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/kakao_rest_api.rb +133 -0
- data/lib/v1/api/story.rb +113 -0
- data/lib/v1/api/talk.rb +11 -0
- data/lib/v1/user.rb +71 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62f7ad14fb01750d5c0fc93578878444d46f4716
|
4
|
+
data.tar.gz: 8db9528d927b240dd2c58ed1180942f388cd5f39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c0b67cbea1d6028c71c0c6df7e76fc3d13884020cbebe008b426b30fa2239522f4ff3d7d0ea52838dac68f1e0ee2296faad5b8d5d0f46849df8e8bad22e26324
|
7
|
+
data.tar.gz: 18bf86c7656f9e3171eb895cba8fe094445f64d86588a818f0eae89f80e8b31042c00af3398f02a4bfaaa6bc46bde7752e0aff11f96e0276fc8beeec47c7b187
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'v1/user'
|
3
|
+
require 'v1/api/story'
|
4
|
+
require 'v1/api/talk'
|
5
|
+
|
6
|
+
class KakaoRestApi
|
7
|
+
attr_accessor :app_key, :admin_key, :authorize_code, :redirect_uri
|
8
|
+
|
9
|
+
HOST_KAUTH = 'https://kauth.kakao.com'.freeze
|
10
|
+
HOST_KAPI = 'https://kapi.kakao.com'.freeze
|
11
|
+
|
12
|
+
def initialize(app_key, admin_key, redirect_uri)
|
13
|
+
self.app_key = app_key
|
14
|
+
self.admin_key = admin_key
|
15
|
+
self.redirect_uri = redirect_uri
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_authorize_code(authorize_code)
|
19
|
+
self.authorize_code = authorize_code
|
20
|
+
end
|
21
|
+
|
22
|
+
def login(state = nil, encode_state = false)
|
23
|
+
response_type = 'code'
|
24
|
+
path = "/oauth/authorize?client_id=#{app_key}&redirect_uri=#{redirect_uri}&response_type=#{response_type}"
|
25
|
+
path.concat("&state=#{state}") unless state.nil?
|
26
|
+
path.concat('&encode_state=true') if encode_state
|
27
|
+
|
28
|
+
"#{HOST_KAUTH}#{path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def token
|
32
|
+
query_params = {
|
33
|
+
grant_type: 'authorization_code',
|
34
|
+
client_id: app_key,
|
35
|
+
redirect_uri: redirect_uri,
|
36
|
+
code: authorize_code
|
37
|
+
}
|
38
|
+
request_url = "#{HOST_KAUTH}/oauth/token"
|
39
|
+
RestClient.post(request_url, query_params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def refresh_token(refresh_token)
|
43
|
+
query_params = {
|
44
|
+
grant_type: 'refresh_token',
|
45
|
+
client_id: app_key,
|
46
|
+
refresh_token: refresh_token
|
47
|
+
}
|
48
|
+
request_url = "#{HOST_KAUTH}/oauth/token"
|
49
|
+
RestClient.post(request_url, query_params)
|
50
|
+
end
|
51
|
+
|
52
|
+
def logout(access_token)
|
53
|
+
User.logout access_token
|
54
|
+
end
|
55
|
+
|
56
|
+
def signup(access_token, properties = {})
|
57
|
+
User.signup access_token, properties
|
58
|
+
end
|
59
|
+
|
60
|
+
def unlink(access_token)
|
61
|
+
User.unlink access_token
|
62
|
+
end
|
63
|
+
|
64
|
+
def me(access_token, property_keys = [], secure_resource = false)
|
65
|
+
User.me access_token, property_keys, secure_resource
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_profile(access_token, props = {})
|
69
|
+
User.update_profile access_token, props
|
70
|
+
end
|
71
|
+
|
72
|
+
def user_ids(limit = 100, from_id = 0, order = 'asc')
|
73
|
+
User.ids admin_key, limit, from_id, order
|
74
|
+
end
|
75
|
+
|
76
|
+
def access_token_info(access_token)
|
77
|
+
User.access_token_info access_token
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_story_user?(access_token)
|
81
|
+
Story.story_user? access_token
|
82
|
+
end
|
83
|
+
|
84
|
+
def story_profile(access_token, secure_resource = false)
|
85
|
+
Story.story_profile access_token, secure_resource
|
86
|
+
end
|
87
|
+
|
88
|
+
def story_post(access_token, type, required_params, options = {})
|
89
|
+
required_params[:access_token] = access_token
|
90
|
+
|
91
|
+
case type
|
92
|
+
when Story::POST_TYPE_NOTE
|
93
|
+
Story.post_note required_params, options
|
94
|
+
when Story::POST_TYPE_IMAGE
|
95
|
+
file_paths = required_params[:image_url_list]
|
96
|
+
required_params[:image_url_list] = upload_multi(access_token, file_paths)
|
97
|
+
Story.post_photo required_params, options
|
98
|
+
when Story::POST_TYPE_LINK
|
99
|
+
url = required_params[:url]
|
100
|
+
required_params[:link_info] = link_info(access_token, url)
|
101
|
+
Story.post_link required_params, options
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def my_story(access_token, story_id)
|
106
|
+
Story.my_story access_token, story_id
|
107
|
+
end
|
108
|
+
|
109
|
+
def my_stories(access_token, last_id)
|
110
|
+
Story.my_stories access_token, last_id
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete_my_story(access_token, id)
|
114
|
+
Story.delete_my_story access_token, id
|
115
|
+
end
|
116
|
+
|
117
|
+
def talk_profile(access_token, secure_resource = false)
|
118
|
+
Talk.talk_profile access_token, secure_resource
|
119
|
+
end
|
120
|
+
|
121
|
+
def upload_multi(access_token, file_paths)
|
122
|
+
files = []
|
123
|
+
file_paths.each do |path|
|
124
|
+
files << File.new(path, 'rb')
|
125
|
+
end
|
126
|
+
|
127
|
+
Story.upload_multi access_token, files
|
128
|
+
end
|
129
|
+
|
130
|
+
def link_info(access_token, url)
|
131
|
+
Story.link_info access_token, url
|
132
|
+
end
|
133
|
+
end
|
data/lib/v1/api/story.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
class Story
|
2
|
+
POST_TYPE_NOTE = 0
|
3
|
+
POST_TYPE_IMAGE = 1
|
4
|
+
POST_TYPE_LINK = 2
|
5
|
+
|
6
|
+
HOST_KAUTH = 'https://kauth.kakao.com'.freeze
|
7
|
+
HOST_KAPI = 'https://kapi.kakao.com'.freeze
|
8
|
+
|
9
|
+
def self.story_user?(access_token)
|
10
|
+
authorization = "Bearer #{access_token}"
|
11
|
+
|
12
|
+
request_url = "#{HOST_KAPI}/v1/api/story/isstoryuser"
|
13
|
+
RestClient.get(request_url, Authorization: authorization)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.story_profile(access_token, secure_resource = false)
|
17
|
+
authorization = "Bearer #{access_token}"
|
18
|
+
|
19
|
+
request_url = "#{HOST_KAPI}/v1/api/story/profile"
|
20
|
+
request_url.concat('?secure_resource=true') if secure_resource
|
21
|
+
RestClient.get(request_url, Authorization: authorization)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.my_story(access_token, story_id)
|
25
|
+
authorization = "Bearer #{access_token}"
|
26
|
+
|
27
|
+
request_url = "#{HOST_KAPI}/v1/api/story/mystory?id=#{story_id}"
|
28
|
+
RestClient.get(request_url, Authorization: authorization)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.my_stories(access_token, last_id)
|
32
|
+
authorization = "Bearer #{access_token}"
|
33
|
+
|
34
|
+
request_url = "#{HOST_KAPI}/v1/api/story/mystories?last_id=#{last_id}"
|
35
|
+
RestClient.get(request_url, Authorization: authorization)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.delete_my_story(access_token, id)
|
39
|
+
authorization = "Bearer #{access_token}"
|
40
|
+
|
41
|
+
request_url = "#{HOST_KAPI}/v1/api/story/delete/mystory?id=#{id}"
|
42
|
+
RestClient.delete(request_url, Authorization: authorization)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.default_story_post_options
|
46
|
+
{
|
47
|
+
permission: 'A',
|
48
|
+
enable_share: false
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.link_info(access_token, url)
|
53
|
+
authorization = "Bearer #{access_token}"
|
54
|
+
|
55
|
+
request_url = "#{HOST_KAPI}/v1/api/story/linkinfo?url=#{url}"
|
56
|
+
RestClient.get(request_url, Authorization: authorization)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.upload_multi(access_token, files)
|
60
|
+
authorization = "Bearer #{access_token}"
|
61
|
+
content_type = 'multipart/form-data; boundary=---------------------------012345678901234567890123456'
|
62
|
+
|
63
|
+
params = {
|
64
|
+
file: files,
|
65
|
+
multipart: true
|
66
|
+
}
|
67
|
+
request_url = "#{HOST_KAPI}/v1/api/story/upload/multi"
|
68
|
+
RestClient.post(request_url, params, Authorization: authorization, content_type: content_type)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.post_note(required_params, options)
|
72
|
+
content = required_params[:content]
|
73
|
+
access_token = required_params[:access_token]
|
74
|
+
authorization = "Bearer #{access_token}"
|
75
|
+
|
76
|
+
params = {}
|
77
|
+
params[:content] = content
|
78
|
+
params.merge!(options)
|
79
|
+
|
80
|
+
request_url = "#{HOST_KAPI}/v1/api/story/post/note"
|
81
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.post_photo(required_params, options)
|
85
|
+
content = options[:content]
|
86
|
+
image_url_list = required_params[:image_url_list]
|
87
|
+
access_token = required_params[:access_token]
|
88
|
+
authorization = "Bearer #{access_token}"
|
89
|
+
|
90
|
+
params = {}
|
91
|
+
params[:content] = content || ''
|
92
|
+
params[:image_url_list] = image_url_list
|
93
|
+
params.merge!(options)
|
94
|
+
|
95
|
+
request_url = "#{HOST_KAPI}/v1/api/story/post/photo"
|
96
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.post_link(required_params, options)
|
100
|
+
link_info = required_params[:link_info]
|
101
|
+
content = options[:content]
|
102
|
+
access_token = required_params[:access_token]
|
103
|
+
authorization = "Bearer #{access_token}"
|
104
|
+
|
105
|
+
params = {}
|
106
|
+
params[:content] = content || ''
|
107
|
+
params[:link_info] = link_info
|
108
|
+
params.merge!(options)
|
109
|
+
|
110
|
+
request_url = "#{HOST_KAPI}/v1/api/story/post/link"
|
111
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
112
|
+
end
|
113
|
+
end
|
data/lib/v1/api/talk.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class Talk
|
2
|
+
HOST_KAUTH = 'https://kauth.kakao.com'.freeze
|
3
|
+
HOST_KAPI = 'https://kapi.kakao.com'.freeze
|
4
|
+
|
5
|
+
def self.talk_profile(access_token, secure_resource = false)
|
6
|
+
authorization = "Bearer #{access_token}"
|
7
|
+
request_url = "#{HOST_KAPI}/v1/api/talk/profile"
|
8
|
+
request_url.concat('&secure_resource=true') if secure_resource
|
9
|
+
RestClient.get(request_url, Authorization: authorization)
|
10
|
+
end
|
11
|
+
end
|
data/lib/v1/user.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
class User
|
2
|
+
HOST_KAUTH = 'https://kauth.kakao.com'.freeze
|
3
|
+
HOST_KAPI = 'https://kapi.kakao.com'.freeze
|
4
|
+
|
5
|
+
def self.logout(access_token)
|
6
|
+
authorization = "Bearer #{access_token}"
|
7
|
+
|
8
|
+
request_url = "#{HOST_KAPI}/v1/user/logout"
|
9
|
+
RestClient.post(request_url, nil, Authorization: authorization)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.signup(access_token, properties = {})
|
13
|
+
authorization = "Bearer #{access_token}"
|
14
|
+
|
15
|
+
query_params = {
|
16
|
+
properties: properties.to_json
|
17
|
+
}
|
18
|
+
|
19
|
+
request_url = "#{HOST_KAPI}/v1/user/signup"
|
20
|
+
RestClient.post(request_url, query_params, Authorization: authorization)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.unlink(access_token)
|
24
|
+
authorization = "Bearer #{access_token}"
|
25
|
+
|
26
|
+
request_url = "#{HOST_KAPI}/v1/user/unlink"
|
27
|
+
RestClient.post(request_url, nil, Authorization: authorization)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.me(access_token, property_keys = [], secure_resource = false, user_id = 0)
|
31
|
+
authorization = "Bearer #{access_token}"
|
32
|
+
params = {
|
33
|
+
propertyKeys: property_keys,
|
34
|
+
secure_resource: secure_resource
|
35
|
+
}
|
36
|
+
if user_id > 0
|
37
|
+
params[:target_id_type] = 'user_id'
|
38
|
+
params[:target_id] = user_id
|
39
|
+
end
|
40
|
+
|
41
|
+
request_url = "#{HOST_KAPI}/v1/user/me"
|
42
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.update_profile(access_token, props = {})
|
46
|
+
authorization = "Bearer #{access_token}"
|
47
|
+
params = {
|
48
|
+
properties: props.to_json
|
49
|
+
}
|
50
|
+
request_url = "#{HOST_KAPI}/v1/user/update_profile"
|
51
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.ids(admin_key, limit = 100, from_id = 0, order = 'asc')
|
55
|
+
authorization = "KakaoAK #{admin_key}"
|
56
|
+
params = {}
|
57
|
+
params[:limit] = limit
|
58
|
+
params[:from_id] = from_id if from_id > 0
|
59
|
+
params[:order] = order
|
60
|
+
|
61
|
+
request_url = "#{HOST_KAPI}/v1/user/ids"
|
62
|
+
RestClient.post(request_url, params, Authorization: authorization)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.access_token_info(access_token)
|
66
|
+
authorization = "Bearer #{access_token}"
|
67
|
+
|
68
|
+
request_url = "#{HOST_KAPI}/v1/user/access_token_info"
|
69
|
+
RestClient.get(request_url, Authorization: authorization)
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kakao_rest_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyoungwon Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.8.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.8'
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.8.0
|
33
|
+
description: Simple Kakao platform REST API client for Ruby
|
34
|
+
email: kyoungwon.lee86@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/kakao_rest_api.rb
|
40
|
+
- lib/v1/api/story.rb
|
41
|
+
- lib/v1/api/talk.rb
|
42
|
+
- lib/v1/user.rb
|
43
|
+
homepage: http://rubygems.org/gems/kakao_rest_api
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.0.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.5.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Simple Kakao platform REST API client for Ruby
|
67
|
+
test_files: []
|