lib/powertrack/streaming/stream.rb in powertrack-1.2.0 vs lib/powertrack/streaming/stream.rb in powertrack-1.3.0
- old
+ new
@@ -19,12 +19,12 @@
# The format of the URLs to connect to the various stream services
FEATURE_URL_FORMAT = {
# [ hostname, account, source, mode, label, feature ]
v1: "https://%s.gnip.com/accounts/%s/publishers/%s/%s/track/%s%s.json".freeze,
- # [ hostname, feature, account, source, label, sub-feature ]
- v2: "https://gnip-%s.twitter.com/%s/powertrack/accounts/%s/publishers/%s/%s%s.json".freeze
+ # [ hostname, domain, feature, stream type, account, source, label, sub-feature ]
+ v2: "https://gnip-%s.%s.com/%s/%s/accounts/%s/publishers/%s/%s%s.json".freeze
}.freeze
# The default timeout on a connection to PowerTrack. Can be overriden per call.
DEFAULT_CONNECTION_TIMEOUT = 30
@@ -66,14 +66,11 @@
@data_source = data_source
@label = label
@options = DEFAULT_STREAM_OPTIONS.merge(options || {})
@replay = !!@options[:replay]
@client_id = @options[:client_id]
- @stream_mode = @replay ? 'replay' : 'streams'
-
- # force v1 if Replay activated
- @v2 = !@replay && !!@options[:v2]
+ @v2 = !!@options[:v2]
end
# Adds many rules to your PowerTrack stream’s ruleset.
#
# <tt>POST /rules</tt>
@@ -179,25 +176,33 @@
# Returns the URL of the stream for a given feature.
def feature_url(hostname, feature=nil, sub_feature=nil)
_url = nil
if @v2
- feature ||= hostname
+ feature ||= @replay ? 'replay' : hostname
sub_feature = sub_feature ? "/#{sub_feature}" : ''
+ stream_type = (feature == 'rules' && @replay ? 'powertrack-replay' : 'powertrack')
+ # replay streaming is on gnip.com while replay rules are on twitter.com...
+ domain = (feature == 'replay' && @replay ? 'gnip' : 'twitter')
+
_url = FEATURE_URL_FORMAT[:v2] %
[ hostname,
+ domain,
feature,
+ stream_type,
@account_name,
@data_source,
@label,
sub_feature ]
else
feature = feature ? "/#{feature}" : ''
+ mode = @replay ? 'replay' : 'streams'
+
_url = FEATURE_URL_FORMAT[:v1] %
[ hostname,
@account_name,
@data_source,
- @stream_mode,
+ mode,
@label,
feature ]
_url += "?client=#{@client_id}" if @client_id
end