Class: Andpush::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/andpush/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, proxy_addr: nil, proxy_port: nil, proxy_user: nil, proxy_password: nil, request_handler: RequestHandler.new, **options) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/andpush/client.rb', line 10

def initialize(domain, proxy_addr: nil, proxy_port: nil, proxy_user: nil, proxy_password: nil, request_handler: RequestHandler.new, **options)
  @domain = domain
  @proxy_addr = proxy_addr
  @proxy_port = proxy_port
  @proxy_user = proxy_user
  @proxy_password = proxy_password
  @interceptors = []
  @observers = []
  @request_handler = request_handler
  @options = DEFAULT_OPTIONS.merge(options)

  register_interceptor(JsonSerializer.new)
  register_observer(ResponseHandler.new)
  register_observer(JsonDeserializer.new)
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



8
9
10
# File 'lib/andpush/client.rb', line 8

def domain
  @domain
end

#proxy_addrObject (readonly)

Returns the value of attribute proxy_addr.



8
9
10
# File 'lib/andpush/client.rb', line 8

def proxy_addr
  @proxy_addr
end

#proxy_passwordObject (readonly)

Returns the value of attribute proxy_password.



8
9
10
# File 'lib/andpush/client.rb', line 8

def proxy_password
  @proxy_password
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



8
9
10
# File 'lib/andpush/client.rb', line 8

def proxy_port
  @proxy_port
end

#proxy_userObject (readonly)

Returns the value of attribute proxy_user.



8
9
10
# File 'lib/andpush/client.rb', line 8

def proxy_user
  @proxy_user
end

#request_handlerObject (readonly)

Returns the value of attribute request_handler.



8
9
10
# File 'lib/andpush/client.rb', line 8

def request_handler
  @request_handler
end

Instance Method Details

#push(body, query: {}, headers: {}, **options) ⇒ Object



36
37
38
# File 'lib/andpush/client.rb', line 36

def push(body, query: {}, headers: {}, **options)
  request(Net::HTTP::Post, uri('/fcm/send', query), body, headers, method: :push, **options)
end

#register_interceptor(interceptor) ⇒ Object



26
27
28
29
# File 'lib/andpush/client.rb', line 26

def register_interceptor(interceptor)
  @interceptors << interceptor
  self
end

#register_observer(observer) ⇒ Object



31
32
33
34
# File 'lib/andpush/client.rb', line 31

def register_observer(observer)
  @observers << observer
  self
end