Class: EpnsClient::Connection
- Inherits:
-
Object
- Object
- EpnsClient::Connection
- Defined in:
- lib/epns_client.rb
Class Method Summary collapse
- .builder(api_key, reg_id) ⇒ Object
- .error?(json) ⇒ Boolean
- .post(params, url) ⇒ Object
- .register(api_key) ⇒ Object
- .send_notification(ids, api_key, options) ⇒ Object
Class Method Details
.builder(api_key, reg_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/epns_client.rb', line 27 def self.builder(api_key, reg_id) params = Hash.new params.store('api_key', api_key) params.store('registration_id', reg_id) json = post(params, File.join($host, 'weset/websocket/connect')) error?(json) return json end |
.error?(json) ⇒ Boolean
54 55 56 57 |
# File 'lib/epns_client.rb', line 54 def self.error?(json) return if json['error'].nil? raise EpnsClientError, "#{json['error']['message']}:#{json['error']['code']}" end |
.post(params, url) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/epns_client.rb', line 59 def self.post(params, url) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = $ssl request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data(params) response = nil http.start do |h| response = h.request(request).body end json = JSON.parse(response) return json end |
.register(api_key) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/epns_client.rb', line 36 def self.register(api_key) params = Hash.new params.store('api_key', api_key) json = post(params, File.join($host, 'weset/websocket/regist')) error?(json) return json['data']['registration_id'] end |
.send_notification(ids, api_key, options) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/epns_client.rb', line 44 def self.send_notification(ids, api_key, ) params = Hash.new params.store('api_key', api_key) params.store('registration_ids', ids) params.store('options', .to_json) json = post(params, File.join($host, 'weset/websocket/send_notification')) error?(json) return json end |