kakao-rest-api 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/kakao-rest-api.rb +247 -0
  3. metadata +64 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de0f57ef24ccf97384a7dac95ff9796af913bbf1
4
+ data.tar.gz: c2d83f58c7e7dca065d7c9b62a61795810f04433
5
+ SHA512:
6
+ metadata.gz: 507bd3442b357be53f2bea8177f1fff916e8a75be6d0360aa41b11190fdd07f62835862fbdf7fda88bde1a4d5f8025e66f856e846c2b183c97712d0a6290093c
7
+ data.tar.gz: 115752456445a9bd0cd40f6855ae54fd2e8500181ea5d04c4a01ed37c6a780869af38e05f7d02213c57d0b68dc08a9f4cddd53364295edddd03af06b0ff22161
@@ -0,0 +1,247 @@
1
+ require 'rest-client'
2
+
3
+ class KakaoRestApi
4
+ attr_accessor :app_key, :admin_key, :authorize_code, :redirect_uri
5
+
6
+ STORY_POST_TYPE_NOTE = 0
7
+ STORY_POST_TYPE_IMAGE = 1
8
+ STORY_POST_TYPE_LINK = 2
9
+
10
+ def initialize(app_key, admin_key, redirect_uri)
11
+ # raise ArgumentError 'required parameter is blank' if app_key.blank? || admin_key.blank?
12
+ self.app_key = app_key
13
+ self.admin_key = admin_key
14
+ self.redirect_uri = redirect_uri
15
+ end
16
+
17
+ def set_authorize_code(authorize_code)
18
+ self.authorize_code = authorize_code
19
+ end
20
+
21
+ def login(state=nil, encode_state=nil)
22
+ # raise ArgumentError 'required parameter is blank' if redirect_uri.blank?
23
+ response_type = 'code'
24
+ host = 'https://kauth.kakao.com'
25
+ path = "/oauth/authorize?client_id=#{app_key}&redirect_uri=#{redirect_uri}&response_type=#{response_type}"
26
+
27
+ "#{host}#{path}"
28
+ end
29
+
30
+ def token
31
+ query_params = {
32
+ grant_type: 'authorization_code',
33
+ client_id: app_key,
34
+ redirect_uri: redirect_uri,
35
+ code: authorize_code
36
+ }
37
+
38
+ request_url = 'https://kauth.kakao.com/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
+
49
+ request_url = 'https://kauth.kakao.com/oauth/token'
50
+ RestClient.post(request_url, query_params)
51
+ end
52
+
53
+ def logout(access_token)
54
+ authorization = "Bearer #{access_token}"
55
+
56
+ request_url = 'https://kapi.kakao.com/v1/user/logout'
57
+ RestClient.post(request_url, nil, Authorization: authorization)
58
+ end
59
+
60
+ def signup(access_token, properties = {})
61
+ authorization = "Bearer #{access_token}"
62
+
63
+ query_params = {
64
+ properties: properties.to_json
65
+ }
66
+
67
+ request_url = 'https://kapi.kakao.com/v1/user/signup'
68
+ RestClient.post(request_url, query_params, Authorization: authorization)
69
+ end
70
+
71
+ def unlink(access_token)
72
+ authorization = "Bearer #{access_token}"
73
+
74
+ request_url = 'https://kapi.kakao.com/v1/user/unlink'
75
+ RestClient.post(request_url, nil, Authorization: authorization)
76
+ end
77
+
78
+ def me(access_token, property_keys = [], secure_resource = false)
79
+ authorization = "Bearer #{access_token}"
80
+
81
+ request_url = 'https://kapi.kakao.com/v1/user/me'
82
+ RestClient.post(request_url, nil, Authorization: authorization)
83
+ end
84
+
85
+ def update_profile(access_token, props = {})
86
+ authorization = "Bearer #{access_token}"
87
+ params = {
88
+ properties: props.to_json
89
+ }
90
+ request_url = 'https://kapi.kakao.com/v1/user/update_profile'
91
+ RestClient.post(request_url, params, Authorization: authorization)
92
+ end
93
+
94
+ def user_ids(limit = 100, from_id = 0, order = 'asc')
95
+ authorization = "KakaoAK #{admin_key}"
96
+ params = {}
97
+ params[:limit] = limit
98
+ params[:from_id] = from_id if from_id > 0
99
+ params[:order] = order
100
+
101
+ request_url = 'https://kapi.kakao.com/v1/user/ids'
102
+ RestClient.post(request_url, params, Authorization: authorization)
103
+ end
104
+
105
+ def access_token_info(access_token)
106
+ authorization = "Bearer #{access_token}"
107
+
108
+ request_url = 'https://kapi.kakao.com/v1/user/access_token_info'
109
+ RestClient.get(request_url, Authorization: authorization)
110
+ end
111
+
112
+ def is_story_user?(access_token)
113
+ authorization = "Bearer #{access_token}"
114
+
115
+ request_url = 'https://kapi.kakao.com/v1/api/story/isstoryuser'
116
+ RestClient.get(request_url, Authorization: authorization)
117
+ end
118
+
119
+ def story_profile(access_token, secure_resource = false)
120
+ authorization = "Bearer #{access_token}"
121
+
122
+ request_url = 'https://kapi.kakao.com/v1/api/story/profile'
123
+ RestClient.get(request_url, Authorization: authorization)
124
+ end
125
+
126
+ def story_write_post(access_token, type, required_params, options = {})
127
+ required_params[:access_token] = access_token
128
+
129
+ case type
130
+ when STORY_POST_TYPE_NOTE
131
+ story_write_note_post required_params, options
132
+ when STORY_POST_TYPE_IMAGE
133
+ file_paths = required_params[:image_url_list]
134
+ required_params[:image_url_list] = upload_multi(access_token, file_paths)
135
+ story_write_photo_post required_params, options
136
+ when STORY_POST_TYPE_LINK
137
+ url = required_params[:url]
138
+ required_params[:link_info] = link_info(access_token, url)
139
+ story_write_link_post required_params, options
140
+ end
141
+ end
142
+
143
+ def my_story(access_token, story_id)
144
+ authorization = "Bearer #{access_token}"
145
+
146
+ request_url = "https://kapi.kakao.com/v1/api/story/mystory?id=#{story_id}"
147
+ RestClient.get(request_url, Authorization: authorization)
148
+ end
149
+
150
+ def my_stories(access_token, last_id)
151
+ authorization = "Bearer #{access_token}"
152
+
153
+ request_url = "https://kapi.kakao.com/v1/api/story/mystories?last_id=#{last_id}"
154
+ RestClient.get(request_url, Authorization: authorization)
155
+ end
156
+
157
+ def delete_my_story(access_token, id)
158
+ authorization = "Bearer #{access_token}"
159
+
160
+ request_url = "https://kapi.kakao.com/v1/api/story/delete/mystory?id=#{id}"
161
+ RestClient.delete(request_url, Authorization: authorization)
162
+ end
163
+
164
+ def talk_profile(access_token, secure_resource=false)
165
+ authorization = "Bearer #{access_token}"
166
+
167
+ request_url = 'https://kapi.kakao.com/v1/api/talk/profile'
168
+ RestClient.get(request_url, Authorization: authorization)
169
+ end
170
+
171
+ def self.default_story_post_options
172
+ # TODO. add app schemes
173
+ {
174
+ permission: 'A',
175
+ enable_share: false,
176
+ }
177
+ end
178
+
179
+ def upload_multi(access_token, file_paths)
180
+ authorization = "Bearer #{access_token}"
181
+ content_type = 'multipart/form-data; boundary=---------------------------012345678901234567890123456'
182
+
183
+ files = []
184
+ file_paths.each do |path|
185
+ files << File.new(path, 'rb')
186
+ end
187
+
188
+ params = {
189
+ file: files,
190
+ multipart: true
191
+ }
192
+ request_url = 'https://kapi.kakao.com/v1/api/story/upload/multi'
193
+ RestClient.post(request_url, params, Authorization: authorization, content_type: content_type)
194
+ end
195
+
196
+ def link_info(access_token, url)
197
+ authorization = "Bearer #{access_token}"
198
+
199
+ request_url = "https://kapi.kakao.com/v1/api/story/linkinfo?url=#{url}"
200
+ RestClient.get(request_url, Authorization: authorization)
201
+ end
202
+
203
+ private
204
+
205
+ def story_write_note_post(required_params, options)
206
+ content = required_params[:content]
207
+ access_token = required_params[:access_token]
208
+ authorization = "Bearer #{access_token}"
209
+
210
+ params = {}
211
+ params[:content] = content
212
+ params.merge!(options)
213
+
214
+ request_url = 'https://kapi.kakao.com/v1/api/story/post/note'
215
+ RestClient.post(request_url, params, Authorization: authorization)
216
+ end
217
+
218
+ def story_write_photo_post(required_params, options)
219
+ content = required_params[:content]
220
+ image_url_list = required_params[:image_url_list]
221
+ access_token = required_params[:access_token]
222
+ authorization = "Bearer #{access_token}"
223
+
224
+ params = {}
225
+ params[:content] = content || ''
226
+ params[:image_url_list] = image_url_list
227
+ params.merge!(options)
228
+
229
+ request_url = 'https://kapi.kakao.com/v1/api/story/post/photo'
230
+ RestClient.post(request_url, params, Authorization: authorization)
231
+ end
232
+
233
+ def story_write_link_post(required_params, options)
234
+ link_info = required_params[:link_info]
235
+ content = required_params[:content]
236
+ access_token = required_params[:access_token]
237
+ authorization = "Bearer #{access_token}"
238
+
239
+ params = {}
240
+ params[:content] = content || ''
241
+ params[:link_info] = link_info
242
+ params.merge!(options)
243
+
244
+ request_url = 'https://kapi.kakao.com/v1/api/story/post/link'
245
+ RestClient.post(request_url, params, Authorization: authorization)
246
+ end
247
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kakao-rest-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
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
+ homepage: http://rubygems.org/gems/kakao-rest-api
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.5.1
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Simple Kakao platform REST API client for Ruby
64
+ test_files: []