Module: Andpush

Defined in:
lib/andpush.rb,
lib/andpush/client.rb,
lib/andpush/version.rb,
lib/andpush/exceptions.rb,
lib/andpush/json_handler.rb

Defined Under Namespace

Classes: APIError, BadGateway, BadRequest, Client, ClientError, Conflict, ExpectationFailed, FailedDependency, Forbidden, GatewayTimeout, Gone, HTTPVersionNotSupported, HttpError, ImaTeapot, InsufficientStorage, InternalServerError, JsonResponse, LengthRequired, Locked, LoopDetected, MethodNotAllowed, MisdirectedRequest, NetworkAuthenticationRequired, NetworkError, NotAcceptable, NotExtended, NotFound, NotImplemented, PayloadTooLarge, PaymentRequired, PreconditionFailed, PreconditionRequired, ProxyAuthenticationRequired, RangeNotSatisfiable, RequestHeaderFieldsTooLarge, RequestTimeout, ServerError, ServiceUnavailable, TooManyRequests, URITooLong, Unauthorized, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType, UpgradeRequired, VariantAlsoNegotiates

Constant Summary collapse

DOMAIN =
'https://fcm.googleapis.com'.freeze
VERSION =
'0.2.1'.freeze
STATUS_TO_EXCEPTION_MAPPING =
{
  '400' => BadRequest,
  '401' => Unauthorized,
  '402' => PaymentRequired,
  '403' => Forbidden,
  '404' => NotFound,
  '405' => MethodNotAllowed,
  '406' => NotAcceptable,
  '407' => ProxyAuthenticationRequired,
  '408' => RequestTimeout,
  '409' => Conflict,
  '410' => Gone,
  '411' => LengthRequired,
  '412' => PreconditionFailed,
  '413' => PayloadTooLarge,
  '414' => URITooLong,
  '415' => UnsupportedMediaType,
  '416' => RangeNotSatisfiable,
  '417' => ExpectationFailed,
  '418' => ImaTeapot,
  '421' => MisdirectedRequest,
  '422' => UnprocessableEntity,
  '423' => Locked,
  '424' => FailedDependency,
  '426' => UpgradeRequired,
  '428' => PreconditionRequired,
  '429' => TooManyRequests,
  '431' => RequestHeaderFieldsTooLarge,
  '451' => UnavailableForLegalReasons,
  '500' => InternalServerError,
  '501' => NotImplemented,
  '502' => BadGateway,
  '503' => ServiceUnavailable,
  '504' => GatewayTimeout,
  '505' => HTTPVersionNotSupported,
  '506' => VariantAlsoNegotiates,
  '507' => InsufficientStorage,
  '508' => LoopDetected,
  '510' => NotExtended,
  '511' => NetworkAuthenticationRequired
}.freeze

Class Method Summary collapse

Class Method Details

.build(server_key, domain: nil, name: nil, proxy: nil, pool_size: Net::HTTP::Persistent::DEFAULT_POOL_SIZE) ⇒ Object Also known as: new



10
11
12
13
14
# File 'lib/andpush.rb', line 10

def build(server_key, domain: nil, name: nil, proxy: nil, pool_size: Net::HTTP::Persistent::DEFAULT_POOL_SIZE)
  ::Andpush::Client
    .new(domain || DOMAIN, request_handler: ConnectionPool.new(name: name, proxy: proxy, pool_size: pool_size))
    .register_interceptor(Authenticator.new(server_key))
end

.http2(server_key, domain: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/andpush.rb', line 17

def http2(server_key, domain: nil)
  begin
    require 'curb' if !defined?(Curl)
  rescue LoadError => error
    raise LoadError, "Could not load the curb gem. Make sure to install the gem by running:\n\n" \
                     "  $ gem i curb\n\n" \
                     "Or the Gemfile has the following declaration:\n\n" \
                     "  gem 'curb'\n\n" \
                     "  (#{error.class}: #{error.message})"
  end

  ::Andpush::Client
    .new(domain || DOMAIN, request_handler: Http2RequestHandler.new)
    .register_interceptor(Authenticator.new(server_key))
end