Class: KakaoRestApi
- Inherits:
-
Object
- Object
- KakaoRestApi
- Defined in:
- lib/kakao-rest-api.rb
Constant Summary collapse
- STORY_POST_TYPE_NOTE =
0
- STORY_POST_TYPE_IMAGE =
1
- STORY_POST_TYPE_LINK =
2
Instance Attribute Summary collapse
-
#admin_key ⇒ Object
Returns the value of attribute admin_key.
-
#app_key ⇒ Object
Returns the value of attribute app_key.
-
#authorize_code ⇒ Object
Returns the value of attribute authorize_code.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
Class Method Summary collapse
Instance Method Summary collapse
- #access_token_info(access_token) ⇒ Object
- #delete_my_story(access_token, id) ⇒ Object
-
#initialize(app_key, admin_key, redirect_uri) ⇒ KakaoRestApi
constructor
A new instance of KakaoRestApi.
- #is_story_user?(access_token) ⇒ Boolean
- #link_info(access_token, url) ⇒ Object
- #login(state = nil, encode_state = nil) ⇒ Object
- #logout(access_token) ⇒ Object
- #me(access_token, property_keys = [], secure_resource = false) ⇒ Object
- #my_stories(access_token, last_id) ⇒ Object
- #my_story(access_token, story_id) ⇒ Object
- #refresh_token(refresh_token) ⇒ Object
- #set_authorize_code(authorize_code) ⇒ Object
- #signup(access_token, properties = {}) ⇒ Object
- #story_profile(access_token, secure_resource = false) ⇒ Object
- #story_write_post(access_token, type, required_params, options = {}) ⇒ Object
- #talk_profile(access_token, secure_resource = false) ⇒ Object
- #token ⇒ Object
- #unlink(access_token) ⇒ Object
- #update_profile(access_token, props = {}) ⇒ Object
- #upload_multi(access_token, file_paths) ⇒ Object
- #user_ids(limit = 100, from_id = 0, order = 'asc') ⇒ Object
Constructor Details
#initialize(app_key, admin_key, redirect_uri) ⇒ KakaoRestApi
Returns a new instance of KakaoRestApi.
10 11 12 13 14 15 |
# File 'lib/kakao-rest-api.rb', line 10 def initialize(app_key, admin_key, redirect_uri) # raise ArgumentError 'required parameter is blank' if app_key.blank? || admin_key.blank? self.app_key = app_key self.admin_key = admin_key self.redirect_uri = redirect_uri end |
Instance Attribute Details
#admin_key ⇒ Object
Returns the value of attribute admin_key.
4 5 6 |
# File 'lib/kakao-rest-api.rb', line 4 def admin_key @admin_key end |
#app_key ⇒ Object
Returns the value of attribute app_key.
4 5 6 |
# File 'lib/kakao-rest-api.rb', line 4 def app_key @app_key end |
#authorize_code ⇒ Object
Returns the value of attribute authorize_code.
4 5 6 |
# File 'lib/kakao-rest-api.rb', line 4 def @authorize_code end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
4 5 6 |
# File 'lib/kakao-rest-api.rb', line 4 def redirect_uri @redirect_uri end |
Class Method Details
.default_story_post_options ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/kakao-rest-api.rb', line 171 def self. # TODO. add app schemes { permission: 'A', enable_share: false, } end |
Instance Method Details
#access_token_info(access_token) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/kakao-rest-api.rb', line 105 def access_token_info(access_token) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/user/access_token_info' RestClient.get(request_url, Authorization: ) end |
#delete_my_story(access_token, id) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/kakao-rest-api.rb', line 157 def delete_my_story(access_token, id) = "Bearer #{access_token}" request_url = "https://kapi.kakao.com/v1/api/story/delete/mystory?id=#{id}" RestClient.delete(request_url, Authorization: ) end |
#is_story_user?(access_token) ⇒ Boolean
112 113 114 115 116 117 |
# File 'lib/kakao-rest-api.rb', line 112 def is_story_user?(access_token) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/api/story/isstoryuser' RestClient.get(request_url, Authorization: ) end |
#link_info(access_token, url) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/kakao-rest-api.rb', line 196 def link_info(access_token, url) = "Bearer #{access_token}" request_url = "https://kapi.kakao.com/v1/api/story/linkinfo?url=#{url}" RestClient.get(request_url, Authorization: ) end |
#login(state = nil, encode_state = nil) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kakao-rest-api.rb', line 21 def login(state=nil, encode_state=nil) # raise ArgumentError 'required parameter is blank' if redirect_uri.blank? response_type = 'code' host = 'https://kauth.kakao.com' path = "/oauth/authorize?client_id=#{app_key}&redirect_uri=#{redirect_uri}&response_type=#{response_type}" "#{host}#{path}" end |
#logout(access_token) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/kakao-rest-api.rb', line 53 def logout(access_token) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/user/logout' RestClient.post(request_url, nil, Authorization: ) end |
#me(access_token, property_keys = [], secure_resource = false) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/kakao-rest-api.rb', line 78 def me(access_token, property_keys = [], secure_resource = false) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/user/me' RestClient.post(request_url, nil, Authorization: ) end |
#my_stories(access_token, last_id) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/kakao-rest-api.rb', line 150 def my_stories(access_token, last_id) = "Bearer #{access_token}" request_url = "https://kapi.kakao.com/v1/api/story/mystories?last_id=#{last_id}" RestClient.get(request_url, Authorization: ) end |
#my_story(access_token, story_id) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/kakao-rest-api.rb', line 143 def my_story(access_token, story_id) = "Bearer #{access_token}" request_url = "https://kapi.kakao.com/v1/api/story/mystory?id=#{story_id}" RestClient.get(request_url, Authorization: ) end |
#refresh_token(refresh_token) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kakao-rest-api.rb', line 42 def refresh_token(refresh_token) query_params = { grant_type: 'refresh_token', client_id: app_key, refresh_token: refresh_token } request_url = 'https://kauth.kakao.com/oauth/token' RestClient.post(request_url, query_params) end |
#set_authorize_code(authorize_code) ⇒ Object
17 18 19 |
# File 'lib/kakao-rest-api.rb', line 17 def () self. = end |
#signup(access_token, properties = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/kakao-rest-api.rb', line 60 def signup(access_token, properties = {}) = "Bearer #{access_token}" query_params = { properties: properties.to_json } request_url = 'https://kapi.kakao.com/v1/user/signup' RestClient.post(request_url, query_params, Authorization: ) end |
#story_profile(access_token, secure_resource = false) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/kakao-rest-api.rb', line 119 def story_profile(access_token, secure_resource = false) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/api/story/profile' RestClient.get(request_url, Authorization: ) end |
#story_write_post(access_token, type, required_params, options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kakao-rest-api.rb', line 126 def story_write_post(access_token, type, required_params, = {}) required_params[:access_token] = access_token case type when STORY_POST_TYPE_NOTE story_write_note_post required_params, when STORY_POST_TYPE_IMAGE file_paths = required_params[:image_url_list] required_params[:image_url_list] = upload_multi(access_token, file_paths) story_write_photo_post required_params, when STORY_POST_TYPE_LINK url = required_params[:url] required_params[:link_info] = link_info(access_token, url) story_write_link_post required_params, end end |
#talk_profile(access_token, secure_resource = false) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/kakao-rest-api.rb', line 164 def talk_profile(access_token, secure_resource=false) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/api/talk/profile' RestClient.get(request_url, Authorization: ) end |
#token ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kakao-rest-api.rb', line 30 def token query_params = { grant_type: 'authorization_code', client_id: app_key, redirect_uri: redirect_uri, code: } request_url = 'https://kauth.kakao.com/oauth/token' RestClient.post(request_url, query_params) end |
#unlink(access_token) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/kakao-rest-api.rb', line 71 def unlink(access_token) = "Bearer #{access_token}" request_url = 'https://kapi.kakao.com/v1/user/unlink' RestClient.post(request_url, nil, Authorization: ) end |
#update_profile(access_token, props = {}) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/kakao-rest-api.rb', line 85 def update_profile(access_token, props = {}) = "Bearer #{access_token}" params = { properties: props.to_json } request_url = 'https://kapi.kakao.com/v1/user/update_profile' RestClient.post(request_url, params, Authorization: ) end |
#upload_multi(access_token, file_paths) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/kakao-rest-api.rb', line 179 def upload_multi(access_token, file_paths) = "Bearer #{access_token}" content_type = 'multipart/form-data; boundary=---------------------------012345678901234567890123456' files = [] file_paths.each do |path| files << File.new(path, 'rb') end params = { file: files, multipart: true } request_url = 'https://kapi.kakao.com/v1/api/story/upload/multi' RestClient.post(request_url, params, Authorization: , content_type: content_type) end |
#user_ids(limit = 100, from_id = 0, order = 'asc') ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/kakao-rest-api.rb', line 94 def user_ids(limit = 100, from_id = 0, order = 'asc') = "KakaoAK #{admin_key}" params = {} params[:limit] = limit params[:from_id] = from_id if from_id > 0 params[:order] = order request_url = 'https://kapi.kakao.com/v1/user/ids' RestClient.post(request_url, params, Authorization: ) end |