Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ gem install 'analytics-ruby'

Create an instance of the Analytics object:
```ruby
analytics = Segment::Analytics.new(write_key: 'YOUR_WRITE_KEY')
analytics = SegmentIO::Analytics.new(write_key: 'YOUR_WRITE_KEY')
```

Identify the user for the people section, see more [here](https://segment.com/docs/libraries/ruby/#identify).
Expand Down Expand Up @@ -92,14 +92,14 @@ Documentation is available at [segment.com/docs/sources/server/ruby](https://seg

### Test Queue

You can use the `test: true` option to Segment::Analytics.new to cause all requests to be saved to a test queue until manually reset. All events will process as specified by the configuration, and they will also be stored in a separate queue for inspection during testing.
You can use the `test: true` option to SegmentIO::Analytics.new to cause all requests to be saved to a test queue until manually reset. All events will process as specified by the configuration, and they will also be stored in a separate queue for inspection during testing.

A test queue can be used as follows:

```ruby
client = Segment::Analytics.new(test: true)
client = SegmentIO::Analytics.new(test: true)

client.test_queue # => #<Segment::Analytics::TestQueue:0x00007f88d454e9a8 @messages={}>
client.test_queue # => #<SegmentIO::Analytics::TestQueue:0x00007f88d454e9a8 @messages={}>

client.track(user_id: 'foo', event: 'bar')

Expand Down
2 changes: 1 addition & 1 deletion analytics-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require File.expand_path('../lib/segment/analytics/version', __FILE__)

Gem::Specification.new do |spec|
spec.name = 'analytics-ruby'
spec.version = Segment::Analytics::VERSION
spec.version = SegmentIO::Analytics::VERSION
spec.files = Dir.glob("{lib,bin}/**/*")
spec.require_paths = ['lib']
spec.bindir = 'bin'
Expand Down
2 changes: 1 addition & 1 deletion bin/analytics
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ command :send do |c|
c.option '--previousId=<previousId>', String, 'the previous id'

c.action do |args, options|
Analytics = Segment::Analytics.new({
Analytics = SegmentIO::Analytics.new({
write_key: options.writeKey,
on_error: Proc.new { |status, msg| print msg }
})
Expand Down
8 changes: 4 additions & 4 deletions lib/segment/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
require 'segment/analytics/logging'
require 'segment/analytics/test_queue'

module Segment
module SegmentIO
class Analytics
# Initializes a new instance of {Segment::Analytics::Client}, to which all
# Initializes a new instance of {SegmentIO::Analytics::Client}, to which all
# method calls are proxied.
#
# @param options includes options that are passed down to
# {Segment::Analytics::Client#initialize}
# {SegmentIO::Analytics::Client#initialize}
# @option options [Boolean] :stub (false) If true, requests don't hit the
# server and are stubbed to be successful.
def initialize(options = {})
Transport.stub = options[:stub] if options.has_key?(:stub)
@client = Segment::Analytics::Client.new options
@client = SegmentIO::Analytics::Client.new options
end

def method_missing(message, *args, &block)
Expand Down
4 changes: 2 additions & 2 deletions lib/segment/analytics/backoff_policy.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'segment/analytics/defaults'

module Segment
module SegmentIO
class Analytics
class BackoffPolicy
include Segment::Analytics::Defaults::BackoffPolicy
include SegmentIO::Analytics::Defaults::BackoffPolicy

# @param [Hash] opts
# @option opts [Numeric] :min_timeout_ms The minimum backoff timeout
Expand Down
6 changes: 3 additions & 3 deletions lib/segment/analytics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
require 'segment/analytics/utils'
require 'segment/analytics/worker'

module Segment
module SegmentIO
class Analytics
class Client
include Segment::Analytics::Utils
include Segment::Analytics::Logging
include SegmentIO::Analytics::Utils
include SegmentIO::Analytics::Logging

# @param [Hash] opts
# @option opts [String] :write_key Your project's write_key
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/analytics/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Segment
module SegmentIO
class Analytics
module Defaults
module Request
Expand Down
6 changes: 3 additions & 3 deletions lib/segment/analytics/field_parser.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Segment
module SegmentIO
class Analytics
# Handles parsing fields according to the Segment Spec
#
# @see https://segment.com/docs/spec/
class FieldParser
class << self
include Segment::Analytics::Utils
include SegmentIO::Analytics::Utils

# In addition to the common fields, track accepts:
#
Expand Down Expand Up @@ -171,7 +171,7 @@ def check_timestamp!(timestamp)
end

def add_context!(context)
context[:library] = { :name => 'analytics-ruby', :version => Segment::Analytics::VERSION.to_s }
context[:library] = { :name => 'analytics-ruby', :version => SegmentIO::Analytics::VERSION.to_s }
end

# private: Ensures that a string is non-empty
Expand Down
4 changes: 2 additions & 2 deletions lib/segment/analytics/logging.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'logger'

module Segment
module SegmentIO
class Analytics
# Wraps an existing logger and adds a prefix to all messages
class PrefixedLogger
Expand Down Expand Up @@ -35,7 +35,7 @@ def logger
Rails.logger
else
logger = Logger.new STDOUT
logger.progname = 'Segment::Analytics'
logger.progname = 'SegmentIO::Analytics'
logger
end
@logger = PrefixedLogger.new(base_logger, '[analytics-ruby]')
Expand Down
6 changes: 3 additions & 3 deletions lib/segment/analytics/message_batch.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'forwardable'
require 'segment/analytics/logging'

module Segment
module SegmentIO
class Analytics
# A batch of `Message`s to be sent to the API
class MessageBatch
class JSONGenerationError < StandardError; end

extend Forwardable
include Segment::Analytics::Logging
include Segment::Analytics::Defaults::MessageBatch
include SegmentIO::Analytics::Logging
include SegmentIO::Analytics::Defaults::MessageBatch

def initialize(max_message_count)
@messages = []
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/analytics/response.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Segment
module SegmentIO
class Analytics
class Response
attr_reader :status, :error
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/analytics/test_queue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Segment
module SegmentIO
class Analytics
class TestQueue
attr_reader :messages
Expand Down
10 changes: 5 additions & 5 deletions lib/segment/analytics/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
require 'net/https'
require 'json'

module Segment
module SegmentIO
class Analytics
class Transport
include Segment::Analytics::Defaults::Request
include Segment::Analytics::Utils
include Segment::Analytics::Logging
include SegmentIO::Analytics::Defaults::Request
include SegmentIO::Analytics::Utils
include SegmentIO::Analytics::Logging

def initialize(options = {})
options[:host] ||= HOST
Expand All @@ -22,7 +22,7 @@ def initialize(options = {})
@path = options[:path] || PATH
@retries = options[:retries] || RETRIES
@backoff_policy =
options[:backoff_policy] || Segment::Analytics::BackoffPolicy.new
options[:backoff_policy] || SegmentIO::Analytics::BackoffPolicy.new

http = Net::HTTP.new(options[:host], options[:port])
http.use_ssl = options[:ssl]
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/analytics/utils.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'securerandom'

module Segment
module SegmentIO
class Analytics
module Utils
extend self
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/analytics/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Segment
module SegmentIO
class Analytics
VERSION = '2.4.2'
end
Expand Down
8 changes: 4 additions & 4 deletions lib/segment/analytics/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require 'segment/analytics/transport'
require 'segment/analytics/utils'

module Segment
module SegmentIO
class Analytics
class Worker
include Segment::Analytics::Utils
include Segment::Analytics::Defaults
include Segment::Analytics::Logging
include SegmentIO::Analytics::Utils
include SegmentIO::Analytics::Defaults
include SegmentIO::Analytics::Logging

# public: Creates a new worker
#
Expand Down
2 changes: 1 addition & 1 deletion spec/isolated/json_example.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.shared_examples 'message_batch_json' do
it 'MessageBatch generates proper JSON' do
batch = Segment::Analytics::MessageBatch.new(100)
batch = SegmentIO::Analytics::MessageBatch.new(100)
batch << { 'a' => 'b' }
batch << { 'c' => 'd' }

Expand Down
2 changes: 1 addition & 1 deletion spec/segment/analytics/backoff_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe BackoffPolicy do
describe '#initialize' do
Expand Down
2 changes: 1 addition & 1 deletion spec/segment/analytics/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe Client do
let(:client) do
Expand Down
2 changes: 1 addition & 1 deletion spec/segment/analytics/message_batch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe MessageBatch do
subject { described_class.new(100) }
Expand Down
2 changes: 1 addition & 1 deletion spec/segment/analytics/response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe Response do
describe '#status' do
Expand Down
2 changes: 1 addition & 1 deletion spec/segment/analytics/test_queue_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe TestQueue do
let(:test_queue) { described_class.new }
Expand Down
4 changes: 2 additions & 2 deletions spec/segment/analytics/transport_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

module Segment
module SegmentIO
class Analytics
describe Transport do
before do
Expand Down Expand Up @@ -48,7 +48,7 @@ class Analytics

it 'sets a default backoff policy' do
backoff_policy = subject.instance_variable_get(:@backoff_policy)
expect(backoff_policy).to be_a(Segment::Analytics::BackoffPolicy)
expect(backoff_policy).to be_a(SegmentIO::Analytics::BackoffPolicy)
end

it 'initializes a new Net::HTTP with default host and port' do
Expand Down
Loading