Class: KakaoRestApi
- Inherits:
-
Object
- Object
- KakaoRestApi
- Defined in:
- lib/kakao_rest_api.rb
Constant Summary collapse
- HOST_KAUTH =
'https://kauth.kakao.com'.freeze
- HOST_KAPI =
'https://kapi.kakao.com'.freeze
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.
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 = false) ⇒ Object
- #logout(access_token) ⇒ Object
- #me(access_token, property_keys = [], secure_resource = false) ⇒ Object
- #me_with_admin(user_id, property_keys = [], secure_resource = true) ⇒ 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_post(access_token, type, required_params, options = {}) ⇒ Object
- #story_profile(access_token, secure_resource = false) ⇒ 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.
12 13 14 15 16 |
# File 'lib/kakao_rest_api.rb', line 12 def initialize(app_key, admin_key, redirect_uri) 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.
7 8 9 |
# File 'lib/kakao_rest_api.rb', line 7 def admin_key @admin_key end |
#app_key ⇒ Object
Returns the value of attribute app_key.
7 8 9 |
# File 'lib/kakao_rest_api.rb', line 7 def app_key @app_key end |
#authorize_code ⇒ Object
Returns the value of attribute authorize_code.
7 8 9 |
# File 'lib/kakao_rest_api.rb', line 7 def @authorize_code end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
7 8 9 |
# File 'lib/kakao_rest_api.rb', line 7 def redirect_uri @redirect_uri end |
Instance Method Details
#access_token_info(access_token) ⇒ Object
89 90 91 |
# File 'lib/kakao_rest_api.rb', line 89 def access_token_info(access_token) KakaoUser.access_token_info access_token end |
#delete_my_story(access_token, id) ⇒ Object
126 127 128 |
# File 'lib/kakao_rest_api.rb', line 126 def delete_my_story(access_token, id) Story.delete_my_story access_token, id end |
#is_story_user?(access_token) ⇒ Boolean
93 94 95 |
# File 'lib/kakao_rest_api.rb', line 93 def is_story_user?(access_token) Story.story_user? access_token end |
#link_info(access_token, url) ⇒ Object
143 144 145 |
# File 'lib/kakao_rest_api.rb', line 143 def link_info(access_token, url) Story.link_info access_token, url end |
#login(state = nil, encode_state = false) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/kakao_rest_api.rb', line 22 def login(state = nil, encode_state = false) response_type = 'code' path = "/oauth/authorize?client_id=#{app_key}&redirect_uri=#{redirect_uri}&response_type=#{response_type}" path.concat("&state=#{state}") unless state.nil? path.concat('&encode_state=true') if encode_state "#{HOST_KAUTH}#{path}" end |
#logout(access_token) ⇒ Object
52 53 54 |
# File 'lib/kakao_rest_api.rb', line 52 def logout(access_token) KakaoUser.logout access_token end |
#me(access_token, property_keys = [], secure_resource = false) ⇒ Object
64 65 66 |
# File 'lib/kakao_rest_api.rb', line 64 def me(access_token, property_keys = [], secure_resource = false) KakaoUser.me access_token, property_keys, secure_resource end |
#me_with_admin(user_id, property_keys = [], secure_resource = true) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kakao_rest_api.rb', line 68 def me_with_admin(user_id, property_keys = [], secure_resource = true) = "KakaoAK #{admin_key}" params = { propertyKeys: property_keys, secure_resource: secure_resource, target_id_type: 'user_id', target_id: user_id } request_url = "#{HOST_KAPI}/v1/user/me" RestClient.post(request_url, params, Authorization: ) end |
#my_stories(access_token, last_id) ⇒ Object
122 123 124 |
# File 'lib/kakao_rest_api.rb', line 122 def my_stories(access_token, last_id) Story.my_stories access_token, last_id end |
#my_story(access_token, story_id) ⇒ Object
118 119 120 |
# File 'lib/kakao_rest_api.rb', line 118 def my_story(access_token, story_id) Story.my_story access_token, story_id end |
#refresh_token(refresh_token) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 = "#{HOST_KAUTH}/oauth/token" RestClient.post(request_url, query_params) end |
#set_authorize_code(authorize_code) ⇒ Object
18 19 20 |
# File 'lib/kakao_rest_api.rb', line 18 def () self. = end |
#signup(access_token, properties = {}) ⇒ Object
56 57 58 |
# File 'lib/kakao_rest_api.rb', line 56 def signup(access_token, properties = {}) KakaoUser.signup access_token, properties end |
#story_post(access_token, type, required_params, options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/kakao_rest_api.rb', line 101 def story_post(access_token, type, required_params, = {}) required_params[:access_token] = access_token case type when Story::POST_TYPE_NOTE Story.post_note 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.post_photo required_params, when Story::POST_TYPE_LINK url = required_params[:url] required_params[:link_info] = link_info(access_token, url) Story.post_link required_params, end end |
#story_profile(access_token, secure_resource = false) ⇒ Object
97 98 99 |
# File 'lib/kakao_rest_api.rb', line 97 def story_profile(access_token, secure_resource = false) Story.story_profile access_token, secure_resource end |
#talk_profile(access_token, secure_resource = false) ⇒ Object
130 131 132 |
# File 'lib/kakao_rest_api.rb', line 130 def talk_profile(access_token, secure_resource = false) Talk.talk_profile access_token, secure_resource end |
#token ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kakao_rest_api.rb', line 31 def token query_params = { grant_type: 'authorization_code', client_id: app_key, redirect_uri: redirect_uri, code: } request_url = "#{HOST_KAUTH}/oauth/token" RestClient.post(request_url, query_params) end |
#unlink(access_token) ⇒ Object
60 61 62 |
# File 'lib/kakao_rest_api.rb', line 60 def unlink(access_token) KakaoUser.unlink access_token end |
#update_profile(access_token, props = {}) ⇒ Object
81 82 83 |
# File 'lib/kakao_rest_api.rb', line 81 def update_profile(access_token, props = {}) KakaoUser.update_profile access_token, props end |
#upload_multi(access_token, file_paths) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/kakao_rest_api.rb', line 134 def upload_multi(access_token, file_paths) files = [] file_paths.each do |path| files << File.new(path, 'rb') end Story.upload_multi access_token, files end |