title: Using Ruby to send notification to Firebase
body: <p>I am using Ruby version 1.8.7.</p>
  
  <p>I use this FCM gem <a href="https://github.com/spacialdb/fcm" rel="nofollow noreferrer">https://github.com/spacialdb/fcm</a> and want to send notification message to Android client app but it does not work.</p>
  
  <p>In Controller:</p>
  
  <pre><code>fcm = FCM.new(FIREBASE_API_KEY, :timeout =&gt; 30)
   options = {:data =&gt; {:message =&gt; "This is a FCM Topic Message!"}}
   response = fcm.send_to_topic('global', options)
  </code></pre>
  
  <p>Class FCM:</p>
  
  <pre><code>require 'httparty'
  require 'cgi'
  require 'json'
  
  class FCM
    include HTTParty
    base_uri 'https://fcm.googleapis.com/fcm'
    default_timeout 30
    format :json
  
    attr_accessor :timeout, :api_key
  
    def initialize(api_key, client_options = {})
      @api_key = api_key
      @client_options = client_options
    end
  
    def send_with_notification_key(notification_key, options = {})
      body = { :to =&gt; notification_key }.merge(options)
  
      params = {
          :body =&gt; body.to_json,
          :headers =&gt; {
          'Authorization' =&gt; "key=#{@api_key}",
          'Content-Type' =&gt; 'application/json'
      }
    }
  
    response = self.class.post('/send', params.merge(@client_options))
    response.parsed_response
    end
  
    def send_to_topic(topic, options = {})
      if topic =~ /[a-zA-Z0-9\-_.~%]+/
          send_with_notification_key('/topics/' + topic, options)
      end
    end
  end
  </code></pre>
  
  <ol>
  <li>The server key is correct, because I can send notification successfully by PHP code.</li>
  <li>The response output as below:
  {"message_id"=>8885803884270587181}</li>
  </ol>
  
  <p>Could anyone please to point out what wrong with the code. 
  Any help would be greatly appreciated.</p>