lib/zero_push.rb in zero_push-2.4.1 vs lib/zero_push.rb in zero_push-2.5.0
- old
+ new
@@ -2,48 +2,42 @@
require 'zero_push/client'
require 'faraday'
module ZeroPush
class << self
- attr_accessor :auth_token
+ extend Forwardable
+ attr_accessor :auth_token, :auth_tokens, :config
- def verify_credentials
- client.verify_credentials
- end
+ def_delegators :client,
+ :verify_credentials,
+ :notify,
+ :broadcast,
+ :subscribe,
+ :unsubscribe,
+ :register,
+ :unregister,
+ :set_badge,
+ :inactive_tokens,
+ :devices,
+ :set_device,
+ :update_device,
+ :channels,
+ :channel,
+ :delete_channel
- def notify(params)
- client.notify(params)
+ def client(auth_token = self.auth_token)
+ ZeroPush::Client.new(auth_token)
end
- def broadcast(params)
- client.broadcast(params)
+ def config
+ @config ||= {:http_adapter => Faraday.default_adapter, request_encoding: :json}
end
- def subscribe(device_token, channel)
- client.subscribe(device_token, channel)
- end
-
- def unsubscribe(device_token, channel)
- client.unsubscribe(device_token, channel)
- end
-
- def register(device_token, channel=nil)
- client.register(device_token, channel)
- end
-
- def unregister(device_token)
- client.unregister(device_token)
- end
-
- def set_badge(device_token, badge)
- client.set_badge(device_token, badge)
- end
-
- def inactive_tokens
- client.inactive_tokens
- end
-
- def client(auth_token = self.auth_token)
- ZeroPush::Client.new(auth_token)
+ def method_missing(method, *params, &block)
+ if auth_tokens.is_a?(Hash) && auth_tokens.keys.include?(method)
+ self.client(auth_tokens[method])
+ else
+ super
+ end
end
end
end