Sha256: 97b17238c5f266871764b27a43dc0e4bb0ae3587fe280dbbf5812876446f2b9f
Contents?: true
Size: 1.66 KB
Versions: 2
Compression:
Stored size: 1.66 KB
Contents
require 'uri' require 'faraday/errors' module FiveMobilePush class Client DEFAULT_ENDPOINT = 'https://push.fivemobile.com/rest' attr_accessor :application_uid, :api_token, :adapter def initialize(options={}) self.application_uid = options[:application_uid] || FiveMobilePush.application_uid self.api_token = options[:api_token] || FiveMobilePush.api_token self.adapter = options[:adapter] || FiveMobilePush.adapter end def connection @connection ||= Faraday.new(:url => DEFAULT_ENDPOINT, :user_agent => 'FiveMobilePush Ruby gem') do |builder| builder.adapter self.adapter builder.use Faraday::Response::Errors end end def get(path, options={}) perform_request(:get, path, options) end def post(path, options={}) perform_request(:post, path, options) end def device(device_uid) FiveMobilePush::Device.new(self, device_uid) end def notifier FiveMobilePush::Notifier.new(self) end def tag(device_uid) FiveMobilePush::Tag.new(self, device_uid) end # @return [URI] a URI object for the {DEFAULT_ENDPOINT} def self.default_endpoint URI.parse(DEFAULT_ENDPOINT) end private def perform_request(method, path, options={}) options.merge!({:api_token => self.api_token, :application_id => self.application_uid }) connection.send(method) do |request| case method when :get, :delete request.url(path, options) when :post, :put request.path = path request.body = options end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
five_mobile_push-0.4.5 | lib/five_mobile_push/client.rb |
five_mobile_push-0.4.4-x86_64-darwin-10 | lib/five_mobile_push/client.rb |