module AFMotion::Rocket

Constants

VERSION

Public Class Methods

included(klass) click to toggle source
# File lib/afmotion-rocket/client_patch.rb, line 3
def self.included(klass)
  klass.send(:alias_method,"headers_without_wrapper", "headers")
  klass.send(:alias_method,"headers", "headers_with_wrapper")
end

Public Instance Methods

headers_with_wrapper() click to toggle source
# File lib/afmotion-rocket/client_patch.rb, line 46
def headers_with_wrapper
  @headers_wrapper ||= HeaderWrapper.new(self)
end
rocket_client() click to toggle source
# File lib/afmotion-rocket/client_patch.rb, line 8
def rocket_client
  @rocket_client ||= begin
    client = AFRocketClient.alloc.init
    self.all_headers.each do |header, value|
      client.requestSerializer.headers[header] = value
    end
    client
  end
end
subscribe(url, &callback) click to toggle source
# File lib/afmotion-rocket/client_patch.rb, line 18
def subscribe(url, &callback)
  url_string = NSURL.URLWithString(url, relativeToURL: self.baseURL).absoluteString
  error_ptr = Pointer.new(:object)
  event_source = rocket_client.SUBSCRIBE(url_string, usingBlock: ->(operations, error) {
    callback.call operations.map(&:to_h)
  }, error: error_ptr)

  # .retain because event_source will otherwise be autoreleased.
  # see also: https://github.com/AFNetworking/AFRocketClient/issues/3 .
  [error_ptr[0], event_source.retain]
end