Sha256: 121e93220a13481bfa0ba96c6b3ef93128dc2926e849dcc5ef95f90d0554a2c3
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
require 'hubspot-api-ruby' namespace :hubspot do desc 'Dump properties to file' task :dump_properties, [:kind, :file, :hapikey, :include, :exclude] do |_, args| Hubspot::Deprecator.build.deprecation_warning("hubspot:dump_properties") hapikey = args[:hapikey] || ENV['HUBSPOT_API_KEY'] kind = args[:kind] unless %w(contact deal).include?(kind) raise ArgumentError, ':kind must be either "contact" or "deal"' end klass = kind == 'contact' ? Hubspot::ContactProperties : Hubspot::DealProperties props = Hubspot::Utils::dump_properties(klass, hapikey, build_filter(args)) if args[:file].blank? puts JSON.pretty_generate(props) else File.open(args[:file], 'w') do |f| f.write(JSON.pretty_generate(props)) end end end desc 'Restore properties from file' task :restore_properties, [:kind, :file, :hapikey, :dry_run] do |_, args| Hubspot::Deprecator.build.deprecation_warning("hubspot:restore_properties") hapikey = args[:hapikey] || ENV['HUBSPOT_API_KEY'] if args[:file].blank? raise ArgumentError, ':file is a required parameter' end kind = args[:kind] unless %w(contact deal).include?(kind) raise ArgumentError, ':kind must be either "contact" or "deal"' end klass = kind == 'contact' ? Hubspot::ContactProperties : Hubspot::DealProperties file = File.read(args[:file]) props = JSON.parse(file) Hubspot::Utils.restore_properties(klass, hapikey, props, args[:dry_run] != 'false') end private def build_filter(args) { include: val_to_array(args[:include]), exclude: val_to_array(args[:exclude]) } end def val_to_array(val) val.blank? ? val : val.split(/\W+/) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hubspot-api-ruby-0.9.0 | lib/tasks/hubspot.rake |
hubspot-api-ruby-0.8.1 | lib/tasks/hubspot.rake |
hubspot-api-ruby-0.8.0 | lib/tasks/hubspot.rake |