@@ -507,21 +507,8 @@ def get_rich_menu_image(rich_menu_id)
507
507
def create_rich_menu_image ( rich_menu_id , file )
508
508
channel_token_required
509
509
510
- content_type = if file . respond_to? ( :content_type )
511
- content_type = file . content_type
512
- raise ArgumentError , "invalid content type: #{ content_type } " unless [ 'image/jpeg' , 'image/png' ] . include? ( content_type )
513
- content_type
514
- else
515
- case file . path
516
- when /\. jpe?g\z /i then 'image/jpeg'
517
- when /\. png\z /i then 'image/png'
518
- else
519
- raise ArgumentError , "invalid file extension: #{ file . path } "
520
- end
521
- end
522
-
523
510
endpoint_path = "/bot/richmenu/#{ rich_menu_id } /content"
524
- headers = credentials . merge ( 'Content-Type' => content_type )
511
+ headers = credentials . merge ( 'Content-Type' => content_type ( file ) )
525
512
post ( blob_endpoint , endpoint_path , file . rewind && file . read , headers )
526
513
end
527
514
@@ -697,6 +684,21 @@ def secure_compare(a, b)
697
684
res == 0
698
685
end
699
686
687
+ def content_type ( file )
688
+ if file . respond_to? ( :content_type )
689
+ content_type = file . content_type
690
+ raise ArgumentError , "invalid content type: #{ content_type } " unless [ 'image/jpeg' , 'image/png' ] . include? ( content_type )
691
+ content_type
692
+ else
693
+ case file . path
694
+ when /\. jpe?g\z /i then 'image/jpeg'
695
+ when /\. png\z /i then 'image/png'
696
+ else
697
+ raise ArgumentError , "invalid file extension: #{ file . path } "
698
+ end
699
+ end
700
+ end
701
+
700
702
def channel_token_required
701
703
raise ArgumentError , '`channel_token` is not configured' unless channel_token
702
704
end
0 commit comments