idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
9,300 | def as_couch_json _attributes . inject ( { } ) { | h , ( k , v ) | h [ k ] = v . respond_to? ( :as_couch_json ) ? v . as_couch_json : v ; h } end | Provide JSON data hash that can be stored in the database . Will go through each attribute value and request the as_couch_json method on each if available or return the value as - is . |
9,301 | def database! ( name ) connection . head name database ( name ) rescue CouchRest :: NotFound create_db ( name ) end | Creates the database if it doesn t exist |
9,302 | def next_uuid ( count = @uuid_batch_count ) if uuids . nil? || uuids . empty? @uuids = connection . get ( "_uuids?count=#{count}" ) [ "uuids" ] end uuids . pop end | Retrive an unused UUID from CouchDB . Server instances manage caching a list of unused UUIDs . |
9,303 | def get ( url , options = { } ) connection ( url , options ) do | uri , conn | conn . get ( uri . request_uri , options ) end end | Send a GET request . |
9,304 | def put ( url , doc = nil , options = { } ) connection ( url , options ) do | uri , conn | conn . put ( uri . request_uri , doc , options ) end end | Send a PUT request . |
9,305 | def delete ( url , options = { } ) connection ( url , options ) do | uri , conn | conn . delete ( uri . request_uri , options ) end end | Send a DELETE request . |
9,306 | def replicate_from ( other_db , continuous = false , create_target = false , doc_ids = nil ) replicate ( other_db , continuous , :target => name , :create_target => create_target , :doc_ids => doc_ids ) end | Replicates via pulling from another database to this database . Makes no attempt to deal with conflicts . |
9,307 | def replicate_to ( other_db , continuous = false , create_target = false , doc_ids = nil ) replicate ( other_db , continuous , :source => name , :create_target => create_target , :doc_ids => doc_ids ) end | Replicates via pushing to another database . Makes no attempt to deal with conflicts . |
9,308 | def get! ( id , params = { } ) slug = escape_docid ( id ) url = CouchRest . paramify_url ( "#{path}/#{slug}" , params ) result = connection . get ( url ) return result unless result . is_a? ( Hash ) doc = if / / =~ result [ "_id" ] Design . new ( result ) else Document . new ( result ) end doc . database = self doc end | == Retrieving and saving single documents GET a document from CouchDB by id . Returns a Document Design or raises an exception if the document does not exist . |
9,309 | def bulk_save ( docs = nil , opts = { } ) opts = { :use_uuids => true , :all_or_nothing => false } . update ( opts ) if docs . nil? docs = @bulk_save_cache @bulk_save_cache = [ ] end if opts [ :use_uuids ] ids , noids = docs . partition { | d | d [ '_id' ] } uuid_count = [ noids . length , @server . uuid_batch_count ] ... | POST an array of documents to CouchDB . If any of the documents are missing ids supply one from the uuid cache . |
9,310 | def update_doc ( doc_id , params = { } , update_limit = 10 ) resp = { 'ok' => false } last_fail = nil until resp [ 'ok' ] or update_limit <= 0 doc = self . get ( doc_id , params ) yield doc begin resp = self . save_doc doc rescue CouchRest :: RequestFailed => e if e . http_code == 409 update_limit -= 1 last_fail = e el... | Updates the given doc by yielding the current state of the doc and trying to update update_limit times . Returns the doc if successfully updated without hitting the limit . If the limit is reached the last execption will be raised . |
9,311 | def put_attachment ( doc , name , file , options = { } ) file = StringIO . new ( file ) if file . is_a? ( String ) connection . put path_for_attachment ( doc , name ) , file , options end | PUT an attachment directly to CouchDB expects an IO object or a string that will be converted to a StringIO in the file parameter . |
9,312 | def delete_attachment ( doc , name , force = false ) attach_path = path_for_attachment ( doc , name ) begin connection . delete ( attach_path ) rescue Exception => error if force doc = get ( doc [ '_id' ] ) attach_path = path_for_attachment ( doc , name ) connection . delete ( attach_path ) else error end end end | DELETE an attachment directly from CouchDB |
9,313 | def cast_value ( parent , value ) if ! allow_blank && value . to_s . empty? nil else value = typecast_value ( parent , self , value ) associate_casted_value_to_parent ( parent , value ) end end | Cast an individual value |
9,314 | def build ( * args ) raise StandardError , "Cannot build property without a class" if @type . nil? if @init_method . is_a? ( Proc ) @init_method . call ( * args ) else @type . send ( @init_method , * args ) end end | Initialize a new instance of a property s type ready to be used . If a proc is defined for the init method it will be used instead of a normal call to the class . |
9,315 | def front_end ( name , path = name , options = { } ) defaults = { app_name : name } . merge ( options ) post ( "#{path}" => "front_end_builds/builds#create" , defaults : { app_name : name } ) constraints FrontEndBuilds :: HtmlRoutingConstraint . new do get ( "/#{path}/(*path)" => "front_end_builds/bests#show" , default... | Create a front end in your rails router . |
9,316 | def restore ( opts = { } ) run_callbacks ( :restore ) do _paranoia_update ( "$unset" => { paranoid_field => true } ) attributes . delete ( "deleted_at" ) @destroyed = false restore_relations if opts [ :recursive ] true end end | Restores a previously soft - deleted document . Handles this by removing the deleted_at flag . |
9,317 | def good_listize ( real_addresses ) good_listed = clean_addresses ( real_addresses , :good_list ) good_listed = clean_addresses ( good_listed , :bad_list ) unless good_listed . empty? good_listed end | Replace non - white - listed addresses with these sanitized addresses . Allow good listed email addresses and then remove the bad listed addresses |
9,318 | def to_html html = '<table><tr>' @source . each { | color | html . concat ( "<th>" + color + "</th>" ) } html . concat ( "</tr><tr>" ) @source . each { | color | html . concat ( "<td style=\"background-color:" + color + ";\"> </td>" ) } html += '</tr></table>' return html end | display colorset on IRuby notebook as a html table |
9,319 | def generate_html ( temp_path ) path = File . expand_path ( temp_path , __FILE__ ) url = Nyaplot . get_url id = SecureRandom . uuid model = to_json template = File . read ( path ) ERB . new ( template ) . result ( binding ) end | generate static html file |
9,320 | def export_html ( path = "./plot.html" , to_png = false ) path = File . expand_path ( path , Dir :: pwd ) body = generate_html ( "../templates/iruby.erb" ) temp_path = File . expand_path ( "../templates/static_html.erb" , __FILE__ ) template = File . read ( temp_path ) num = File . write ( path , ERB . new ( template )... | export static html file |
9,321 | def add ( type , * data ) df = DataFrame . new ( { x : data [ 0 ] , y : data [ 1 ] , z : data [ 2 ] } ) return add_with_df ( df , type , :x , :y , :z ) end | Add diagram with Array |
9,322 | def add_with_df ( df , type , * labels ) diagram = Diagram3D . new ( df , type , labels ) diagrams = get_property ( :diagrams ) diagrams . push ( diagram ) return diagram end | Add diagram with DataFrame |
9,323 | def export_html ( path = nil ) require 'securerandom' path = "./plot-" + SecureRandom . uuid ( ) . to_s + ".html" if path . nil? Frame . new . tap { | f | f . add ( self ) } . export_html ( path ) end | export html file |
9,324 | def analyze @analyze ||= begin debug { "Analyzing spec and lock:" } if same? debug { " Same!" } return lock . manifests end debug { " Removed:" } ; removed_dependency_names . each { | name | debug { " #{name}" } } debug { " ExplicitRemoved:" } ; explicit_removed_dependency_names . each { | name | debug { " #{n... | Returns an array of those manifests from the previous spec which should be kept based on inspecting the new spec against the locked resolution from the previous spec . |
9,325 | def dependencies_of ( names ) names = Array === names ? names . dup : names . to_a assert_strings! ( names ) deps = Set . new until names . empty? name = names . shift next if deps . include? ( name ) deps << name names . concat index [ name ] . dependencies . map ( & :name ) end deps . to_a end | Straightforward breadth - first graph traversal algorithm . |
9,326 | def fetch_templatable_page! parent_page_path = File . dirname ( @path ) parent_page_path = Kms :: Page :: INDEX_FULLPATH if parent_page_path == "." parent_page = Kms :: Page . published . find_by_fullpath! ( parent_page_path ) templatable_pages = parent_page . children . where ( templatable : true ) templatable_pages .... | finds templatable page that works for path |
9,327 | def permalink templatable_page = Kms :: Page . where ( templatable_type : self . class . name ) . first if templatable_page Pathname . new ( templatable_page . parent . fullpath ) . join ( slug . to_s ) . to_s end end | Entity should respond to slug |
9,328 | def set ( * severities ) @severities = Yell :: Severities . map { true } severity = severities . length > 1 ? severities : severities . first case severity when Array then at ( * severity ) when Range then gte ( severity . first ) . lte ( severity . last ) when String then interpret ( severity ) when Integer , Symbol t... | Create a new level instance . |
9,329 | def show_for ( object , html_options = { } , & block ) html_options = html_options . dup tag = html_options . delete ( :show_for_tag ) || ShowFor . show_for_tag html_options [ :id ] ||= dom_id ( object ) html_options [ :class ] = show_for_html_class ( object , html_options ) builder = html_options . delete ( :builder )... | Creates a div around the object and yields a builder . |
9,330 | def execute_call_xml ( url ) doc = REXML :: Document . new ( execute_call_plain ( url ) ) raise create_error ( doc ) unless doc . elements [ "rsp" ] . attributes [ "stat" ] == "ok" doc end | Get plain response body and parse the XML doc |
9,331 | def execute_call_plain ( url ) res = Net :: HTTP . get_response ( URI . parse ( url ) ) case res when Net :: HTTPRedirection res [ 'location' ] when Net :: HTTPSuccess res . body else raise "HTTP Error connecting to scorm cloud: #{res.inspect}" end end | Execute the call - returns response body or redirect url |
9,332 | def prepare_url ( method , params = { } ) timestamp = Time . now . utc . strftime ( '%Y%m%d%H%M%S' ) params [ :method ] = method params [ :appid ] = @appid params [ :ts ] = timestamp html_params = params . map { | k , v | "#{k.to_s}=#{v}" } . join ( "&" ) raw = @secret + params . keys . sort { | a , b | a . to_s . down... | Get the URL for the call |
9,333 | def create_error ( doc , url ) err = doc . elements [ "rsp" ] . elements [ "err" ] code = err . attributes [ "code" ] msg = err . attributes [ "msg" ] "Error In Scorm Cloud: Error=#{code} Message=#{msg} URL=#{url}" end | Create an exception with code & message |
9,334 | def compile @source . gsub ( '{{STORY_NAME}}' , Twee2 :: build_config . story_name ) . gsub ( '{{STORY_DATA}}' , Twee2 :: build_config . story_file . xmldata ) . gsub ( '{{STORY_FORMAT}}' , @name ) end | Loads the StoryFormat with the specified name Given a story file injects it into the StoryFormat and returns the HTML results |
9,335 | def run_preprocessors @passages . each_key do | k | if @passages [ k ] [ :tags ] . include? 'haml' @passages [ k ] [ :content ] = Haml :: Engine . new ( @passages [ k ] [ :content ] , HAML_OPTIONS ) . render @passages [ k ] [ :tags ] . delete 'haml' end if @passages [ k ] [ :tags ] . include? 'coffee' @passages [ k ] [... | Runs HAML Coffeescript etc . preprocessors across each applicable passage |
9,336 | def validate_id_or_name ( record_name = nil ) child_options = IdNameOptionsValidator . build_child_options ( record_name ) validate_options do any ( * child_options ) . required end end | This method simply checks that either id or name is supplied |
9,337 | def call ( event , * args ) return unless @listeners [ event ] @listeners [ event ] . each do | callback | callback . call ( * args ) end end | Call an event s callbacks with provided arguments . |
9,338 | def remove ( event , value = nil ) return unless @listeners [ event ] if value @listeners [ event ] . delete ( value ) if @listeners [ event ] . empty? @listeners . delete ( event ) end else @listeners . delete ( event ) end end | Remove an specific callback on an event or all an event s callbacks . |
9,339 | def set_autoload_paths if ActiveSupport :: Dependencies . respond_to? ( :autoload_paths ) ActiveSupport :: Dependencies . autoload_paths = configuration . autoload_paths . uniq ActiveSupport :: Dependencies . autoload_once_paths = configuration . autoload_once_paths . uniq else ActiveSupport :: Dependencies . load_path... | Set the paths from which Bowline will automatically load source files and the load_once paths . |
9,340 | def set_root_path! raise 'APP_ROOT is not set' unless defined? ( :: APP_ROOT ) raise 'APP_ROOT is not a directory' unless File . directory? ( :: APP_ROOT ) @root_path = if RUBY_PLATFORM =~ / / File . expand_path ( :: APP_ROOT ) else Pathname . new ( :: APP_ROOT ) . realpath . to_s end Object . const_set ( :RELATIVE_APP... | Create a new Configuration instance initialized with the default values . Set the root_path to APP_ROOT and canonicalize it . |
9,341 | def pods_from_project ( context , master_pods ) context . umbrella_targets . flat_map do | target | root_specs = target . specs . map ( & :root ) . uniq pods = root_specs . select { | spec | master_pods . include? ( spec . name ) } . map { | spec | { :name => spec . name , :version => spec . version . to_s } } user_tar... | Loop though all targets in the pod generate a collection of hashes |
9,342 | def collect @assets = YAML . safe_load ( @manifest ) . map! do | path | full_path = File . join ( @source , path ) File . open ( File . join ( @source , path ) ) do | file | :: JekyllAssetPipeline :: Asset . new ( file . read , File . basename ( path ) , File . dirname ( full_path ) ) end end rescue StandardError => e ... | Collect assets based on manifest |
9,343 | def convert_asset ( klass , asset ) converter = klass . new ( asset ) asset . content = converter . converted asset . filename = File . basename ( asset . filename , '.*' ) if File . extname ( asset . filename ) == '' asset . filename = "#{asset.filename}#{@type}" end rescue StandardError => e puts "Asset Pipeline: Fai... | Convert an asset with a given converter class |
9,344 | def compress @assets . each do | asset | klass = :: JekyllAssetPipeline :: Compressor . subclasses . select do | c | c . filetype == @type end . last break unless klass begin asset . content = klass . new ( asset . content ) . compressed rescue StandardError => e puts "Asset Pipeline: Failed to compress '#{asset.filena... | Compress assets if compressor is defined |
9,345 | def gzip @assets . map! do | asset | gzip_content = Zlib :: Deflate . deflate ( asset . content ) [ asset , :: JekyllAssetPipeline :: Asset . new ( gzip_content , "#{asset.filename}.gz" , asset . dirname ) ] end . flatten! end | Create Gzip versions of assets |
9,346 | def save output_path = @options [ 'output_path' ] staging_path = @options [ 'staging_path' ] @assets . each do | asset | directory = File . join ( @source , staging_path , output_path ) write_asset_file ( directory , asset ) asset . output_path = output_path end end | Save assets to file |
9,347 | def put ( key , data ) queue = queues ( key ) return nil unless queue @stats [ :current_bytes ] += data . size @stats [ :total_items ] += 1 queue . push ( data ) return true end | Create a new QueueCollection at + path + |
9,348 | def take ( key ) queue = queues ( key ) if queue . nil? || queue . length == 0 @stats [ :get_misses ] += 1 return nil else @stats [ :get_hits ] += 1 end result = queue . pop @stats [ :current_bytes ] -= result . size result end | Retrieves data from the queue named + key + |
9,349 | def queues ( key = nil ) return nil if @shutdown_mutex . locked? return @queues if key . nil? return @queues [ key ] if @queues [ key ] @queue_init_mutexes [ key ] ||= Mutex . new if @queue_init_mutexes [ key ] . locked? return nil else begin @queue_init_mutexes [ key ] . lock if @queues [ key ] . nil? @queues [ key ] ... | Returns all active queues . |
9,350 | def pop ( log_trx = true ) raise NoTransactionLog if log_trx && ! @trx begin rv = super ( ! log_trx ) rescue ThreadError puts "WARNING: The queue was empty when trying to pop(). Technically this shouldn't ever happen. Probably a bug in the transactional underpinnings. Or maybe shutdown didn't happen cleanly at some poi... | Retrieves data from the queue . |
9,351 | def run @stats [ :start_time ] = Time . now if @opts [ :syslog_channel ] begin require 'syslog_logger' @@logger = SyslogLogger . new ( @opts [ :syslog_channel ] ) rescue LoadError end end @@logger ||= case @opts [ :logger ] when IO , String ; Logger . new ( @opts [ :logger ] ) when Logger ; @opts [ :logger ] else ; Log... | Initialize a new Starling server but do not accept connections or process requests . |
9,352 | def post_init @stash = [ ] @data = "" @data_buf = "" @server = @opts [ :server ] @logger = StarlingServer :: Base . logger @expiry_stats = Hash . new ( 0 ) @expected_length = nil @server . stats [ :total_connections ] += 1 set_comm_inactivity_timeout @opts [ :timeout ] @queue_collection = @opts [ :queue ] @session_id =... | Creates a new handler for the MemCache protocol that communicates with a given client . |
9,353 | def child ( role ) @cached_children ||= { } @cached_children [ role . to_sym ] ||= self . children . where ( :role => role ) . first || :nil @cached_children [ role . to_sym ] == :nil ? nil : @cached_children [ role . to_sym ] end | Return a child process |
9,354 | def add_child ( role , & block ) attachment = self . children . build attachment . role = role attachment . owner = self . owner attachment . file_name = self . file_name attachment . file_type = self . file_type attachment . disposition = self . disposition attachment . cache_type = self . cache_type attachment . cach... | Add a child attachment |
9,355 | def netmask6 ( scope = :global ) if [ :global , :link ] . include? ( scope ) @network_conf [ "mask6_#{scope}" . to_sym ] ||= IPAddr . new ( 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' ) . mask ( prefix6 ( scope ) ) . to_s if prefix6 ( scope ) else raise ArgumentError , "Unrecognized address scope #{scope}" end end | Retrieve the IPv6 sub - net mask assigned to the interface |
9,356 | def apply_static ( ip , mask , gw , dns , search = nil ) self . address = ip self . netmask = mask self . gateway = gw self . dns = dns self . search_order = search if search save end | Applies the given static network configuration to the interface |
9,357 | def apply_static6 ( ip , prefix , gw , dns , search = nil ) self . address6 = "#{ip}/#{prefix}" self . gateway6 = gw self . dns = dns self . search_order = search if search save end | Applies the given static IPv6 network configuration to the interface |
9,358 | def klass_with_custom_fields ( name ) recipe = self . custom_fields_recipe_for ( name ) _metadata = self . send ( name ) . relation_metadata target = _metadata [ :original_klass ] || _metadata . klass target . klass_with_custom_fields ( recipe ) end | Returns the class enhanced by the custom fields . Be careful call this method only if the source class has been saved with success . |
9,359 | def collect_custom_fields_diff ( name , fields ) memo = self . initialize_custom_fields_diff ( name ) fields . map do | field | field . collect_diff ( memo ) end fields . each do | field | if field . localized_changed? && field . persisted? self . _custom_field_localize_diff [ name ] << { field : field . name , localiz... | Collects all the modifications of the custom fields |
9,360 | def apply_custom_fields_diff ( name ) operations = self . _custom_fields_diff [ name ] operations [ '$set' ] . merge! ( { 'custom_fields_recipe.version' => self . custom_fields_version ( name ) } ) collection , selector = self . send ( name ) . collection , self . send ( name ) . criteria . selector %w( set unset renam... | Apply the modifications collected from the custom fields by updating all the documents of the relation . The update uses the power of mongodb to make it fully optimized . |
9,361 | def apply_custom_fields_localize_diff ( name ) return if self . _custom_field_localize_diff [ name ] . empty? self . send ( name ) . all . each do | record | updates = { } self . _custom_field_localize_diff [ name ] . each do | changes | if changes [ :localized ] value = record . read_attribute ( changes [ :field ] . t... | If the localized attribute has been changed in at least one of the custom fields we have to upgrade all the records enhanced by custom_fields in order to make the values consistent with the mongoid localize option . |
9,362 | def custom_fields_methods ( & filter ) self . custom_fields_recipe [ 'rules' ] . map do | rule | method = self . custom_fields_getters_for rule [ 'name' ] , rule [ 'type' ] if block_given? filter . call ( rule ) ? method : nil else method end end . compact . flatten end | Return the list of the getters dynamically based on the custom_fields recipe in order to get the formatted values of the custom fields . If a block is passed then the list will be filtered accordingly with the following logic . If the block is evaluated as true then the method will be kept in the list otherwise it will... |
9,363 | def custom_fields_safe_setters self . custom_fields_recipe [ 'rules' ] . map do | rule | case rule [ 'type' ] . to_sym when :date , :date_time , :money then "formatted_#{rule['name']}" when :file then [ rule [ 'name' ] , "remove_#{rule['name']}" , "remote_#{rule['name']}_url" ] when :select , :belongs_to then [ "#{rule... | List all the setters that are used by the custom_fields in order to get updated thru a html form for instance . |
9,364 | def custom_fields_basic_attributes { } . tap do | hash | self . non_relationship_custom_fields . each do | rule | name , type = rule [ 'name' ] , rule [ 'type' ] . to_sym method_name = "#{type}_attribute_get" hash . merge! ( self . class . send ( method_name , self , name ) ) end end end | Build a hash for all the non - relationship fields meaning string text date boolean select file types . This hash stores their name and their value . |
9,365 | def is_a_custom_field_many_relationship? ( name ) rule = self . custom_fields_recipe [ 'rules' ] . detect do | rule | rule [ 'name' ] == name && _custom_field_many_relationship? ( rule [ 'type' ] ) end end | Check if the rule defined by the name is a many relationship kind . A many relationship includes has_many and many_to_many |
9,366 | def gauge ( metric , value , time = Time . now , count = 1 ) if valid? ( metric , value , time , count ) && send_command ( "gauge" , metric , value , time . to_i , count . to_i ) value else nil end rescue Exception => e report_exception ( e ) nil end | Sets up a connection to the collector . |
9,367 | def time ( metric , multiplier = 1 ) start = Time . now begin result = yield ensure finish = Time . now duration = finish - start gauge ( metric , duration * multiplier , start ) end result end | Store the duration of a block in a metric . multiplier can be used to scale the duration to desired unit or change the duration in some meaningful way . |
9,368 | def cleanup if running? logger . info "Cleaning up agent, queue size: #{@queue.size}, thread running: #{@thread.alive?}" @allow_reconnect = false if @queue . size > 0 queue_message ( 'exit' ) begin with_timeout ( EXIT_FLUSH_TIMEOUT ) { @thread . join } rescue Timeout :: Error if @queue . size > 0 logger . error "Timed ... | Called when a process is exiting to give it some extra time to push events to the service . An at_exit handler is automatically registered for this method but can be called manually in cases where at_exit is bypassed like Resque workers . |
9,369 | def ecdsa_signature_normalize ( raw_sig , check_only : false ) sigout = check_only ? nil : C :: ECDSASignature . new . pointer res = C . secp256k1_ecdsa_signature_normalize ( @ctx , sigout , raw_sig ) [ res == 1 , sigout ] end | Check and optionally convert a signature to a normalized lower - S form . If check_only is true then the normalized signature is not returned . |
9,370 | def combine ( pubkeys ) raise ArgumentError , 'must give at least 1 pubkey' if pubkeys . empty? outpub = FFI :: Pubkey . new . pointer res = C . secp256k1_ec_pubkey_combine ( @ctx , outpub , pubkeys , pubkeys . size ) raise AssertError , 'failed to combine public keys' unless res == 1 @public_key = outpub outpub end | Add a number of public keys together . |
9,371 | def get_room response = self . class . get ( @api . get_room_config [ :url ] , :query => { :auth_token => @token } . merge ( @api . get_room_config [ :query_params ] ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , response response . parsed_response end | Retrieve data for this room |
9,372 | def update_room ( options = { } ) merged_options = { :privacy => 'public' , :is_archived => false , :is_guest_accessible => false } . merge symbolize ( options ) response = self . class . send ( @api . topic_config [ :method ] , @api . update_room_config [ :url ] , :query => { :auth_token => @token } , :body => { :name... | Update a room |
9,373 | def delete_room response = self . class . send ( @api . delete_room_config [ :method ] , @api . delete_room_config [ :url ] , :query => { :auth_token => @token } . merge ( @api . get_room_config [ :query_params ] ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , response t... | Delete a room |
9,374 | def invite ( user , reason = '' ) response = self . class . post ( @api . invite_config [ :url ] + "/#{user}" , :query => { :auth_token => @token } , :body => { :reason => reason } . to_json , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , response true end | Invite user to this room |
9,375 | def add_member ( user , room_roles = [ 'room_member' ] ) response = self . class . put ( @api . member_config [ :url ] + "/#{user}" , :query => { :auth_token => @token } , :body => { :room_roles => room_roles } . to_json , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , resp... | Add member to this room |
9,376 | def members ( options = { } ) response = self . class . get ( @api . member_config [ :url ] , :query => { :auth_token => @token } . merge ( options ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , response wrap_users ( response ) end | Get a list of members in this room This is all people who have been added a to a private room |
9,377 | def participants ( options = { } ) response = self . class . get ( @api . participant_config [ :url ] , :query => { :auth_token => @token } . merge ( options ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , room_id , response wrap_users ( response ) end | Get a list of participants in this room This is all people currently in the room |
9,378 | def send_message ( message ) response = self . class . post ( @api . send_message_config [ :url ] , :query => { :auth_token => @token } , :body => { :room_id => room_id , :message => message , } . send ( @api . send_config [ :body_format ] ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :... | Send a message to this room . |
9,379 | def send ( from , message , options_or_notify = { } ) if from . length > 20 raise UsernameTooLong , "Username #{from} is `#{from.length} characters long. Limit is 20'" end if options_or_notify == true or options_or_notify == false warn 'DEPRECATED: Specify notify flag as an option (e.g., :notify => true)' options = { :... | Send a notification message to this room . |
9,380 | def send_file ( from , message , file ) if from . length > 20 raise UsernameTooLong , "Username #{from} is `#{from.length} characters long. Limit is 20'" end response = self . class . post ( @api . send_file_config [ :url ] , :query => { :auth_token => @token } , :body => file_body ( { :room_id => room_id , :from => fr... | Send a file to this room . |
9,381 | def topic ( new_topic , options = { } ) merged_options = { :from => 'API' } . merge options response = self . class . send ( @api . topic_config [ :method ] , @api . topic_config [ :url ] , :query => { :auth_token => @token } , :body => { :room_id => room_id , :from => merged_options [ :from ] , :topic => new_topic } .... | Change this room s topic |
9,382 | def history ( options = { } ) merged_options = { :date => 'recent' , :timezone => 'UTC' , :format => 'JSON' , :' ' => 100 , :' ' => 0 , :' ' => nil } . merge options response = self . class . get ( @api . history_config [ :url ] , :query => { :room_id => room_id , :date => merged_options [ :date ] , :timezone => merged... | Pull this room s history |
9,383 | def statistics ( options = { } ) response = self . class . get ( @api . statistics_config [ :url ] , :query => { :room_id => room_id , :date => options [ :date ] , :timezone => options [ :timezone ] , :format => options [ :format ] , :auth_token => @token , } . reject! { | k , v | v . nil? } , :headers => @api . header... | Pull this room s statistics |
9,384 | def create_webhook ( url , event , options = { } ) raise InvalidEvent . new ( "Invalid event: #{event}" ) unless %w( room_message room_notification room_exit room_enter room_topic_change room_archived room_deleted room_unarchived ) . include? event begin u = URI :: parse ( url ) raise InvalidUrl . new ( "Invalid Scheme... | Create a webhook for this room |
9,385 | def delete_webhook ( webhook_id ) response = self . class . delete ( "#{@api.webhook_config[:url]}/#{URI::escape(webhook_id)}" , :query => { :auth_token => @token } , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :webhook , webhook_id , response true end | Delete a webhook for this room |
9,386 | def get_all_webhooks ( options = { } ) merged_options = { :' ' => 0 , :' ' => 100 } . merge ( options ) response = self . class . get ( @api . webhook_config [ :url ] , :query => { :auth_token => @token , :' ' => merged_options [ :' ' ] , :' ' => merged_options [ :' ' ] } , :headers => @api . headers ) ErrorHandler . r... | Gets all webhooks for this room |
9,387 | def get_webhook ( webhook_id ) response = self . class . get ( "#{@api.webhook_config[:url]}/#{URI::escape(webhook_id)}" , :query => { :auth_token => @token } , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :webhook , webhook_id , response response . body end | Get a webhook for this room |
9,388 | def add ( item , opts = { } ) opts = { :skip_duplicate_check => false } . merge ( opts ) raise ArgumentError , "Items must specify both an id and a term" unless item [ "id" ] && item [ "term" ] remove ( "id" => item [ "id" ] ) unless opts [ :skip_duplicate_check ] Soulmate . redis . pipelined do Soulmate . redis . hset... | id term score aliases data |
9,389 | def remove ( item ) prev_item = Soulmate . redis . hget ( database , item [ "id" ] ) if prev_item prev_item = MultiJson . decode ( prev_item ) Soulmate . redis . pipelined do Soulmate . redis . hdel ( database , prev_item [ "id" ] ) phrase = ( [ prev_item [ "term" ] ] + ( prev_item [ "aliases" ] || [ ] ) ) . join ( ' '... | remove only cares about an item s id but for consistency takes an object |
9,390 | def send ( message , options = { } ) message_format = options [ :message_format ] ? options [ :message_format ] : 'text' notify = options [ :notify ] ? options [ :notify ] : false response = self . class . post ( @api . send_config [ :url ] , :query => { :auth_token => @token } , :body => { :message => message , :messa... | Send a private message to user . |
9,391 | def send_file ( message , file ) response = self . class . post ( @api . send_file_config [ :url ] , :query => { :auth_token => @token } , :body => file_body ( { :message => message } . send ( @api . send_config [ :body_format ] ) , file ) , :headers => file_body_headers ( @api . headers ) ) ErrorHandler . response_cod... | Send a private file to user . |
9,392 | def view response = self . class . get ( @api . view_config [ :url ] , :query => { :auth_token => @token } . merge ( @api . view_config [ :query_params ] ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :user , user_id , response User . new ( @token , response . merge ( :api_version => @ap... | Get a user s details . |
9,393 | def rooms response = self . class . get ( @api . user_joined_rooms_config [ :url ] , :query => { :auth_token => @token } . merge ( @api . user_joined_rooms_config [ :query_params ] ) , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :user , user_id , response User . new ( @token , response . ... | Getting all rooms details in which user is present |
9,394 | def file_body ( message , file ) file_name = File . basename ( file . path ) mime_type = MimeMagic . by_path ( file_name ) file_content = Base64 . encode64 ( file . read ) body = [ "--#{BOUNDARY}" ] body << 'Content-Type: application/json; charset=UTF-8' body << 'Content-Disposition: attachment; name="metadata"' body <... | Builds a multipart file body for the api . |
9,395 | def scopes ( room : nil ) path = "#{@api.scopes_config[:url]}/#{URI::escape(@token)}" response = self . class . get ( path , :query => { :auth_token => @token } , :headers => @api . headers ) ErrorHandler . response_code_to_exception_for :room , 'scopes' , response return response [ 'scopes' ] unless response [ 'client... | Returns the scopes for the Auth token |
9,396 | def add_stack ( limit : nil , stack : Kernel . caller ) frame_count = 0 @data [ :stack ] = [ ] stack . each do | i | if ! i . match ( / \/ \/ / ) . nil? || ( i . match ( :: Instana :: VERSION_FULL ) . nil? && i . match ( 'lib/instana/' ) . nil? ) break if limit && frame_count >= limit x = i . split ( ':' ) @data [ :sta... | Adds a backtrace to this span |
9,397 | def add_error ( e ) @data [ :error ] = true if @data . key? ( :ec ) @data [ :ec ] = @data [ :ec ] + 1 else @data [ :ec ] = 1 end if e if e . backtrace . is_a? ( Array ) add_stack ( stack : e . backtrace ) end if HTTP_SPANS . include? ( @data [ :n ] ) set_tags ( :http => { :error => "#{e.class}: #{e.message}" } ) else l... | Log an error into the span |
9,398 | def set_tags ( tags ) return unless tags . is_a? ( Hash ) tags . each do | k , v | set_tag ( k , v ) end self end | Helper method to add multiple tags to this span |
9,399 | def tags ( key = nil ) if custom? tags = @data [ :data ] [ :sdk ] [ :custom ] [ :tags ] else tags = @data [ :data ] [ key ] end key ? tags [ key ] : tags end | Retrieve the hash of tags for this span |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.