File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,19 @@ def get_channel_access_token_key_ids_jwt(jwt)
195195 get ( oauth_endpoint , endpoint_path , headers )
196196 end
197197
198+ # Get user profile by access token
199+ #
200+ # @param access_token [String] access token
201+ #
202+ # @return [Net::HTTPResponse]
203+ def get_profile_by_access_token ( access_token )
204+ headers = {
205+ "Authorization" => "Bearer #{ access_token } " ,
206+ }
207+ endpoint_path = "/v2/profile"
208+ get ( oauth_endpoint , endpoint_path , headers )
209+ end
210+
198211 # Push messages to a user using user_id.
199212 #
200213 # @param user_id [String] User Id
Original file line number Diff line number Diff line change 5555}
5656EOS
5757
58+ PROFILE_BY_ACCESS_TOKEN_CONTENT = <<"EOS"
59+ {
60+ "userId": "U4af4980629...",
61+ "displayName": "Brown",
62+ "pictureUrl": "https://profile.line-scdn.net/abcdefghijklmn",
63+ "statusMessage": "Hello, LINE!"
64+ }
65+ EOS
66+
5867describe Line ::Bot ::Client do
5968 def dummy_config
6069 {
@@ -159,4 +168,17 @@ def generate_client
159168
160169 expect ( response ) . to be_a ( Net ::HTTPOK ) . and ( have_attributes ( body : VERIFY_ACCESS_TOKEN_CONTENT ) )
161170 end
171+
172+ it 'gets profile by access token' do
173+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_OAUTH_ENDPOINT + '/v2/profile'
174+ stub_request ( :get , uri_template )
175+ . with ( headers : { 'Authorization' => 'Bearer dummy_access_token' } )
176+ . to_return { |request | { body : PROFILE_BY_ACCESS_TOKEN_CONTENT , status : 200 } }
177+
178+ client = generate_client
179+
180+ response = client . get_profile_by_access_token ( 'dummy_access_token' )
181+
182+ expect ( response ) . to be_a ( Net ::HTTPOK ) . and ( have_attributes ( body : PROFILE_BY_ACCESS_TOKEN_CONTENT ) )
183+ end
162184end
You can’t perform that action at this time.
0 commit comments