lib/livefyre/client.rb in livefyre-0.0.1 vs lib/livefyre/client.rb in livefyre-0.1.0

- old
+ new

@@ -6,11 +6,11 @@ ROLES = %w(admin member none outcast owner) # Public: Valid scopes for #set_user_role SCOPES = %w(domain site conv) - attr_accessor :host, :key, :options, :system_token, :http_client + attr_accessor :host, :key, :options, :system_token, :http_client, :site_key, :quill, :stream, :bootstrap, :search def_delegators :http_client, :get, :post, :delete, :put # Public: Create a new Livefyre client. # @@ -21,10 +21,15 @@ def initialize(options = {}) @options = options.clone @host = options.delete(:network) || options.delete(:host) raise "Invalid host" if @host.nil? @http_client = Faraday.new(:url => "http://#{@host}") + @quill = Faraday.new(:url => "http://quill.#{@host}") + @stream = Faraday.new(:url => "http://stream.#{@host}") + @search = Faraday.new(:url => "http://search.#{@host}") + @bootstrap = Faraday.new(:url => "http://bootstrap.#{@host}") + @site_key = options[:site_key] @key = options.delete(:secret) || options.delete(:key) || options.delete(:network_key) raise "Invalid secret key" if @key.nil? @system_token = options.delete(:system_token) @@ -105,13 +110,32 @@ # Returns [String] JID def jid(id) "%s@%s" % [id, host] end + # Internal: Identifier to use to uniquely identify this client. + # + # Returns string ID + def identifier + @identifier ||= "RubyLib-#{Process.pid}-#{local_ip}-#{object_id}" + end + # Internal: Returns a cleaner string representation of this object # # Returns [String] representation of this class def to_s "#<#{self.class.name}:0x#{object_id.to_s(16).rjust(14, "0")} host='#{host}' key='#{key}'>" + end + + private + + def local_ip + orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily + UDPSocket.open do |s| + s.connect '64.233.187.99', 1 + s.addr.last + end + ensure + Socket.do_not_reverse_lookup = orig end end end \ No newline at end of file