Sha256: d23784046d24facd4d95f3a5350d7a0ee43dcc8422daf21ab513cd788033936b

Contents?: true

Size: 1013 Bytes

Versions: 1

Compression:

Stored size: 1013 Bytes

Contents

require 'faraday_middleware'

module ZeroPush
  class Client

    def initialize(auth_token)
      @faraday = Faraday.new(url: ZeroPush::URL) do |c|
        c.token_auth auth_token                        # Set the Authorization header
        c.request    :url_encoded                      # form-encode POST params
        c.response   :json, :content_type => /\bjson$/ # parse responses to JSON
        c.adapter    Faraday.default_adapter           # Net::HTTP
      end
    end

    def verify_credentials
      response = faraday.get('/verify_credentials')
      response.status == 200
    end

    def notify(params)
      faraday.post('/notify', params)
    end

    def register(device_token)
      faraday.post('/register', device_token: device_token)
    end

    def set_badge(device_token, badge)
      faraday.post('/set_badge', device_token: device_token, badge: badge)
    end

    def inactive_tokens
      faraday.get('/inactive_tokens')
    end

    private
      attr_reader :faraday
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zero_push-1.3.0 lib/zero_push/client.rb