class Firepush::Client
Constants
- BASE_PATH
- BASE_URI
Attributes
access_token[RW]
message[R]
project_id[RW]
Public Class Methods
new(access_token: "", project_id: "")
click to toggle source
@param :access_token [String] optional @param :project_id [String] optional
# File lib/firepush/client.rb, line 21 def initialize(access_token: "", project_id: "") self.access_token = access_token self.project_id = project_id end
Public Instance Methods
message=(message)
click to toggle source
@param message [Hash]
# File lib/firepush/client.rb, line 27 def message=(message) @message = Message.new(message) end
push(message = nil)
click to toggle source
@param message [Hash] optional
TODO: Return useful response @return [Net::HTTPResponse]
@raise [Firepush::Client::InvalidAttributes]
# File lib/firepush/client.rb, line 37 def push(message = nil) self.message = message unless message.nil? raise InvalidAttributes unless valid? http.post(path, self.message.to_json, headers) end
valid?()
click to toggle source
@return [Boolean]
# File lib/firepush/client.rb, line 46 def valid? valid_str?(access_token) && valid_str?(project_id) && !message.nil? && message.valid? end
Private Instance Methods
headers()
click to toggle source
@private @return [Hash]
# File lib/firepush/client.rb, line 55 def headers { "Content-Type" => "application/json", "Authorization" => "Bearer #{access_token}", } end
http()
click to toggle source
@private @return [Net::HTTP]
# File lib/firepush/client.rb, line 64 def http @http ||= begin h = ::Net::HTTP.new(uri.host, uri.port) h.use_ssl = true h end end
path()
click to toggle source
@private @return [String]
# File lib/firepush/client.rb, line 75 def path "#{BASE_PATH}/#{project_id}/messages:send" end
uri()
click to toggle source
@private @return [URI::HTTPS]
# File lib/firepush/client.rb, line 81 def uri @uri ||= ::URI.parse(BASE_URI) end