Module: Pushkin

Extended by:
Pushkin
Included in:
Pushkin
Defined in:
lib/pushkin.rb,
lib/pushkin/engine.rb,
lib/pushkin/version.rb,
lib/pushkin/subscription.rb,
lib/pushkin/configuration.rb,
lib/pushkin/action_view/helpers.rb,
lib/pushkin/faye/authentication.rb,
lib/generators/pushkin/install_generator.rb

Defined Under Namespace

Modules: ActionView, Faye, Generators Classes: Configuration, Engine, Subscription

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#configObject



31
32
33
# File 'lib/pushkin.rb', line 31

def config
  @configuration ||= Configuration.new
end

#configure(opts = {}, &block) ⇒ Object



35
36
37
38
39
40
# File 'lib/pushkin.rb', line 35

def configure(opts = {}, &block)
  opts.each do |attribute, setting|
    Configuration.config.send("#{attribute}=", setting)
  end
  Configuration.configure &block if block_given?
end

#connectionObject



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

def connection
  # conn.post do |req|
  #   req.url '/nigiri'
  #   req.headers['Content-Type'] = 'application/json'
  #   req.body = '{ "name": "Unagi" }'
  # end
  @connection ||= begin
    Faraday.new host do |conn|
      conn.request :json

      conn.response :logger # log the request to STDOUT
      conn.response :json,  :content_type => /\bjson$/

      conn.adapter Faraday.default_adapter
    end
  end
end

#publish_message(message) ⇒ Object



44
45
46
47
# File 'lib/pushkin.rb', line 44

def publish_message(message)
  response = connection.post(endpoint, message)
  response.body
end

#reset!Object



27
28
29
# File 'lib/pushkin.rb', line 27

def reset!
  @configuration = nil
end

#server(options = {}) ⇒ Object

Returns the Faye Rack application. Any options given are passed to the Faye::RackAdapter.



57
58
59
60
# File 'lib/pushkin.rb', line 57

def server(options = {})
  options = {:mount => endpoint, :timeout => 45, :extensions => []}.merge(options)
  ::Faye::RackAdapter.new(options)
end

#subscription(options = {}) ⇒ Object

Returns a subscription hash to pass to the Pushkin.sign call in JavaScript. Any options passed are merged to the hash.



51
52
53
# File 'lib/pushkin.rb', line 51

def subscription(options = {})
  Subscription.new(options).to_hash
end