diff --git a/Gemfile b/Gemfile index a7f86bd..eae9336 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in message_bus-client.gemspec +# Specify your gem's dependencies in message_bus_client.gemspec gemspec diff --git a/README.md b/README.md index 2ce2357..9aeff9f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# MessageBus::Client -[![Build Status](https://travis-ci.org/lowjoel/message_bus-client.svg?branch=master)](https://travis-ci.org/lowjoel/message_bus-client)[![Coverage Status](https://coveralls.io/repos/github/lowjoel/message_bus-client/badge.svg?branch=master)](https://coveralls.io/github/lowjoel/message_bus-client?branch=master)[![Code Climate](https://codeclimate.com/github/lowjoel/message_bus-client/badges/gpa.svg)](https://codeclimate.com/github/lowjoel/message_bus-client)[![security](https://hakiri.io/github/lowjoel/message_bus-client/master.svg)](https://hakiri.io/github/lowjoel/message_bus-client/master)[![Inline docs](http://inch-ci.org/github/lowjoel/message_bus-client.svg?branch=master)](http://inch-ci.org/github/lowjoel/message_bus-client) +# MessageBusClient +[![Build Status](https://travis-ci.org/lowjoel/message_bus_client.svg?branch=master)](https://travis-ci.org/lowjoel/message_bus_client)[![Coverage Status](https://coveralls.io/repos/github/lowjoel/message_bus_client/badge.svg?branch=master)](https://coveralls.io/github/lowjoel/message_bus_client?branch=master)[![Code Climate](https://codeclimate.com/github/lowjoel/message_bus_client/badges/gpa.svg)](https://codeclimate.com/github/lowjoel/message_bus_client)[![security](https://hakiri.io/github/lowjoel/message_bus_client/master.svg)](https://hakiri.io/github/lowjoel/message_bus_client/master)[![Inline docs](http://inch-ci.org/github/lowjoel/message_bus_client.svg?branch=master)](http://inch-ci.org/github/lowjoel/message_bus_client) This is a Ruby implementation of the client for [message_bus](https://github.com/samsaffron/message_bus). @@ -9,7 +9,7 @@ This is a Ruby implementation of the client for Add this line to your application's Gemfile: ```ruby -gem 'message_bus-client' +gem 'message_bus_client' ``` And then execute: @@ -18,14 +18,14 @@ And then execute: Or install it yourself as: - $ gem install message_bus-client + $ gem install message_bus_client ## Usage The API is mostly equivalent with the JavaScript client: ```ruby -client = MessageBus::Client.new('http://chat.samsaffron.com/') +client = MessageBusClient.new('http://chat.samsaffron.com/') client.subscribe('/message') do |payload| # Do stuff end @@ -39,8 +39,8 @@ client.stop Both Long Polling and normal polling are supported: ```ruby -MessageBus::Client.long_polling = true # false to disable -MessageBus::Client.poll_interval = 15 # seconds +MessageBusClient.long_polling = true # false to disable +MessageBusClient.poll_interval = 15 # seconds ``` ## Development @@ -54,5 +54,5 @@ If you are running Windows, Ruby is not able to kill the server process. Run it ## Contributing Bug reports and pull requests are welcome on GitHub at -https://github.com/lowjoel/message_bus-client. +https://github.com/lowjoel/message_bus_client. diff --git a/lib/message_bus/client.rb b/lib/message_bus/client.rb deleted file mode 100644 index 41adeeb..0000000 --- a/lib/message_bus/client.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'excon' -require 'json' -require 'securerandom' - -require 'message_bus/client/version' -require 'message_bus/client/configuration' -require 'message_bus/client/connection' -require 'message_bus/client/message_handler' - -class MessageBus::Client - include MessageBus::Client::Configuration - include MessageBus::Client::Connection - include MessageBus::Client::MessageHandler - - def initialize(base_url) - super - @client_id = SecureRandom.uuid - end -end diff --git a/lib/message_bus/client/version.rb b/lib/message_bus/client/version.rb deleted file mode 100644 index 10281ec..0000000 --- a/lib/message_bus/client/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module MessageBus - class Client - VERSION = '0.1.0' - end -end diff --git a/lib/message_bus_client.rb b/lib/message_bus_client.rb new file mode 100644 index 0000000..fe82137 --- /dev/null +++ b/lib/message_bus_client.rb @@ -0,0 +1,19 @@ +require 'excon' +require 'json' +require 'securerandom' + +require 'message_bus_client/version' +require 'message_bus_client/configuration' +require 'message_bus_client/connection' +require 'message_bus_client/message_handler' + +class MessageBusClient + include MessageBusClient::Configuration + include MessageBusClient::Connection + include MessageBusClient::MessageHandler + + def initialize(base_url) + super + @client_id = SecureRandom.uuid + end +end diff --git a/lib/message_bus/client/configuration.rb b/lib/message_bus_client/configuration.rb similarity index 86% rename from lib/message_bus/client/configuration.rb rename to lib/message_bus_client/configuration.rb index eea479f..ba6235d 100644 --- a/lib/message_bus/client/configuration.rb +++ b/lib/message_bus_client/configuration.rb @@ -1,4 +1,4 @@ -module MessageBus::Client::Configuration +module MessageBusClient::Configuration def self.included(module_) module_.extend(ClassMethods) end diff --git a/lib/message_bus/client/connection.rb b/lib/message_bus_client/connection.rb similarity index 98% rename from lib/message_bus/client/connection.rb rename to lib/message_bus_client/connection.rb index 59c506b..5b1d9b9 100644 --- a/lib/message_bus/client/connection.rb +++ b/lib/message_bus_client/connection.rb @@ -1,4 +1,4 @@ -module MessageBus::Client::Connection +module MessageBusClient::Connection # The connection is in the initialised state. INITIALISED = 0 diff --git a/lib/message_bus/client/message_handler.rb b/lib/message_bus_client/message_handler.rb similarity index 98% rename from lib/message_bus/client/message_handler.rb rename to lib/message_bus_client/message_handler.rb index 71bb0bc..5abce48 100644 --- a/lib/message_bus/client/message_handler.rb +++ b/lib/message_bus_client/message_handler.rb @@ -1,4 +1,4 @@ -module MessageBus::Client::MessageHandler +module MessageBusClient::MessageHandler SubscribedChannel = Struct.new(:callbacks, :last_id) do def initialize(last_id = -1) self.callbacks = [] diff --git a/lib/message_bus_client/version.rb b/lib/message_bus_client/version.rb new file mode 100644 index 0000000..51e765c --- /dev/null +++ b/lib/message_bus_client/version.rb @@ -0,0 +1,3 @@ +class MessageBusClient + VERSION = '0.2.0' +end diff --git a/message_bus-client.gemspec b/message_bus_client.gemspec similarity index 86% rename from message_bus-client.gemspec rename to message_bus_client.gemspec index f6e22ce..f84b3e3 100644 --- a/message_bus-client.gemspec +++ b/message_bus_client.gemspec @@ -1,17 +1,17 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'message_bus/client/version' +require 'message_bus_client/version' Gem::Specification.new do |spec| - spec.name = 'message_bus-client' - spec.version = MessageBus::Client::VERSION + spec.name = 'message_bus_client' + spec.version = MessageBusClient::VERSION spec.authors = ['Joel Low'] spec.email = ['joel@joelsplace.sg'] spec.summary = 'Ruby client for Message Bus' spec.description = 'Implements a client for Message Bus, with communication over HTTP' - spec.homepage = 'https://github.com/lowjoel/message_bus-client' + spec.homepage = 'https://github.com/lowjoel/message_bus_client' spec.files = `git ls-files -z`.split("\x0"). reject { |f| f.match(/^(test|spec|features)\//) } diff --git a/spec/chat_server_helper.rb b/spec/chat_server_helper.rb index da76645..702844b 100644 --- a/spec/chat_server_helper.rb +++ b/spec/chat_server_helper.rb @@ -2,7 +2,7 @@ chat_example_path = File.join(message_bus_path, 'examples/chat') # Override the load path so that the message_bus library loads before us. The middleware uses a -# MessageBus::Client class as well, with a different use case from ours. +# MessageBusClient class as well, with a different use case from ours. $LOAD_PATH.unshift File.expand_path('lib', message_bus_path) # Use the in-memory backend since this is for testing. diff --git a/spec/message_bus/client_spec.rb b/spec/message_bus_client_spec.rb similarity index 82% rename from spec/message_bus/client_spec.rb rename to spec/message_bus_client_spec.rb index 26511de..55e6cc3 100644 --- a/spec/message_bus/client_spec.rb +++ b/spec/message_bus_client_spec.rb @@ -1,17 +1,17 @@ -RSpec.describe MessageBus::Client do +RSpec.describe MessageBusClient do self::SERVER_BASE = 'http://127.0.0.1:9292'.freeze it 'has a version number' do - expect(MessageBus::Client::VERSION).not_to be nil + expect(MessageBusClient::VERSION).not_to be nil end - def write_message(message, user = 'message_bus-client') + def write_message(message, user = 'message_bus_client') Excon.post(URI.join(self.class::SERVER_BASE, '/message').to_s, body: URI.encode_www_form(name: user, data: message), headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }) end - subject { MessageBus::Client.new(self.class::SERVER_BASE) } + subject { MessageBusClient.new(self.class::SERVER_BASE) } context 'when using long polling' do it 'connects to the server' do @@ -56,14 +56,14 @@ def write_message(message, user = 'message_bus-client') context 'when using polling' do around(:each) do |example| begin - old_long_polling = MessageBus::Client.long_polling - old_poll_interval = MessageBus::Client.poll_interval - MessageBus::Client.poll_interval = 1 - MessageBus::Client.long_polling = false + old_long_polling = MessageBusClient.long_polling + old_poll_interval = MessageBusClient.poll_interval + MessageBusClient.poll_interval = 1 + MessageBusClient.long_polling = false example.call ensure - MessageBus::Client.poll_interval = old_poll_interval - MessageBus::Client.long_polling = old_long_polling + MessageBusClient.poll_interval = old_poll_interval + MessageBusClient.long_polling = old_long_polling end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 58b8468..94d456d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'coverage_helper' -require 'message_bus/client' +require 'message_bus_client' require 'chat_server_helper' # This file was generated by the `rspec --init` command. Conventionally, all