Class: Instapush::Application
- Inherits:
-
Object
- Object
- Instapush::Application
- Defined in:
- lib/instapush/application.rb
Instance Method Summary collapse
-
#initialize(app_id, app_secret, opts = {}) ⇒ Application
constructor
A new instance of Application.
- #push(event) ⇒ Object
Constructor Details
#initialize(app_id, app_secret, opts = {}) ⇒ Application
Returns a new instance of Application.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/instapush/application.rb', line 7 def initialize(app_id, app_secret, opts = {}) = { :use_ssl => false } @options = .merge(opts) @app_id = app_id @app_secret = app_secret scheme = @options[:use_ssl] ? 'https' : 'http' @api_url = "#{scheme}://api.instapush.im/post" end |
Instance Method Details
#push(event) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/instapush/application.rb', line 20 def push(event) raise(ArgumentError, "event must be an Instapush::Event") unless event.instance_of? Event data = { :event => event.name, :trackers => event.tracker } uri = URI.parse(@api_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = @options[:use_ssl]; http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.body= data.to_json request.content_type = 'application/json' request['X-INSTAPUSH-APPID'] = @app_id request['X-INSTAPUSH-APPSECRET'] = @app_secret http.request(request) end |