_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q19800
Mongoid.Tree.rearrange
train
def rearrange if self.parent_id self.parent_ids = parent.parent_ids + [self.parent_id] else self.parent_ids = [] end self.depth = parent_ids.size rearrange_children! if self.parent_ids_changed? end
ruby
{ "resource": "" }
q19801
CocoapodsMangle.Config.needs_update?
train
def needs_update? return true unless File.exist?(@context.xcconfig_path) xcconfig_hash = Xcodeproj::Config.new(File.new(@context.xcconfig_path)).to_hash needs_update = xcconfig_hash[MANGLED_SPECS_CHECKSUM_XCCONFIG_KEY] != @context.specs_checksum Pod::UI.message '- Mangling config already up to date' unless needs_update needs_update end
ruby
{ "resource": "" }
q19802
CocoapodsMangle.Config.update_pod_xcconfigs_for_mangling!
train
def update_pod_xcconfigs_for_mangling! Pod::UI.message '- Updating Pod xcconfig files' do @context.pod_xcconfig_paths.each do |pod_xcconfig_path| Pod::UI.message "- Updating '#{File.basename(pod_xcconfig_path)}'" update_pod_xcconfig_for_mangling!(pod_xcconfig_path) end end end
ruby
{ "resource": "" }
q19803
CocoapodsMangle.Config.update_pod_xcconfig_for_mangling!
train
def update_pod_xcconfig_for_mangling!(pod_xcconfig_path) mangle_xcconfig_include = "#include \"#{@context.xcconfig_path}\"\n" gcc_preprocessor_defs = File.readlines(pod_xcconfig_path).select { |line| line =~ /GCC_PREPROCESSOR_DEFINITIONS/ }.first gcc_preprocessor_defs.strip! xcconfig_contents = File.read(pod_xcconfig_path) # import the mangling config new_xcconfig_contents = mangle_xcconfig_include + xcconfig_contents # update GCC_PREPROCESSOR_DEFINITIONS to include mangling new_xcconfig_contents.sub!(gcc_preprocessor_defs, gcc_preprocessor_defs + " $(#{MANGLING_DEFINES_XCCONFIG_KEY})") File.open(pod_xcconfig_path, 'w') { |pod_xcconfig| pod_xcconfig.write(new_xcconfig_contents) } end
ruby
{ "resource": "" }
q19804
Motion::Project.CocoaPods.configure_project
train
def configure_project if (xcconfig = self.pods_xcconfig_hash) && ldflags = xcconfig['OTHER_LDFLAGS'] @config.resources_dirs << resources_dir.to_s frameworks = installed_frameworks[:pre_built] if frameworks @config.embedded_frameworks += frameworks @config.embedded_frameworks.uniq! end if @use_frameworks configure_project_frameworks else configure_project_static_libraries end end end
ruby
{ "resource": "" }
q19805
Motion::Project.CocoaPods.install!
train
def install!(update) FileUtils.rm_rf(resources_dir) pods_installer.update = update pods_installer.installation_options.integrate_targets = false pods_installer.install! install_resources copy_cocoapods_env_and_prefix_headers end
ruby
{ "resource": "" }
q19806
Motion::Project.CocoaPods.resources
train
def resources resources = [] script = Pathname.new(@config.project_dir) + SUPPORT_FILES + "Pods-#{TARGET_NAME}-resources.sh" return resources unless File.exist?(script) File.open(script) { |f| f.each_line do |line| if matched = line.match(/install_resource\s+(.*)/) path = (matched[1].strip)[1..-2] if path.start_with?('${PODS_ROOT}') path = path.sub('${PODS_ROOT}/', '') end if path.include?("$PODS_CONFIGURATION_BUILD_DIR") path = File.join(".build", File.basename(path)) end unless File.extname(path) == '.framework' resources << Pathname.new(@config.project_dir) + PODS_ROOT + path end end end } resources.uniq end
ruby
{ "resource": "" }
q19807
Laser.ActsAsStruct.acts_as_struct
train
def acts_as_struct(*members) include Comparable extend InheritedAttributes class_inheritable_array :current_members unless respond_to?(:current_members) self.current_members ||= [] self.current_members.concat members all_members = self.current_members # Only add new members attr_accessor *members # NOT backwards compatible with a Struct's initializer. If you # try to initialize the first argument to a Hash and don't provide # other arguments, you trigger the hash extraction initializer instead # of the positional initializer. That's a bad idea. define_method :initialize do |*args| if args.size == 1 && Hash === args.first initialize_hash(args.first) else if args.size > all_members.size raise ArgumentError.new("#{self.class} has #{all_members.size} members " + "- you provided #{args.size}") end initialize_positional(args) end end # Initializes by treating the input as key-value assignments. define_method :initialize_hash do |hash| hash.each { |k, v| send("#{k}=", v) } end private :initialize_hash # Initialize by treating the input as positional arguments that # line up with the struct members provided to acts_as_struct. define_method :initialize_positional do |args| args.each_with_index do |value, idx| key = all_members[idx] send("#{key}=", value) end end private :initialize_positional # Helper methods for keys/values. define_method(:keys_and_values) { keys.zip(values) } define_method(:values) { keys.map { |member| send member } } define_method(:keys) { all_members } define_method(:each) { |&blk| keys_and_values.each { |k, v| blk.call([k, v]) } } define_method(:'<=>') do |other| each do |key, value| res = (value <=> other.send(key)) if res != 0 return res end end 0 end end
ruby
{ "resource": "" }
q19808
RGL.MutableGraph.cycles
train
def cycles g = self.clone self.inject([]) do |acc, v| acc = acc.concat(g.cycles_with_vertex(v)) g.remove_vertex(v); acc end end
ruby
{ "resource": "" }
q19809
Laser.Analysis.parse
train
def parse(body = self.body) return PARSING_CACHE[body] if PARSING_CACHE[body] pairs = Analysis.analyze_inputs([[file, body]]) PARSING_CACHE[body] = pairs[0][1] end
ruby
{ "resource": "" }
q19810
Laser.Analysis.find_sexps
train
def find_sexps(type, tree = self.parse(self.body)) result = tree[0] == type ? [tree] : [] tree.each do |node| result.concat find_sexps(type, node) if node.is_a?(Array) end result end
ruby
{ "resource": "" }
q19811
RGL.Graph.strongly_connected_components
train
def strongly_connected_components raise NotDirectedError, "strong_components only works for directed graphs." unless directed? vis = TarjanSccVisitor.new(self) depth_first_search(vis) { |v| } vis end
ruby
{ "resource": "" }
q19812
RGL.Graph.each_edge
train
def each_edge (&block) if directed? each_vertex { |u| each_adjacent(u) { |v| yield u,v } } else each_edge_aux(&block) # concrete graphs should to this better end end
ruby
{ "resource": "" }
q19813
Laser.Runner.handle_global_options
train
def handle_global_options(settings) if settings[:"line-length"] @using << Laser.LineLengthWarning(settings[:"line-length"]) end if (only_name = settings[:only]) @fix = @using = Warning.concrete_warnings.select do |w| classname = w.name && w.name.split('::').last (classname && only_name.index(classname)) || (w.short_name && only_name.index(w.short_name)) end end if settings[:profile] require 'benchmark' require 'profile' SETTINGS[:profile] = true end if settings[:include] Laser::SETTINGS[:load_path] = settings[:include].reverse end ARGV.replace(['(stdin)']) if settings[:stdin] end
ruby
{ "resource": "" }
q19814
Laser.Runner.get_settings
train
def get_settings warning_opts = get_warning_options Trollop::options do banner 'LASER: Lexically- and Semantically-Enriched Ruby' opt :fix, 'Should errors be fixed in-line?', short: '-f' opt :display, 'Should errors be displayed?', short: '-b', default: true opt :'report-fixed', 'Should fixed errors be reported anyway?', short: '-r' opt :'line-length', 'Warn at the given line length', short: '-l', type: :int opt :only, 'Only consider the given warning (by short or full name)', short: '-O', type: :string opt :stdin, 'Read Ruby code from standard input', short: '-s' opt :'list-modules', 'Print the discovered, loaded modules' opt :profile, 'Run the profiler during execution' opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true opt :S, 'look for scripts using PATH environment variable', short: '-S' warning_opts.each { |warning| opt(*warning) } end end
ruby
{ "resource": "" }
q19815
Laser.Runner.get_warning_options
train
def get_warning_options all_options = Warning.all_warnings.inject({}) do |result, warning| options = warning.options options = [options] if options.any? && !options[0].is_a?(Array) options.each do |option| result[option.first] = option end result end all_options.values end
ruby
{ "resource": "" }
q19816
Laser.Runner.print_modules
train
def print_modules Analysis::LaserModule.all_modules.map do |mod| result = [] result << if Analysis::LaserClass === mod && mod.superclass then "#{mod.path} < #{mod.superclass.path}" else mod.name end result end.sort.flatten.each { |name| puts name } end
ruby
{ "resource": "" }
q19817
Laser.Runner.convert_warning_list
train
def convert_warning_list(list) list.map do |list| case list when :all then Warning.all_warnings when :whitespace [ExtraBlankLinesWarning, ExtraWhitespaceWarning, OperatorSpacing, MisalignedUnindentationWarning] else list end end.flatten end
ruby
{ "resource": "" }
q19818
Laser.Runner.collect_warnings
train
def collect_warnings(files, scanner) full_list = files.map do |file| data = file == '(stdin)' ? STDIN.read : File.read(file) if scanner.settings[:fix] scanner.settings[:output_file] = scanner.settings[:stdin] ? STDOUT : File.open(file, 'w') end results = scanner.scan(data, file) if scanner.settings[:fix] && !scanner.settings[:stdin] scanner.settings[:output_file].close end results end full_list.flatten end
ruby
{ "resource": "" }
q19819
Laser.Runner.display_warnings
train
def display_warnings(warnings, settings) num_fixable = warnings.select { |warn| warn.fixable? }.size num_total = warnings.size results = "#{num_total} warnings found. #{num_fixable} are fixable." puts results puts '=' * results.size warnings.each do |warning| puts "#{warning.file}:#{warning.line_number} #{warning.name} " + "(#{warning.severity}) - #{warning.desc}" end end
ruby
{ "resource": "" }
q19820
RGL.GraphVisitor.attach_distance_map
train
def attach_distance_map (map = Hash.new(0)) @dist_map = map class << self def handle_tree_edge (u, v) super @dist_map[v] = @dist_map[u] + 1 end # Answer the distance to the start vertex. def distance_to_root (v) @dist_map[v] end end # class end
ruby
{ "resource": "" }
q19821
RGL.Graph.bfs_search_tree_from
train
def bfs_search_tree_from (v) require 'laser/third_party/rgl/adjacency' bfs = bfs_iterator(v) tree = DirectedAdjacencyGraph.new bfs.set_tree_edge_event_handler { |from, to| tree.add_edge(from, to) } bfs.set_to_end # does the search tree end
ruby
{ "resource": "" }
q19822
RGL.Graph.depth_first_search
train
def depth_first_search (vis = DFSVisitor.new(self), &b) each_vertex do |u| unless vis.finished_vertex?(u) vis.handle_start_vertex(u) depth_first_visit(u, vis, &b) end end end
ruby
{ "resource": "" }
q19823
RGL.Graph.depth_first_visit
train
def depth_first_visit (u, vis = DFSVisitor.new(self), &b) vis.color_map[u] = :GRAY vis.handle_examine_vertex(u) each_adjacent(u) { |v| vis.handle_examine_edge(u, v) if vis.follow_edge?(u, v) # (u,v) is a tree edge vis.handle_tree_edge(u, v) # also discovers v vis.color_map[v] = :GRAY # color of v was :WHITE depth_first_visit(v, vis, &b) else # (u,v) is a non tree edge if vis.color_map[v] == :GRAY vis.handle_back_edge(u, v) # (u,v) has gray target else vis.handle_forward_edge(u, v) # (u,v) is a cross or forward edge end end } vis.color_map[u] = :BLACK vis.handle_finish_vertex(u) # finish vertex b.call(u) end
ruby
{ "resource": "" }
q19824
Laser.Scanner.scan
train
def scan(text, filename='(none)') warnings = scan_for_file_warnings(text, filename) text = filter_fixable(warnings).inject(text) do |text, warning| warning.fix(text) end with_fixing_piped_to_output do text.split(/\n/).each_with_index do |line, number| warnings.concat process_line(line, number + 1, filename) end end warnings += unused_method_warnings warnings end
ruby
{ "resource": "" }
q19825
Laser.Scanner.process_line
train
def process_line(line, line_number, filename) warnings = all_warnings_for_line(line, line_number, filename) fix_input(warnings, line, line_number, filename) if @settings[:fix] warnings end
ruby
{ "resource": "" }
q19826
Laser.Scanner.fix_input
train
def fix_input(warnings, line, line_number, filename) fixable_warnings = filter_fixable warnings if fixable_warnings.size == 1 self.settings[:output_lines] << fixable_warnings.first.fix rescue line elsif fixable_warnings.size > 1 new_text = fixable_warnings.first.fix rescue line process_line(new_text, line_number, filename) else self.settings[:output_lines] << line end end
ruby
{ "resource": "" }
q19827
Laser.Scanner.all_warnings_for_line
train
def all_warnings_for_line(line, line_number, filename) new_warnings = check_for_indent_warnings!(line, filename) new_warnings.concat scan_for_line_warnings(line, filename) new_warnings.each {|warning| warning.line_number = line_number} end
ruby
{ "resource": "" }
q19828
Laser.Scanner.check_for_indent_warnings!
train
def check_for_indent_warnings!(line, filename) return [] if line == "" indent_size = get_indent_size line if indent_size > current_indent self.indent_stack.push indent_size elsif indent_size < current_indent previous = self.indent_stack.pop if indent_size != current_indent && using.include?(MisalignedUnindentationWarning) warnings_to_check = [MisalignedUnindentationWarning.new(filename, line, current_indent)] return filtered_warnings_from_line(line, warnings_to_check) end end [] end
ruby
{ "resource": "" }
q19829
Laser.Scanner.scan_for_line_warnings
train
def scan_for_line_warnings(line, filename) warnings = scan_for_warnings(using & LineWarning.all_warnings, line, filename) filtered_warnings_from_line(line, warnings) end
ruby
{ "resource": "" }
q19830
Laser.LexicalAnalysis.lex
train
def lex(body = self.body, token_class = Token) return [] if body =~ /^#.*encoding.*/ Ripper.lex(body).map {|token| token_class.new(token) } end
ruby
{ "resource": "" }
q19831
Laser.LexicalAnalysis.find_token
train
def find_token(*args) body, list = _extract_token_search_args(args) # grr match comment with encoding in it lexed = lex(body) lexed.find.with_index do |tok, idx| is_token = list.include?(tok.type) is_not_symbol = idx == 0 || lexed[idx-1].type != :on_symbeg is_token && is_not_symbol end end
ruby
{ "resource": "" }
q19832
Laser.LexicalAnalysis.split_on_keyword
train
def split_on_keyword(*args) body, keywords = _extract_token_search_args(args) token = find_keyword(body, *keywords) return _split_body_with_raw_token(body, token) end
ruby
{ "resource": "" }
q19833
Laser.LexicalAnalysis.split_on_token
train
def split_on_token(*args) body, tokens = _extract_token_search_args(args) token = find_token(body, *tokens) return _split_body_with_raw_token(body, token) end
ruby
{ "resource": "" }
q19834
RGL.Graph.to_adjacency
train
def to_adjacency result = (directed? ? DirectedAdjacencyGraph : AdjacencyGraph).new each_vertex { |v| result.add_vertex(v) } each_edge { |u,v| result.add_edge(u, v) } result end
ruby
{ "resource": "" }
q19835
RGL.DirectedAdjacencyGraph.initialize_copy
train
def initialize_copy(orig) @vertex_dict = orig.instance_eval{@vertex_dict}.dup @vertex_dict.keys.each do |v| @vertex_dict[v] = @vertex_dict[v].dup end @predecessor_dict = orig.instance_eval{@predecessor_dict}.dup @predecessor_dict.keys.each do |v| @predecessor_dict[v] = @predecessor_dict[v].dup end end
ruby
{ "resource": "" }
q19836
RGL.DirectedAdjacencyGraph.edgelist_class=
train
def edgelist_class=(klass) @vertex_dict.keys.each do |v| @vertex_dict[v] = klass.new @vertex_dict[v].to_a end @predecessor_dict.keys.each do |v| @predecessor_dict[v] = klass.new @predecessor_dict[v].to_a end end
ruby
{ "resource": "" }
q19837
Laser.ModuleExtensions.opposite_method
train
def opposite_method(new_name, old_name) define_method new_name do |*args, &blk| !send(old_name, *args, &blk) end end
ruby
{ "resource": "" }
q19838
Laser.ModuleExtensions.attr_accessor_with_default
train
def attr_accessor_with_default(name, val) ivar_sym = "@#{name}" define_method name do unless instance_variable_defined?(ivar_sym) instance_variable_set(ivar_sym, val) end instance_variable_get ivar_sym end attr_writer name end
ruby
{ "resource": "" }
q19839
Laser.ModuleExtensions.cattr_get_and_setter
train
def cattr_get_and_setter(*attrs) attrs.each do |attr| cattr_accessor attr singleton_class.instance_eval do alias_method "#{attr}_old_get".to_sym, attr define_method attr do |*args, &blk| if args.size > 0 send("#{attr}=", *args) elsif blk != nil send("#{attr}=", blk) else send("#{attr}_old_get") end end end end end
ruby
{ "resource": "" }
q19840
RGL.Graph.dominance_frontier
train
def dominance_frontier(start_node = self.enter, dom_tree) vertices.inject(Hash.new { |h, k| h[k] = Set.new }) do |result, b| preds = b.real_predecessors if preds.size >= 2 preds.each do |p| b_dominator = dom_tree[b].successors.first break unless b_dominator runner = dom_tree[p] while runner && runner != b_dominator result[runner] << b runner = runner.successors.first end end end result end end
ruby
{ "resource": "" }
q19841
RGL.Graph.dominator_set_intersect
train
def dominator_set_intersect(b1, b2, doms) finger1, finger2 = b1, b2 while finger1.post_order_number != finger2.post_order_number finger1 = doms[finger1] while finger1.post_order_number < finger2.post_order_number finger2 = doms[finger2] while finger2.post_order_number < finger1.post_order_number end finger1 end
ruby
{ "resource": "" }
q19842
OodCore.Cluster.batch_connect_config
train
def batch_connect_config(template = nil) if template @batch_connect_config.fetch(template.to_sym, {}).to_h.symbolize_keys.merge(template: template.to_sym) else @batch_connect_config end end
ruby
{ "resource": "" }
q19843
OodCore.Cluster.batch_connect_template
train
def batch_connect_template(context = {}) context = context.to_h.symbolize_keys BatchConnect::Factory.build batch_connect_config(context[:template] || :basic).merge(context) end
ruby
{ "resource": "" }
q19844
OodCore.Cluster.custom_allow?
train
def custom_allow?(feature) allow? && !custom_config(feature).empty? && build_acls(custom_config(feature).fetch(:acls, []).map(&:to_h)).all?(&:allow?) end
ruby
{ "resource": "" }
q19845
OodCore.Cluster.to_h
train
def to_h { id: id, metadata: metadata_config, login: login_config, job: job_config, custom: custom_config, acls: acls_config, batch_connect: batch_connect_config } end
ruby
{ "resource": "" }
q19846
DRMAA.Session.run_bulk
train
def run_bulk(t, first, last, incr = 1) retry_until { DRMAA.run_bulk_jobs(t.ptr, first, last, incr) } end
ruby
{ "resource": "" }
q19847
DRMAA.Session.wait_each
train
def wait_each(timeout = -1) if ! block_given? ary = Array.new end while true begin info = DRMAA.wait(ANY_JOB, timeout) rescue DRMAAInvalidJobError break end if block_given? yield info else ary << info end end if ! block_given? return ary end end
ruby
{ "resource": "" }
q19848
MetaWhere.Relation.predicate_visitor
train
def predicate_visitor join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_joins) MetaWhere::Visitors::Predicate.new(join_dependency) end
ruby
{ "resource": "" }
q19849
Sailthru.Client.schedule_blast_from_template
train
def schedule_blast_from_template(template, list, schedule_time, options={}) post = options ? options : {} post[:copy_template] = template post[:list] = list post[:schedule_time] = schedule_time api_post(:blast, post) end
ruby
{ "resource": "" }
q19850
Sailthru.Client.schedule_blast_from_blast
train
def schedule_blast_from_blast(blast_id, schedule_time, options={}) post = options ? options : {} post[:copy_blast] = blast_id #post[:name] = name post[:schedule_time] = schedule_time api_post(:blast, post) end
ruby
{ "resource": "" }
q19851
Sailthru.Client.update_blast
train
def update_blast(blast_id, name = nil, list = nil, schedule_time = nil, from_name = nil, from_email = nil, subject = nil, content_html = nil, content_text = nil, options = {}) data = options ? options : {} data[:blast_id] = blast_id if name != nil data[:name] = name end if list != nil data[:list] = list end if schedule_time != nil data[:schedule_time] = schedule_time end if from_name != nil data[:from_name] = from_name end if from_email != nil data[:from_email] = from_email end if subject != nil data[:subject] = subject end if content_html != nil data[:content_html] = content_html end if content_text != nil data[:content_text] = content_text end api_post(:blast, data) end
ruby
{ "resource": "" }
q19852
Sailthru.Client.stats_list
train
def stats_list(list = nil, date = nil) data = {} if list != nil data[:list] = list end if date != nil data[:date] = date end data[:stat] = 'list' api_get(:stats, data) end
ruby
{ "resource": "" }
q19853
Sailthru.Client.stats_blast
train
def stats_blast(blast_id = nil, start_date = nil, end_date = nil, options = {}) data = options if blast_id != nil data[:blast_id] = blast_id end if start_date != nil data[:start_date] = start_date end if end_date != nil data[:end_date] = end_date end data[:stat] = 'blast' api_get(:stats, data) end
ruby
{ "resource": "" }
q19854
Sailthru.Client.stats_send
train
def stats_send(template = nil, start_date = nil, end_date = nil, options = {}) data = options if template != nil data[:template] = template end if start_date != nil data[:start_date] = start_date end if end_date != nil data[:end_date] = end_date end data[:stat] = 'send' api_get(:stats, data) end
ruby
{ "resource": "" }
q19855
Sailthru.Client.save_alert
train
def save_alert(email, type, template, _when = nil, options = {}) data = options data[:email] = email data[:type] = type data[:template] = template if (type == 'weekly' || type == 'daily') data[:when] = _when end api_post(:alert, data) end
ruby
{ "resource": "" }
q19856
Sailthru.Client.process_job
train
def process_job(job, options = {}, report_email = nil, postback_url = nil, binary_key = nil) data = options data['job'] = job if !report_email.nil? data['report_email'] = report_email end if !postback_url.nil? data['postback_url'] = postback_url end api_post(:job, data, binary_key) end
ruby
{ "resource": "" }
q19857
Sailthru.Client.process_import_job
train
def process_import_job(list, emails, report_email = nil, postback_url = nil, options = {}) data = options data['list'] = list data['emails'] = Array(emails).join(',') process_job(:import, data, report_email, postback_url) end
ruby
{ "resource": "" }
q19858
Sailthru.Client.process_import_job_from_file
train
def process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil, options = {}) data = options data['list'] = list data['file'] = file_path process_job(:import, data, report_email, postback_url, 'file') end
ruby
{ "resource": "" }
q19859
Sailthru.Client.process_update_job_from_file
train
def process_update_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) data = options data['file'] = file_path process_job(:update, data, report_email, postback_url, 'file') end
ruby
{ "resource": "" }
q19860
Sailthru.Client.process_purchase_import_job_from_file
train
def process_purchase_import_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) data = options data['file'] = file_path process_job(:purchase_import, data, report_email, postback_url, 'file') end
ruby
{ "resource": "" }
q19861
Sailthru.Client.process_snapshot_job
train
def process_snapshot_job(query = {}, report_email = nil, postback_url = nil, options = {}) data = options data['query'] = query process_job(:snapshot, data, report_email, postback_url) end
ruby
{ "resource": "" }
q19862
Sailthru.Client.process_export_list_job
train
def process_export_list_job(list, report_email = nil, postback_url = nil, options = {}) data = options data['list'] = list process_job(:export_list_data, data, report_email, postback_url) end
ruby
{ "resource": "" }
q19863
Sailthru.Client.get_user_by_key
train
def get_user_by_key(id, key, fields = {}) data = { 'id' => id, 'key' => key, 'fields' => fields } api_get(:user, data) end
ruby
{ "resource": "" }
q19864
Sailthru.Client.get_trigger_by_template
train
def get_trigger_by_template(template, trigger_id = nil) data = {} data['template'] = template if trigger_id != nil then data['trigger_id'] = trigger_id end api_get(:trigger, data) end
ruby
{ "resource": "" }
q19865
Sailthru.Client.post_template_trigger
train
def post_template_trigger(template, time, time_unit, event, zephyr) data = {} data['template'] = template data['time'] = time data['time_unit'] = time_unit data['event'] = event data['zephyr'] = zephyr api_post(:trigger, data) end
ruby
{ "resource": "" }
q19866
Sailthru.Client.post_event_trigger
train
def post_event_trigger(event, time, time_unit, zephyr) data = {} data['time'] = time data['time_unit'] = time_unit data['event'] = event data['zephyr'] = zephyr api_post(:trigger, data) end
ruby
{ "resource": "" }
q19867
Sailthru.Client.set_up_post_request
train
def set_up_post_request(uri, data, headers, binary_key = nil) if !binary_key.nil? binary_data = data[binary_key] if binary_data.is_a?(StringIO) data[binary_key] = UploadIO.new( binary_data, "text/plain", "local.path" ) else data[binary_key] = UploadIO.new( File.open(binary_data), "text/plain" ) end req = Net::HTTP::Post::Multipart.new(uri.path, data) else req = Net::HTTP::Post.new(uri.path, headers) req.set_form_data(data) end req end
ruby
{ "resource": "" }
q19868
BaseCRM.TasksService.create
train
def create(task) validate_type!(task) attributes = sanitize(task) _, _, root = @client.post("/tasks", attributes) Task.new(root[:data]) end
ruby
{ "resource": "" }
q19869
BaseCRM.TasksService.update
train
def update(task) validate_type!(task) params = extract_params!(task, :id) id = params[:id] attributes = sanitize(task) _, _, root = @client.put("/tasks/#{id}", attributes) Task.new(root[:data]) end
ruby
{ "resource": "" }
q19870
BaseCRM.ContactsService.create
train
def create(contact) validate_type!(contact) attributes = sanitize(contact) _, _, root = @client.post("/contacts", attributes) Contact.new(root[:data]) end
ruby
{ "resource": "" }
q19871
BaseCRM.ContactsService.update
train
def update(contact) validate_type!(contact) params = extract_params!(contact, :id) id = params[:id] attributes = sanitize(contact) _, _, root = @client.put("/contacts/#{id}", attributes) Contact.new(root[:data]) end
ruby
{ "resource": "" }
q19872
BaseCRM.CallsService.create
train
def create(call) validate_type!(call) attributes = sanitize(call) _, _, root = @client.post("/calls", attributes) Call.new(root[:data]) end
ruby
{ "resource": "" }
q19873
BaseCRM.CallsService.update
train
def update(call) validate_type!(call) params = extract_params!(call, :id) id = params[:id] attributes = sanitize(call) _, _, root = @client.put("/calls/#{id}", attributes) Call.new(root[:data]) end
ruby
{ "resource": "" }
q19874
BaseCRM.AssociatedContactsService.where
train
def where(deal_id, options = {}) _, _, root = @client.get("/deals/#{deal_id}/associated_contacts", options) root[:items].map{ |item| AssociatedContact.new(item[:data]) } end
ruby
{ "resource": "" }
q19875
BaseCRM.AssociatedContactsService.create
train
def create(deal_id, associated_contact) validate_type!(associated_contact) attributes = sanitize(associated_contact) _, _, root = @client.post("/deals/#{deal_id}/associated_contacts", attributes) AssociatedContact.new(root[:data]) end
ruby
{ "resource": "" }
q19876
BaseCRM.Sync.fetch
train
def fetch(&block) return unless block_given? # Set up a new synchronization session for given device's UUID session = @client.sync.start(@device_uuid) # Check if there is anything to synchronize return unless session && session.id # Drain the main queue unitl there is no more data (empty array) loop do queued_data = @client.sync.fetch(@device_uuid, session.id) # nothing more to synchronize ? break unless queued_data # something bad at the backend next if queued_data.empty? ack_keys = [] queued_data.each do |sync_meta, resource| op, ack_key = block.call(sync_meta, resource) ack_keys << ack_key if op == :ack end # As we fetch new data, we need to send ackwledgement keys - if any @client.sync.ack(@device_uuid, ack_keys) unless ack_keys.empty? end end
ruby
{ "resource": "" }
q19877
BaseCRM.SyncService.start
train
def start(device_uuid) validate_device!(device_uuid) status, _, root = @client.post("/sync/start", {}, build_headers(device_uuid)) return nil if status == 204 build_session(root) end
ruby
{ "resource": "" }
q19878
BaseCRM.SyncService.fetch
train
def fetch(device_uuid, session_id, queue='main') validate_device!(device_uuid) raise ArgumentError, "session_id must not be nil nor empty" unless session_id && !session_id.strip.empty? raise ArgumentError, "queue name must not be nil nor empty" unless queue && !queue.strip.empty? status, _, root = @client.get("/sync/#{session_id}/queues/#{queue}", {}, build_headers(device_uuid)) return nil if status == 204 root[:items].map do |item| klass = classify_type(item[:meta][:type]) next unless klass [build_meta(item[:meta]), klass.new(item[:data])] end end
ruby
{ "resource": "" }
q19879
BaseCRM.SyncService.ack
train
def ack(device_uuid, ack_keys) validate_device!(device_uuid) raise ArgumentError, "ack_keys must not be nil and an array" unless ack_keys && ack_keys.is_a?(Array) return true if ack_keys.empty? payload = { :ack_keys => ack_keys.map(&:to_s) } status, _, _ = @client.post('/sync/ack', payload, build_headers(device_uuid)) status == 202 end
ruby
{ "resource": "" }
q19880
BaseCRM.TagsService.create
train
def create(tag) validate_type!(tag) attributes = sanitize(tag) _, _, root = @client.post("/tags", attributes) Tag.new(root[:data]) end
ruby
{ "resource": "" }
q19881
BaseCRM.TagsService.update
train
def update(tag) validate_type!(tag) params = extract_params!(tag, :id) id = params[:id] attributes = sanitize(tag) _, _, root = @client.put("/tags/#{id}", attributes) Tag.new(root[:data]) end
ruby
{ "resource": "" }
q19882
BaseCRM.LossReasonsService.create
train
def create(loss_reason) validate_type!(loss_reason) attributes = sanitize(loss_reason) _, _, root = @client.post("/loss_reasons", attributes) LossReason.new(root[:data]) end
ruby
{ "resource": "" }
q19883
BaseCRM.LossReasonsService.update
train
def update(loss_reason) validate_type!(loss_reason) params = extract_params!(loss_reason, :id) id = params[:id] attributes = sanitize(loss_reason) _, _, root = @client.put("/loss_reasons/#{id}", attributes) LossReason.new(root[:data]) end
ruby
{ "resource": "" }
q19884
BaseCRM.NotesService.create
train
def create(note) validate_type!(note) attributes = sanitize(note) _, _, root = @client.post("/notes", attributes) Note.new(root[:data]) end
ruby
{ "resource": "" }
q19885
BaseCRM.NotesService.update
train
def update(note) validate_type!(note) params = extract_params!(note, :id) id = params[:id] attributes = sanitize(note) _, _, root = @client.put("/notes/#{id}", attributes) Note.new(root[:data]) end
ruby
{ "resource": "" }
q19886
BaseCRM.SourcesService.create
train
def create(source) validate_type!(source) attributes = sanitize(source) _, _, root = @client.post("/sources", attributes) Source.new(root[:data]) end
ruby
{ "resource": "" }
q19887
BaseCRM.OrdersService.create
train
def create(order) validate_type!(order) attributes = sanitize(order) _, _, root = @client.post("/orders", attributes) Order.new(root[:data]) end
ruby
{ "resource": "" }
q19888
BaseCRM.OrdersService.update
train
def update(order) validate_type!(order) params = extract_params!(order, :id) id = params[:id] attributes = sanitize(order) _, _, root = @client.put("/orders/#{id}", attributes) Order.new(root[:data]) end
ruby
{ "resource": "" }
q19889
BaseCRM.LeadsService.create
train
def create(lead) validate_type!(lead) attributes = sanitize(lead) _, _, root = @client.post("/leads", attributes) Lead.new(root[:data]) end
ruby
{ "resource": "" }
q19890
BaseCRM.LeadsService.update
train
def update(lead) validate_type!(lead) params = extract_params!(lead, :id) id = params[:id] attributes = sanitize(lead) _, _, root = @client.put("/leads/#{id}", attributes) Lead.new(root[:data]) end
ruby
{ "resource": "" }
q19891
BaseCRM.DealsService.create
train
def create(deal) validate_type!(deal) attributes = sanitize(deal) _, _, root = @client.post("/deals", attributes) Deal.new(root[:data]) end
ruby
{ "resource": "" }
q19892
BaseCRM.DealsService.update
train
def update(deal) validate_type!(deal) params = extract_params!(deal, :id) id = params[:id] attributes = sanitize(deal) _, _, root = @client.put("/deals/#{id}", attributes) Deal.new(root[:data]) end
ruby
{ "resource": "" }
q19893
BaseCRM.LineItemsService.where
train
def where(order_id, options = {}) _, _, root = @client.get("/orders/#{order_id}/line_items", options) root[:items].map{ |item| LineItem.new(item[:data]) } end
ruby
{ "resource": "" }
q19894
BaseCRM.LineItemsService.create
train
def create(order_id, line_item) validate_type!(line_item) attributes = sanitize(line_item) _, _, root = @client.post("/orders/#{order_id}/line_items", attributes) LineItem.new(root[:data]) end
ruby
{ "resource": "" }
q19895
BaseCRM.LineItemsService.find
train
def find(order_id, id) _, _, root = @client.get("/orders/#{order_id}/line_items/#{id}") LineItem.new(root[:data]) end
ruby
{ "resource": "" }
q19896
BaseCRM.ProductsService.create
train
def create(product) validate_type!(product) attributes = sanitize(product) _, _, root = @client.post("/products", attributes) Product.new(root[:data]) end
ruby
{ "resource": "" }
q19897
BaseCRM.ProductsService.update
train
def update(product) validate_type!(product) params = extract_params!(product, :id) id = params[:id] attributes = sanitize(product) _, _, root = @client.put("/products/#{id}", attributes) Product.new(root[:data]) end
ruby
{ "resource": "" }
q19898
BaseCRM.DealUnqualifiedReasonsService.where
train
def where(options = {}) _, _, root = @client.get("/deal_unqualified_reasons", options) root[:items].map{ |item| DealUnqualifiedReason.new(item[:data]) } end
ruby
{ "resource": "" }
q19899
BaseCRM.DealUnqualifiedReasonsService.create
train
def create(deal_unqualified_reason) validate_type!(deal_unqualified_reason) attributes = sanitize(deal_unqualified_reason) _, _, root = @client.post("/deal_unqualified_reasons", attributes) DealUnqualifiedReason.new(root[:data]) end
ruby
{ "resource": "" }