Class: EpnsClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/epns_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt, blk) ⇒ Client

Returns a new instance of Client.



75
76
77
# File 'lib/epns_client.rb', line 75

def initialize(opt, blk)
  connect("#{opt['data']['url']}:#{opt['data']['port']}", opt['data']['req_body'], blk)
end

Instance Method Details

#connect(url, req_body, blk) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/epns_client.rb', line 79

def connect(url, req_body, blk)
  ws = WebSocket::Client::Simple.connect url

  ws.on :message do |msg|
    blk.call(msg.data)
  end

  ws.on :open do
    ws.send req_body.to_json
  end

  ws.on :close do |e|
    puts e
  end

  ws.on :error do |e|
    puts e
  end
end