Skip to content

Commit

Permalink
Update ruby/README.md
Browse files Browse the repository at this point in the history
Updating README
  • Loading branch information
Geremy Cohen committed Sep 13, 2012
1 parent d9d2db4 commit 2013a6f
Showing 1 changed file with 52 additions and 59 deletions.
111 changes: 52 additions & 59 deletions ruby/README.md
Expand Up @@ -4,7 +4,7 @@ Pubnub - http://github/pubnub/pubnub-api
##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API. ##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
##### http://www.pubnub.com/account ##### http://www.pubnub.com/account


## PubNub 3.1 Real-time Cloud Push API - RUBY ## PubNub 3.3 Real-time Cloud Push API - RUBY


www.pubnub.com - PubNub Real-time Push Service in the Cloud. www.pubnub.com - PubNub Real-time Push Service in the Cloud.
http://www.pubnub.com/blog/ruby-push-api http://www.pubnub.com/blog/ruby-push-api
Expand All @@ -13,91 +13,84 @@ PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
This is a cloud-based service for broadcasting Real-time messages This is a cloud-based service for broadcasting Real-time messages
to thousands of web and mobile clients simultaneously. to thousands of web and mobile clients simultaneously.


### Ruby Push API ## Pubnub 3.3 for Ruby is a complete rewrite, and is NOT compatible with earlier versions of Pubnub Ruby Client.
### Usage Examples
Examine the tests in spec/lib/* for many different scenarios! Specifically, *_integration. But here is a small sample:


### Ruby: (Init) ### Instantiate a new PN Object


```ruby ```ruby
pubnub = Pubnub.new( pn = Pubnub.new(:publish_key => @publish_key, # publish_key only required if publishing.
"demo", ## PUBLISH_KEY :subscribe_key => @subscribe_key, # required
"demo", ## SUBSCRIBE_KEY :secret_key => @secret_key, # optional, if used, message signing is enabled
"demo", ## SECRET_KEY :cipher_key => @cipher_key, # optional, if used, encryption is enabled
"", ## CIPHER_KEY (Cipher key is Optional) :ssl => @ssl_enabled) # true or default is false
false ## SSL_ON?
)
``` ```


### Ruby: (Publish) ### Publish

For message, you can just pass it a string, a hash, an array, an object -- it will be serialized as a JSON object,
##### Send Message in String Format and urlencoded automatically for you.


```ruby ```ruby
pubnub.publish({
'channel' => 'hello_world', @my_callback = lambda { |message| puts(message) }
'message' => 'hey what is up?',
'callback' => lambda do |message| pn.publish(:channel => :hello_world,
puts(message) :message => "hi",
end :callback => @my_callback)
})
``` ```


##### Send Message in Array Format ### Subscribe


```ruby ```ruby
pubnub.publish({ pn.subscribe(:channel => :hello_world,
'channel' => 'hello_world', :callback => @my_callback)
'message' => { ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] },
'callback' => lambda do |message|
puts(message)
end
})
``` ```


##### Send Message in Dictionary Format ### History (deprecated, use new detailed_history)


```ruby ```ruby
pubnub.publish({ pn.history(:cipher_key => "enigma",
'channel' => 'hello_world', :channel => @no_history_channel,
'message' => { 'text' => 'some text data' }, :limit => 10,
'callback' => lambda do |message| :callback => @my_callback)
puts(message)
end
})
``` ```


### Ruby: (Subscribe) ### Detailed Message History

##### Listen for Messages


Archive messages of on a given channel. Optional start, end, and reverse option examples can be found in the tests.
```ruby ```ruby
pubnub.subscribe({ pn.detailed_history(:channel => channel,
'channel' => 'hello_world', :count => 10,
'callback' => lambda do |message| :callback => @my_callback)
puts(message) ## get and print message
return true ## keep listening?
end
})
``` ```


### Ruby: (History) ### Presence

Realtime see who channel events, such as joins, leaves, and occupancy.
```ruby
pn.presence(:channel => :hello_world,
:callback => @my_callback)
```


##### Load Previously Published Messages ### Here_now


See who is online in a channel at this very moment.
```ruby ```ruby
pubnub.history({ pn.here_now(:channel => channel,
'channel' => 'hello_world', :callback => @my_callback)
'limit' => 10,
'callback' => lambda do |message|
puts(message)
end
})
``` ```


### Ruby: (UUID) ### UUID

Session-UUID is automatic, so you will probably not end up ever using this. But if you need a UUID...
```ruby
Pubnub.new(:subscribe_key => :demo).uuid
```


##### Generate UUID ### Time


Get the current timetoken.
```ruby ```ruby
uuid = pubnub.UUID() pn.time("callback" => @my_callback)
puts(uuid)
``` ```

0 comments on commit 2013a6f

Please sign in to comment.