@@ -507,21 +507,8 @@ def get_rich_menu_image(rich_menu_id)
507507 def create_rich_menu_image ( rich_menu_id , file )
508508 channel_token_required
509509
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-
523510 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 ) )
525512 post ( blob_endpoint , endpoint_path , file . rewind && file . read , headers )
526513 end
527514
@@ -697,6 +684,21 @@ def secure_compare(a, b)
697684 res == 0
698685 end
699686
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+
700702 def channel_token_required
701703 raise ArgumentError , '`channel_token` is not configured' unless channel_token
702704 end
0 commit comments