File tree 2 files changed +35
-0
lines changed
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)
195
195
get ( oauth_endpoint , endpoint_path , headers )
196
196
end
197
197
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
+
198
211
# Push messages to a user using user_id.
199
212
#
200
213
# @param user_id [String] User Id
Original file line number Diff line number Diff line change 55
55
}
56
56
EOS
57
57
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
+
58
67
describe Line ::Bot ::Client do
59
68
def dummy_config
60
69
{
@@ -159,4 +168,17 @@ def generate_client
159
168
160
169
expect ( response ) . to be_a ( Net ::HTTPOK ) . and ( have_attributes ( body : VERIFY_ACCESS_TOKEN_CONTENT ) )
161
170
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
162
184
end
You can’t perform that action at this time.
0 commit comments