fcmpush 0.9.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/fcmpush.gemspec +5 -3
 - data/lib/fcmpush/batch.rb +37 -0
 - data/lib/fcmpush/batch_response.rb +39 -0
 - data/lib/fcmpush/client.rb +31 -1
 - data/lib/fcmpush/json_response.rb +1 -0
 - data/lib/fcmpush/version.rb +1 -1
 - metadata +16 -20
 - data/.gitignore +0 -13
 - data/.rspec +0 -3
 - data/.rubocop.yml +0 -11
 - data/.travis.yml +0 -13
 - data/Gemfile +0 -7
 - data/LICENSE.txt +0 -21
 - data/README.md +0 -99
 - data/Rakefile +0 -6
 - data/bin/console +0 -14
 - data/bin/setup +0 -8
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1daa7e3e80decc9d67986e0ee52eee2863e267dada73aab4ded259f4499577f0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c3f1ae5e9a147f98e32166ccabdc0d8f8a9ad37cf5157827c1e9d3eec67f6e15
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 44d3ca77d9d4ce80b28f4cae8a33b8a6c7ce424b796d1c7509faf353053d64f44eed78b30bf683e92c8d7da0186b19d49ee026c1297ca986dd5e8bf344789282
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 5e6cc5dbff0abaa26db3896e0662a06ea64cab2f2e5bd655710a3571eae9b407d17e0396dcce113199a8e245f105a2145a9e194dc95d84ff57e1ebedabab9e5b
         
     | 
    
        data/fcmpush.gemspec
    CHANGED
    
    | 
         @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       8 
8 
     | 
    
         
             
              spec.authors       = ['miyataka']
         
     | 
| 
       9 
9 
     | 
    
         
             
              spec.email         = ['voyager.3taka28@gmail.com']
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
              spec.summary       = 'Firebase Cloud Messaging API wrapper for ruby, supports HTTP v1.'
         
     | 
| 
      
 11 
     | 
    
         
            +
              spec.summary       = 'Firebase Cloud Messaging API wrapper for ruby, supports HTTP v1. And including access_token Auto Refresh feature!'
         
     | 
| 
       12 
12 
     | 
    
         
             
              spec.homepage      = 'https://github.com/miyataka/fcmpush'
         
     | 
| 
       13 
13 
     | 
    
         
             
              spec.license       = 'MIT'
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -16,16 +16,18 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       16 
16 
     | 
    
         
             
              spec.metadata['source_code_uri'] = 'https://github.com/miyataka/fcmpush'
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         
     | 
| 
       19 
     | 
    
         
            -
                `git ls-files -z`.split("\x0"). 
     | 
| 
      
 19 
     | 
    
         
            +
                `git ls-files -z`.split("\x0").select { |f| f.match(%r{^(lib/|fcmpush.gemspec)}) }
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
21 
     | 
    
         
             
              spec.bindir        = 'exe'
         
     | 
| 
       22 
22 
     | 
    
         
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
       23 
23 
     | 
    
         
             
              spec.require_paths = ['lib']
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
              spec.required_ruby_version = '>= 2.3', '< 2.8'
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
       25 
27 
     | 
    
         
             
              spec.add_dependency 'googleauth', '>= 0.9.0'
         
     | 
| 
       26 
28 
     | 
    
         
             
              spec.add_dependency 'net-http-persistent', '>= 3.1.0'
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
30 
     | 
    
         
             
              spec.add_development_dependency 'bundler', '~> 2.0'
         
     | 
| 
       29 
     | 
    
         
            -
              spec.add_development_dependency 'rake', '~>  
     | 
| 
      
 31 
     | 
    
         
            +
              spec.add_development_dependency 'rake', '~> 13'
         
     | 
| 
       30 
32 
     | 
    
         
             
              spec.add_development_dependency 'rspec', '~> 3.0'
         
     | 
| 
       31 
33 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Fcmpush
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Batch
         
     | 
| 
      
 3 
     | 
    
         
            +
                PART_BOUNDRY = '__END_OF_PART__'.freeze
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def make_batch_payload(messages, headers)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  uri = URI.join(domain, path)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  subrequests = messages.map do |payload|
         
     | 
| 
      
 8 
     | 
    
         
            +
                    req = Net::HTTP::Post.new(uri, headers)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    req.body = payload
         
     | 
| 
      
 10 
     | 
    
         
            +
                    req
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  subrequests.map.with_index { |req, idx| create_part(req, PART_BOUNDRY, idx) }.join + "--#{PART_BOUNDRY}\r\n"
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def create_part(request, part_boundry, idx)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  serialized_request = serialize_sub_request(request)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  "--#{part_boundry}\r\n" \
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "Content-Length: #{serialized_request.length}\r\n" \
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "Content-Type: application/http\r\n" \
         
     | 
| 
      
 20 
     | 
    
         
            +
                    "Content-Id: #{idx + 1}\r\n" \
         
     | 
| 
      
 21 
     | 
    
         
            +
                    "Content-Transfer-Encoding: binary\r\n" \
         
     | 
| 
      
 22 
     | 
    
         
            +
                    "\r\n" \
         
     | 
| 
      
 23 
     | 
    
         
            +
                    "#{serialized_request}\r\n"
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def serialize_sub_request(request)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  body_str = request.body.is_a?(String) ? request.body : request.body.to_json
         
     | 
| 
      
 28 
     | 
    
         
            +
                  subreqest = "POST #{request.path} HTTP/1.1\r\n" \
         
     | 
| 
      
 29 
     | 
    
         
            +
                              "Content-Length: #{body_str.length}\r\n"
         
     | 
| 
      
 30 
     | 
    
         
            +
                  request.to_hash.each do |k, v|
         
     | 
| 
      
 31 
     | 
    
         
            +
                    subreqest += "#{k}: #{v.join(';')}\r\n"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  subreqest += "\r\n" \
         
     | 
| 
      
 34 
     | 
    
         
            +
                               "#{body_str}\r\n"
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'delegate' if RUBY_VERSION >= '2.7'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Fcmpush
         
     | 
| 
      
 4 
     | 
    
         
            +
              class BatchResponse < DelegateClass(Net::HTTPResponse)
         
     | 
| 
      
 5 
     | 
    
         
            +
                alias response __getobj__
         
     | 
| 
      
 6 
     | 
    
         
            +
                alias headers to_hash
         
     | 
| 
      
 7 
     | 
    
         
            +
                HAS_SYMBOL_GC = RUBY_VERSION > '2.2.0'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def json
         
     | 
| 
      
 10 
     | 
    
         
            +
                  parsable? ? @parsed ||= parse_body(body) : nil
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def inspect
         
     | 
| 
      
 14 
     | 
    
         
            +
                  "#<BatchResponse response: #{response.inspect}, json: #{json}>"
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
                alias to_s inspect
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def parsable?
         
     | 
| 
      
 19 
     | 
    
         
            +
                  !body.nil? && !body.empty?
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def success_count
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @success_count ||= json.length - failure_count
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def failure_count
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @failure_count ||= json.select { |i| i[:error] }.size
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                private
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  def parse_body(raw_body)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    devider = raw_body.match(/(\r\n--batch_.*)\r\n/)[1]
         
     | 
| 
      
 34 
     | 
    
         
            +
                    raw_body.split(devider)[1..-2].map do |response|
         
     | 
| 
      
 35 
     | 
    
         
            +
                      JSON.parse(response.split("\r\n\r\n")[2], symbolize_names: HAS_SYMBOL_GC)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/fcmpush/client.rb
    CHANGED
    
    | 
         @@ -1,13 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'fcmpush/exceptions'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'fcmpush/batch'
         
     | 
| 
       2 
3 
     | 
    
         
             
            require 'fcmpush/json_response'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'fcmpush/batch_response'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
            module Fcmpush
         
     | 
| 
       5 
7 
     | 
    
         
             
              V1_ENDPOINT_PREFIX = '/v1/projects/'.freeze
         
     | 
| 
       6 
8 
     | 
    
         
             
              V1_ENDPOINT_SUFFIX = '/messages:send'.freeze
         
     | 
| 
       7 
9 
     | 
    
         
             
              TOPIC_DOMAIN = 'https://iid.googleapis.com'.freeze
         
     | 
| 
       8 
10 
     | 
    
         
             
              TOPIC_ENDPOINT_PREFIX = '/iid/v1'.freeze
         
     | 
| 
      
 11 
     | 
    
         
            +
              BATCH_ENDPOINT = '/batch'.freeze
         
     | 
| 
       9 
12 
     | 
    
         | 
| 
       10 
13 
     | 
    
         
             
              class Client
         
     | 
| 
      
 14 
     | 
    
         
            +
                include Batch
         
     | 
| 
       11 
15 
     | 
    
         
             
                attr_reader :domain, :path, :connection, :configuration, :server_key, :access_token, :access_token_expiry
         
     | 
| 
       12 
16 
     | 
    
         | 
| 
       13 
17 
     | 
    
         
             
                def initialize(domain, project_id, configuration, **options)
         
     | 
| 
         @@ -25,8 +29,13 @@ module Fcmpush 
     | 
|
| 
       25 
29 
     | 
    
         | 
| 
       26 
30 
     | 
    
         
             
                def v1_authorize
         
     | 
| 
       27 
31 
     | 
    
         
             
                  @auth ||= if configuration.json_key_io
         
     | 
| 
      
 32 
     | 
    
         
            +
                              io = if configuration.json_key_io.respond_to?(:read)
         
     | 
| 
      
 33 
     | 
    
         
            +
                                     configuration.json_key_io
         
     | 
| 
      
 34 
     | 
    
         
            +
                                   else
         
     | 
| 
      
 35 
     | 
    
         
            +
                                     File.open(configuration.json_key_io)
         
     | 
| 
      
 36 
     | 
    
         
            +
                                   end
         
     | 
| 
       28 
37 
     | 
    
         
             
                              Google::Auth::ServiceAccountCredentials.make_creds(
         
     | 
| 
       29 
     | 
    
         
            -
                                json_key_io:  
     | 
| 
      
 38 
     | 
    
         
            +
                                json_key_io: io,
         
     | 
| 
       30 
39 
     | 
    
         
             
                                scope: configuration.scope
         
     | 
| 
       31 
40 
     | 
    
         
             
                              )
         
     | 
| 
       32 
41 
     | 
    
         
             
                            else
         
     | 
| 
         @@ -60,6 +69,14 @@ module Fcmpush 
     | 
|
| 
       60 
69 
     | 
    
         
             
                  raise NetworkError, "A network error occurred: #{e.class} (#{e.message})"
         
     | 
| 
       61 
70 
     | 
    
         
             
                end
         
     | 
| 
       62 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
                def batch_push(messages, query: {}, headers: {})
         
     | 
| 
      
 73 
     | 
    
         
            +
                  uri, request = make_batch_request(messages, query, headers)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  response = exception_handler(connection.request(uri, request))
         
     | 
| 
      
 75 
     | 
    
         
            +
                  BatchResponse.new(response)
         
     | 
| 
      
 76 
     | 
    
         
            +
                rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
         
     | 
| 
      
 77 
     | 
    
         
            +
                  raise NetworkError, "A network error occurred: #{e.class} (#{e.message})"
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       63 
80 
     | 
    
         
             
                private
         
     | 
| 
       64 
81 
     | 
    
         | 
| 
       65 
82 
     | 
    
         
             
                  def make_push_request(body, query, headers)
         
     | 
| 
         @@ -121,5 +138,18 @@ module Fcmpush 
     | 
|
| 
       121 
138 
     | 
    
         
             
                      registration_tokens: instance_ids
         
     | 
| 
       122 
139 
     | 
    
         
             
                    }.to_json
         
     | 
| 
       123 
140 
     | 
    
         
             
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                  def make_batch_request(messages, query, headers)
         
     | 
| 
      
 143 
     | 
    
         
            +
                    uri = URI.join(domain, BATCH_ENDPOINT)
         
     | 
| 
      
 144 
     | 
    
         
            +
                    uri.query = URI.encode_www_form(query) unless query.empty?
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                    access_token_refresh
         
     | 
| 
      
 147 
     | 
    
         
            +
                    headers = v1_authorized_header(headers)
         
     | 
| 
      
 148 
     | 
    
         
            +
                    post = Net::HTTP::Post.new(uri, headers)
         
     | 
| 
      
 149 
     | 
    
         
            +
                    post['Content-Type'] = "multipart/mixed; boundary=#{::Fcmpush::Batch::PART_BOUNDRY}"
         
     | 
| 
      
 150 
     | 
    
         
            +
                    post.body = make_batch_payload(messages, headers)
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    [uri, post]
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
       124 
154 
     | 
    
         
             
              end
         
     | 
| 
       125 
155 
     | 
    
         
             
            end
         
     | 
    
        data/lib/fcmpush/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fcmpush
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - miyataka
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-07-22 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: googleauth
         
     | 
| 
         @@ -58,14 +58,14 @@ dependencies: 
     | 
|
| 
       58 
58 
     | 
    
         
             
                requirements:
         
     | 
| 
       59 
59 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       60 
60 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       61 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 61 
     | 
    
         
            +
                    version: '13'
         
     | 
| 
       62 
62 
     | 
    
         
             
              type: :development
         
     | 
| 
       63 
63 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       64 
64 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       65 
65 
     | 
    
         
             
                requirements:
         
     | 
| 
       66 
66 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       67 
67 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       68 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 68 
     | 
    
         
            +
                    version: '13'
         
     | 
| 
       69 
69 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       70 
70 
     | 
    
         
             
              name: rspec
         
     | 
| 
       71 
71 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -80,25 +80,17 @@ dependencies: 
     | 
|
| 
       80 
80 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       81 
81 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       82 
82 
     | 
    
         
             
                    version: '3.0'
         
     | 
| 
       83 
     | 
    
         
            -
            description: 
     | 
| 
      
 83 
     | 
    
         
            +
            description:
         
     | 
| 
       84 
84 
     | 
    
         
             
            email:
         
     | 
| 
       85 
85 
     | 
    
         
             
            - voyager.3taka28@gmail.com
         
     | 
| 
       86 
86 
     | 
    
         
             
            executables: []
         
     | 
| 
       87 
87 
     | 
    
         
             
            extensions: []
         
     | 
| 
       88 
88 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       89 
89 
     | 
    
         
             
            files:
         
     | 
| 
       90 
     | 
    
         
            -
            - ".gitignore"
         
     | 
| 
       91 
     | 
    
         
            -
            - ".rspec"
         
     | 
| 
       92 
     | 
    
         
            -
            - ".rubocop.yml"
         
     | 
| 
       93 
     | 
    
         
            -
            - ".travis.yml"
         
     | 
| 
       94 
     | 
    
         
            -
            - Gemfile
         
     | 
| 
       95 
     | 
    
         
            -
            - LICENSE.txt
         
     | 
| 
       96 
     | 
    
         
            -
            - README.md
         
     | 
| 
       97 
     | 
    
         
            -
            - Rakefile
         
     | 
| 
       98 
     | 
    
         
            -
            - bin/console
         
     | 
| 
       99 
     | 
    
         
            -
            - bin/setup
         
     | 
| 
       100 
90 
     | 
    
         
             
            - fcmpush.gemspec
         
     | 
| 
       101 
91 
     | 
    
         
             
            - lib/fcmpush.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - lib/fcmpush/batch.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
            - lib/fcmpush/batch_response.rb
         
     | 
| 
       102 
94 
     | 
    
         
             
            - lib/fcmpush/client.rb
         
     | 
| 
       103 
95 
     | 
    
         
             
            - lib/fcmpush/configuration.rb
         
     | 
| 
       104 
96 
     | 
    
         
             
            - lib/fcmpush/exceptions.rb
         
     | 
| 
         @@ -110,7 +102,7 @@ licenses: 
     | 
|
| 
       110 
102 
     | 
    
         
             
            metadata:
         
     | 
| 
       111 
103 
     | 
    
         
             
              homepage_uri: https://github.com/miyataka/fcmpush
         
     | 
| 
       112 
104 
     | 
    
         
             
              source_code_uri: https://github.com/miyataka/fcmpush
         
     | 
| 
       113 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 105 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       114 
106 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       115 
107 
     | 
    
         
             
            require_paths:
         
     | 
| 
       116 
108 
     | 
    
         
             
            - lib
         
     | 
| 
         @@ -118,7 +110,10 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       118 
110 
     | 
    
         
             
              requirements:
         
     | 
| 
       119 
111 
     | 
    
         
             
              - - ">="
         
     | 
| 
       120 
112 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       121 
     | 
    
         
            -
                  version: ' 
     | 
| 
      
 113 
     | 
    
         
            +
                  version: '2.3'
         
     | 
| 
      
 114 
     | 
    
         
            +
              - - "<"
         
     | 
| 
      
 115 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 116 
     | 
    
         
            +
                  version: '2.8'
         
     | 
| 
       122 
117 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       123 
118 
     | 
    
         
             
              requirements:
         
     | 
| 
       124 
119 
     | 
    
         
             
              - - ">="
         
     | 
| 
         @@ -126,7 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       126 
121 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       127 
122 
     | 
    
         
             
            requirements: []
         
     | 
| 
       128 
123 
     | 
    
         
             
            rubygems_version: 3.0.3
         
     | 
| 
       129 
     | 
    
         
            -
            signing_key: 
     | 
| 
      
 124 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       130 
125 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       131 
     | 
    
         
            -
            summary: Firebase Cloud Messaging API wrapper for ruby, supports HTTP v1.
         
     | 
| 
      
 126 
     | 
    
         
            +
            summary: Firebase Cloud Messaging API wrapper for ruby, supports HTTP v1. And including
         
     | 
| 
      
 127 
     | 
    
         
            +
              access_token Auto Refresh feature!
         
     | 
| 
       132 
128 
     | 
    
         
             
            test_files: []
         
     | 
    
        data/.gitignore
    DELETED
    
    
    
        data/.rspec
    DELETED
    
    
    
        data/.rubocop.yml
    DELETED
    
    
    
        data/.travis.yml
    DELETED
    
    | 
         @@ -1,13 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            sudo: false
         
     | 
| 
       2 
     | 
    
         
            -
            language: ruby
         
     | 
| 
       3 
     | 
    
         
            -
            cache: bundler
         
     | 
| 
       4 
     | 
    
         
            -
            script: bundle exec rspec
         
     | 
| 
       5 
     | 
    
         
            -
            rvm:
         
     | 
| 
       6 
     | 
    
         
            -
              - 2.3.8
         
     | 
| 
       7 
     | 
    
         
            -
              - 2.4.9
         
     | 
| 
       8 
     | 
    
         
            -
              - 2.5.7
         
     | 
| 
       9 
     | 
    
         
            -
              - 2.6.5
         
     | 
| 
       10 
     | 
    
         
            -
            before_install: gem install bundler -v 2.0.2
         
     | 
| 
       11 
     | 
    
         
            -
            notifications:
         
     | 
| 
       12 
     | 
    
         
            -
              slack:
         
     | 
| 
       13 
     | 
    
         
            -
                secure: Uckm/iIr1N6dvkzJeGes8yARAQSHLFGWjAw7CsNGiU5KERf0a/WWo+8OoWAqBtgcnqVDdBcNm0aUax+5JbfyLg0q8YW1wtYuAE2Gqocvs5TPt8XwyEQv6sYyN1mqrcJWl4FO22DCxF+Oetju1wEjpjSVYs6uzDrj7U6HzuJON/yd+lUjJWOD1OOaRJUYjI9uU7x7RRscECGU8p0ffjeiGOkM2EuJ/osA/CeDlDd93hlUpseZqxceQGdsSZHscbqV0eWVDexoPtUOIK08VFgCk3FIA4vfO8XDaBibSiqiTYUPGPQILjMhGKmB/dmz2LyxdWGdCBOjH1CnD1LXNq9yPhquDXm/2u4cVWIV7bgOHDZ6ylRz0u+AUWVMI/VJOd27YOkZCGgqbb12Y7sBh0m9KalU/fqfIafOvt24j5o2abjJCKHoTUgdESpbLYqnZvK00uRjjOp0H0yQnXicaFE4lByAGbxmpxWZ3fs1OZkppYOl8dF9AQWB6Uty4KraTpUB6fGHoE7/IPeUNsENXWPUqITsRDPFjCTWED/YvKfUi+xTA+K1vJZympsPevT6xcL82TXGDtdHA4U52MLiAuizXP/+R3XhO2PzBSyLbEMus2iJYwXsIac157uhcDrECQfIkm9DMtSHKP83ABf/Flj73NKayWYP0OsigBdUYVgs5aQ=
         
     | 
    
        data/Gemfile
    DELETED
    
    
    
        data/LICENSE.txt
    DELETED
    
    | 
         @@ -1,21 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            The MIT License (MIT)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            Copyright (c) 2019 Takayuki Miyahara
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Permission is hereby granted, free of charge, to any person obtaining a copy
         
     | 
| 
       6 
     | 
    
         
            -
            of this software and associated documentation files (the "Software"), to deal
         
     | 
| 
       7 
     | 
    
         
            -
            in the Software without restriction, including without limitation the rights
         
     | 
| 
       8 
     | 
    
         
            -
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         
     | 
| 
       9 
     | 
    
         
            -
            copies of the Software, and to permit persons to whom the Software is
         
     | 
| 
       10 
     | 
    
         
            -
            furnished to do so, subject to the following conditions:
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            The above copyright notice and this permission notice shall be included in
         
     | 
| 
       13 
     | 
    
         
            -
            all copies or substantial portions of the Software.
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         
     | 
| 
       16 
     | 
    
         
            -
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         
     | 
| 
       17 
     | 
    
         
            -
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         
     | 
| 
       18 
     | 
    
         
            -
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         
     | 
| 
       19 
     | 
    
         
            -
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         
     | 
| 
       20 
     | 
    
         
            -
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         
     | 
| 
       21 
     | 
    
         
            -
            THE SOFTWARE.
         
     | 
    
        data/README.md
    DELETED
    
    | 
         @@ -1,99 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Fcmpush [](https://travis-ci.org/miyataka/fcmpush)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            Fcmpush is an Firebase Cloud Messaging(FCM) Client. It implements [FCM HTTP v1 API](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages), including **Auto Refresh** access_token feature!!
         
     | 
| 
       4 
     | 
    
         
            -
            This gem supports HTTP v1 API only, **NOT supported [legacy HTTP protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref)**.
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            fcmpush is highly inspired by [andpush gem](https://github.com/yuki24/andpush).
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            ## Installation
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            Add this line to your application's Gemfile:
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       13 
     | 
    
         
            -
            gem 'fcmpush'
         
     | 
| 
       14 
     | 
    
         
            -
            ```
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            And then execute:
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                $ bundle
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            Or install it yourself as:
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                $ gem install fcmpush
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            ## Usage
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            on Rails, config/initializers/fcmpush.rb
         
     | 
| 
       27 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       28 
     | 
    
         
            -
            Fcmpush.configure do |config|
         
     | 
| 
       29 
     | 
    
         
            -
              ## for message push
         
     | 
| 
       30 
     | 
    
         
            -
              # firebase web console => project settings => service account => firebase admin sdk => generate new private key
         
     | 
| 
       31 
     | 
    
         
            -
              config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
              # Or set environment variables
         
     | 
| 
       34 
     | 
    
         
            -
              # ENV['GOOGLE_ACCOUNT_TYPE'] = 'service_account'
         
     | 
| 
       35 
     | 
    
         
            -
              # ENV['GOOGLE_CLIENT_ID'] = '000000000000000000000'
         
     | 
| 
       36 
     | 
    
         
            -
              # ENV['GOOGLE_CLIENT_EMAIL'] = 'xxxx@xxxx.iam.gserviceaccount.com'
         
     | 
| 
       37 
     | 
    
         
            -
              # ENV['GOOGLE_PRIVATE_KEY'] = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n\'
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              ## for topic subscribe/unsubscribe because they use regacy auth
         
     | 
| 
       40 
     | 
    
         
            -
              # firebase web console => project settings => cloud messaging => Project credentials => Server key
         
     | 
| 
       41 
     | 
    
         
            -
              config.server_key = 'your firebase server key'
         
     | 
| 
       42 
     | 
    
         
            -
              # Or set environment variables
         
     | 
| 
       43 
     | 
    
         
            -
              # ENV['FCM_SERVER_KEY'] = 'your firebase server key'
         
     | 
| 
       44 
     | 
    
         
            -
            end
         
     | 
| 
       45 
     | 
    
         
            -
            ```
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
            for more detail. see [here](https://github.com/googleapis/google-auth-library-ruby#example-service-account).
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
            ### push message
         
     | 
| 
       50 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       51 
     | 
    
         
            -
            require 'fcmpush'
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
            project_id   = "..." # Your project_id
         
     | 
| 
       54 
     | 
    
         
            -
            device_token = "..." # The device token of the device you'd like to push a message to
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
            client  = Fcmpush.new(project_id)
         
     | 
| 
       57 
     | 
    
         
            -
            payload = { # ref. https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
         
     | 
| 
       58 
     | 
    
         
            -
              message: {
         
     | 
| 
       59 
     | 
    
         
            -
                token: device_token,
         
     | 
| 
       60 
     | 
    
         
            -
                notification: {
         
     | 
| 
       61 
     | 
    
         
            -
                  title: "this is title",
         
     | 
| 
       62 
     | 
    
         
            -
                  body: "this is message body"
         
     | 
| 
       63 
     | 
    
         
            -
                }
         
     | 
| 
       64 
     | 
    
         
            -
              }
         
     | 
| 
       65 
     | 
    
         
            -
            }
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
            response = client.push(payload)
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
            json = response.json
         
     | 
| 
       70 
     | 
    
         
            -
            json[:name] # => "projects/[your_project_id]/messages/0:1571037134532751%31bd1c9631bd1c96"
         
     | 
| 
       71 
     | 
    
         
            -
            ```
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
            ### topic subscribe/unsubscribe
         
     | 
| 
       74 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       75 
     | 
    
         
            -
            require 'fcmpush'
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
            project_id   = "..." # Your project_id
         
     | 
| 
       78 
     | 
    
         
            -
            topic = "your_topic_name"
         
     | 
| 
       79 
     | 
    
         
            -
            device_tokens = ["device_tokenA", "device_tokenB", ...] # The device tokens of the device you'd like to subscribe
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
            client  = Fcmpush.new(project_id)
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
            response = client.subscribe(topic, device_tokens)
         
     | 
| 
       84 
     | 
    
         
            -
            # response = client.unsubscribe(topic, device_tokens)
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
            json = response.json
         
     | 
| 
       87 
     | 
    
         
            -
            json[:results] # => [{}, {"error":"NOT_FOUND"}, ...]  ref. https://developers.google.com/instance-id/reference/server#example_result_3
         
     | 
| 
       88 
     | 
    
         
            -
            ```
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
            ## Future Work
         
     | 
| 
       91 
     | 
    
         
            -
            - [DEV] compare other gems
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
            ## Contributing
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
            Bug reports and pull requests are welcome on GitHub at https://github.com/miyataka/fcmpush.
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
            ## License
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         
     | 
    
        data/Rakefile
    DELETED
    
    
    
        data/bin/console
    DELETED
    
    | 
         @@ -1,14 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #!/usr/bin/env ruby
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require "bundler/setup"
         
     | 
| 
       4 
     | 
    
         
            -
            require "fcmpush"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            # You can add fixtures and/or initialization code here to make experimenting
         
     | 
| 
       7 
     | 
    
         
            -
            # with your gem easier. You can also use a different console, if you like.
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            # (If you use this, don't forget to add pry to your Gemfile!)
         
     | 
| 
       10 
     | 
    
         
            -
            # require "pry"
         
     | 
| 
       11 
     | 
    
         
            -
            # Pry.start
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            require "irb"
         
     | 
| 
       14 
     | 
    
         
            -
            IRB.start(__FILE__)
         
     |