Sha256: 962a96cc7a3df4dda651b2641f893f19e78f877e5622608c6ef04f55952b0f33
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
require 'http' module Pwush class Client def initialize(options) @config = Config.new(options) end def create_message(*messages) post(:createMessage, notifications: messages.flatten) end alias push create_message def message_details(message) post(:getMessageDetails, message: message) end # enterprise api def message_stats(message) post(:getMsgStats, message: message) end # enterprise api def results(request_id) post(:getResults, request_id: request_id) end # enterprise api def applications post(:getApplications) end # enterprise api def preset(preset_code) post(:getPreset, preset_code: preset_code) end private def get(action, payload = nil) perform_request(:get, action, payload) end def post(action, payload = nil) perform_request(:post, action, payload) end def perform_request(verb, action, payload) Response.wrap { raw_request(verb, action, payload) } end def raw_request(verb, action, payload) request = build_request(payload) url = url(action) @config.logger.info( "Pushwoosh #{verb.upcase} #{url} BODY #{request.body.to_json}" ) Http.timeout(@config.timeout).request(verb, url, json: request.body) end def build_request(payload = nil) Request.new(auth: @config.auth, app: @config.app, payload: payload) end def url(action) [@config.url, action].join('/') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pwush-0.1.5 | lib/pwush/client.rb |
pwush-0.1.4 | lib/pwush/client.rb |