lib/ably/rest/client.rb in ably-0.7.6 vs lib/ably/rest/client.rb in ably-0.8.0

- old
+ new

@@ -68,40 +68,38 @@ # Creates a {Ably::Rest::Client Rest Client} and configures the {Ably::Auth} object for the connection. # # @param [Hash,String] options an options Hash used to configure the client and the authentication, or String with an API key or Token ID # @option options (see Ably::Auth#authorise) # @option options [Boolean] :tls TLS is used by default, providing a value of false disables TLS. Please note Basic Auth is disallowed without TLS as secrets cannot be transmitted over unsecured connections. - # @option options [String] :key API key comprising the key ID and key secret in a single string - # @option options [Boolean] :use_token_auth Will force Basic Auth if set to false, and TOken auth if set to true + # @option options [String] :key API key comprising the key name and key secret in a single string + # @option options [String] :token Token string or {Models::TokenDetails} used to authenticate requests + # @option options [String] :token_details {Models::TokenDetails} used to authenticate requests + # @option options [Boolean] :use_token_auth Will force Basic Auth if set to false, and Token auth if set to true # @option options [String] :environment Specify 'sandbox' when testing the client library against an alternate Ably environment # @option options [Symbol] :protocol Protocol used to communicate with Ably, :json and :msgpack currently supported. Defaults to :msgpack # @option options [Boolean] :use_binary_protocol Protocol used to communicate with Ably, defaults to true and uses MessagePack protocol. This option will overide :protocol option # @option options [Logger::Severity,Symbol] :log_level Log level for the standard Logger that outputs to STDOUT. Defaults to Logger::ERROR, can be set to :fatal (Logger::FATAL), :error (Logger::ERROR), :warn (Logger::WARN), :info (Logger::INFO), :debug (Logger::DEBUG) or :none # @option options [Logger] :logger A custom logger can be used however it must adhere to the Ruby Logger interface, see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html # - # @yield (see Ably::Auth#authorise) - # @yieldparam (see Ably::Auth#authorise) - # @yieldreturn (see Ably::Auth#authorise) - # # @return [Ably::Rest::Client] # # @example # # create a new client authenticating with basic auth # client = Ably::Rest::Client.new('key.id:secret') # # # create a new client and configure a client ID used for presence # client = Ably::Rest::Client.new(key: 'key.id:secret', client_id: 'john') # - def initialize(options, &token_request_block) + def initialize(options) raise ArgumentError, 'Options Hash is expected' if options.nil? options = options.clone if options.kind_of?(String) options = if options.match(/^[\w]{2,}\.[\w]{2,}:[\w]{2,}$/) { key: options } else - { token_id: options } + { token: options } end end @tls = options.delete(:tls) == false ? false : true @environment = options.delete(:environment) # nil is production @@ -125,11 +123,11 @@ end end raise ArgumentError, 'Protocol is invalid. Must be either :msgpack or :json' unless [:msgpack, :json].include?(@protocol) @options = options.freeze - @auth = Auth.new(self, options, &token_request_block) + @auth = Auth.new(self, options) @channels = Ably::Rest::Channels.new(self) @encoders = [] initialize_default_encoders end @@ -144,21 +142,22 @@ end # Retrieve the Stats for the application # # @param [Hash] options the options for the stats request - # @option options [Integer,Time] :start Time or millisecond since epoch - # @option options [Integer,Time] :end Time or millisecond since epoch - # @option options [Symbol] :direction `:forwards` or `:backwards` - # @option options [Integer] :limit Maximum number of stats to retrieve up to 10,000 - # @option options [Symbol] :by `:minute`, `:hour`, `:day` or `:month`. Defaults to `:minute` + # @option options [Integer,Time] :start Ensure earliest time or millisecond since epoch for any stats retrieved is +:start+ + # @option options [Integer,Time] :end Ensure latest time or millisecond since epoch for any stats retrieved is +:end+ + # @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+ + # @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100 + # @option options [Symbol] :unit `:minute`, `:hour`, `:day` or `:month`. Defaults to `:minute` # # @return [Ably::Models::PaginatedResource<Ably::Models::Stats>] An Array of Stats # def stats(options = {}) options = { - :direction => :forwards, - :by => :minute + :direction => :backwards, + :unit => :minute, + :limit => 100 }.merge(options) [:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) } paginated_options = {