lib/pwush/client.rb in pwush-0.0.0 vs lib/pwush/client.rb in pwush-0.1.0
- old
+ new
@@ -1,13 +1,15 @@
+require 'http'
+
module Pwush
class Client
def initialize(options)
@config = Config.new(options)
end
- def create_message(*notifications)
- post(:createMessage, notifications: notifications)
+ def create_message(*messages)
+ post(:createMessage, notifications: messages)
end
alias push create_message
def message_details(message)
post(:getMessageDetails, message: message)
@@ -31,10 +33,14 @@
# enterprise api
def preset(preset_code)
post(:getPreset, preset_code: preset_code)
end
+ def fail
+ post(:someshit, shit: 'crap')
+ end
+
private
def get(action, payload = nil)
perform_request(:get, action, payload)
end
@@ -42,21 +48,18 @@
def post(action, payload = nil)
perform_request(:post, action, payload)
end
def perform_request(verb, action, payload)
- response = Http.request(
- verb, url(action), json: build_request(payload).body
- )
- parse_response(response)
+ Response.wrap { raw_request(verb, action, payload) }
end
- def build_request(payload = nil)
- Request.new(auth: @config.auth, app: @config.app, payload: payload)
+ def raw_request(verb, action, payload)
+ Http.request(verb, url(action), json: build_request(payload).body)
end
- def parse_response(response)
- Oj.load(response.body)
+ def build_request(payload = nil)
+ Request.new(auth: @config.auth, app: @config.app, payload: payload)
end
def url(action)
[@config.url, action].join('/')
end