Class: Baidu::Push::Client
- Inherits:
-
Object
- Object
- Baidu::Push::Client
- Defined in:
- lib/baidu/push/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/baidu/push/client.rb', line 5 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/baidu/push/client.rb', line 5 def logger @logger end |
Class Method Details
.setup(options = {api_key: nil, secret_key: nil}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/baidu/push/client.rb', line 7 def self.setup( = {api_key: nil, secret_key: nil}) raise 'api_key can not be nil.' unless [:api_key] raise 'secret_key can not be nil.' unless [:secret_key] md5 = Digest::MD5.hexdigest([[:api_key], [:secret_key]].join) instance_variable_get("@client_#{md5}") || instance_variable_set("@client_#{md5}", begin config = Configuration.new config.api_key = [:api_key] config.secret_key = [:secret_key] client = self.new client.config = config client.logger = [:logger] client end) end |
Instance Method Details
#push_msg(message) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/baidu/push/client.rb', line 27 def push_msg() raise 'invalid baidu push message' unless .is_a?(Baidu::Push::Message) attr = .non_nil_attributes attr.merge!(apikey: config.api_key, method: __method__) rest_api.connection.post do |req| req.url "#{rest_api.base_path}/channel" req.params = attr.merge(sign: get_sign('POST', "#{rest_api.default_domain}#{rest_api.base_path}/channel", attr)) end end |