Class: Metadata::MetadataService

Inherits:
Object
  • Object
show all
Defined in:
lib/metadata_services/metadata_service.rb

Constant Summary collapse

API_VERSION =

todo move to constants file

33.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ MetadataService

Returns a new instance of MetadataService.



30
31
32
33
# File 'lib/metadata_services/metadata_service.rb', line 30

def initialize(args = {})
  @args = args
   = get_client
end

Instance Attribute Details

#current_session_idObject

Returns the value of attribute current_session_id.



28
29
30
# File 'lib/metadata_services/metadata_service.rb', line 28

def current_session_id
  @current_session_id
end

#metadata_clientObject

Returns the value of attribute metadata_client.



28
29
30
# File 'lib/metadata_services/metadata_service.rb', line 28

def 
  
end

#zip_nameObject

Returns the value of attribute zip_name.



28
29
30
# File 'lib/metadata_services/metadata_service.rb', line 28

def zip_name
  @zip_name
end

Instance Method Details

#deployObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/metadata_services/metadata_service.rb', line 59

def deploy
  begin
    dir_zip_service = SfdcDirectoryService.new(@args)
    @zip_name = dir_zip_service.write
    blob_zip = Base64.encode64(File.open(@zip_name, "rb").read)

    # todo read options from console arguments
    options = {
      singlePackage: true,
      rollbackOnError: true,
      checkOnly: false,
      allowMissingFiles: false,
      runAllTests: false,
      ignoreWarnings: false
    }

    # prepare xml for deployment
    deploy_options_snippet = ""
    options.each do |k, v|
      # todo take care of array options if any
      value = @args[k].nil? ? v.to_s : @args[k].to_s
      key = k.to_s
      deploy_options_snippet += "<met:#{key}>#{value}</met:#{key}>"
    end

    debug_options_snippet = "" #by default no debug options

    deploy_request_xml = File.read(File.dirname(__FILE__) + "/deploy_request.xml");
    xml_param = deploy_request_xml % [debug_options_snippet, @current_session_id, blob_zip, deploy_options_snippet]
    response = .call(:deploy, :xml => xml_param)
    # todo catch exceptions

    if response.body[:deploy_response][:result][:state] == "Queued"
      p "DEPLOYMENT STARTED. YOU CAN ALSO CHECK DEPLOYMENT STATUS IN SALESFORCE ORG."

      Forcer::StatusPrintService.new().run_status_check(
          {id: response.body[:deploy_response][:result][:id], session_id: @current_session_id},
          lambda { |header, body| .call(:check_deploy_status, soap_header: header) { message(body) }}
      ) unless @args[:unit_test_running]

    else
      p "DEPLOYMENT FAILED. CHECK DEPLOYMENT STATUS LOG IN SALESFORCE ORG."
    end
  ensure
    p "deleting zip file with project metadata"
    FileUtils.rm_f @zip_name
  end

  return response
end

#listObject

lists metadata types like Classes, Pages



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metadata_services/metadata_service.rb', line 36

def list
  default_list = ["CustomObject", "ApexClass", "ApexTrigger", "CustomLabels", "CustomTab", "EmailTemplate",
    "Profile", "Queue", "StaticResource", "ApexComponent", "ApexPage"]

  # assume components listed in terminal without commas as option to program
  if @args[:types] != nil
    types = @args[:types]
  elsif
    types = default_list
  end

  queries = ""
  types.each do |type|
    queries += "<met:type>#{type.to_s}</met:type><met:folder>#{type.to_s}</met:folder>"
  end

   = File.read(File.dirname(__FILE__) + "/list_metadata_request.xml")
  xml_param =  % [@current_session_id, queries, API_VERSION]
  response = .call(:list_metadata, :xml => xml_param)

  return response
end