Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade gem dependencies, upgrade savon to v2, fix issues, wsdl v50.0 #74

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/metaforce.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'savon'
require 'hashie'
require 'active_support'
require 'active_support/core_ext'

require 'metaforce/version'
Expand Down
23 changes: 13 additions & 10 deletions lib/metaforce/abstract_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ def initialize(options={})

# Internal: The Savon client to send SOAP requests with.
def client
@client ||= Savon.client(wsdl) do |wsdl|
wsdl.endpoint = endpoint
end.tap do |client|
client.config.soap_header = soap_headers
client.http.auth.ssl.verify_mode = :none
end
@client ||= Savon.client(
wsdl: wsdl,
endpoint: endpoint,
soap_header: soap_headers,
ssl_verify_mode: :none,
namespace_identifier: :ins0,
log: true,
log_level: :debug
)
end

# Internal: Performs a SOAP request. If the session is invalid, it will
# attempt to reauthenticate by called the reauthentication handler if
# present.
def request(*args, &block)
def call(*args, &block)
authenticate! unless session_id
retries = authentication_retries
begin
perform_request(*args, &block)
rescue Savon::SOAP::Fault => e
rescue Savon::SOAPFault => e
if e.message =~ /INVALID_SESSION_ID/ && authentication_handler && retries > 0
authenticate!
retries -= 1
Expand All @@ -51,7 +54,7 @@ def request(*args, &block)
end

def perform_request(*args, &block)
response = client.request(*args, &block)
response = client.call(*args, &block)
Hashie::Mash.new(response.body)[:"#{args[0]}_response"].result
end

Expand All @@ -60,7 +63,7 @@ def perform_request(*args, &block)
def authenticate!
options = authentication_handler.call(self, @options)
@options.merge!(options)
client.config.soap_header = soap_headers
client
end

# A proc object that gets called when the client needs to reauthenticate.
Expand Down
2 changes: 1 addition & 1 deletion lib/metaforce/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def initialize
end

def api_version
@api_version ||= '26.0'
@api_version ||= '50.0'
end

def host
Expand Down
15 changes: 7 additions & 8 deletions lib/metaforce/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ def initialize(username, password, security_token=nil)
#
# Returns a hash with the session id and server urls.
def login
response = client.request(:login) do
soap.body = {
:username => username,
:password => password
}
response = client.call(:login) do |locals|
locals.message username: username, password: password
end
response.body[:login_response][:result]
end
Expand All @@ -21,9 +18,11 @@ def login

# Internal: Savon client.
def client
@client ||= Savon.client(Metaforce.configuration.partner_wsdl) do |wsdl|
wsdl.endpoint = Metaforce.configuration.endpoint
end.tap { |client| client.http.auth.ssl.verify_mode = :none }
@client ||= Savon.client(
wsdl: Metaforce.configuration.partner_wsdl,
endpoint: Metaforce.configuration.endpoint,
ssl_verify_mode: :none
)
end

# Internal: Usernamed passed in from options.
Expand Down
67 changes: 63 additions & 4 deletions lib/metaforce/metadata/client/crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module CRUD
# client._create(:apex_page, :full_name => 'TestPage', label: 'Test page', :content => '<apex:page>foobar</apex:page>')
def _create(type, metadata={})
type = type.to_s.camelize
request :create do |soap|
call :create do |soap|
soap.body = {
:metadata => prepare(metadata)
}.merge(attributes!(type))
Expand All @@ -25,7 +25,7 @@ def _create(type, metadata={})
def _delete(type, *args)
type = type.to_s.camelize
metadata = args.map { |full_name| {:full_name => full_name} }
request :delete do |soap|
call :delete do |soap|
soap.body = {
:metadata => metadata
}.merge(attributes!(type))
Expand All @@ -39,7 +39,7 @@ def _delete(type, *args)
# client._update(:apex_page, 'OldPage', :full_name => 'TestPage', :label => 'Test page', :content => '<apex:page>hello world</apex:page>')
def _update(type, current_name, metadata={})
type = type.to_s.camelize
request :update do |soap|
call :update do |soap|
soap.body = {
:metadata => {
:current_name => current_name,
Expand All @@ -50,6 +50,66 @@ def _update(type, current_name, metadata={})
end
end

# Adds one or more new metadata components to your organization
# synchronously.
#
# Available in API version 30.0 and later.
#
# Example: metadataResponse = client.create_metadata(:custom_object, :full_name => 'Test__c', :label => 'Test Object', :plural_label => 'Test Objects', :name_field => [:type => 'Text', :label => 'Test Name'], :deployment_status => 'Deployed', :sharing_model => 'ReadWrite')
def create_metadata(type, metadata={})
type = type.to_s.camelize
call(:create_metadata, message: { metadata: prepare(metadata) }.merge(attributes!(type)))
end

# Returns one or more metadata components from your organization
# synchronously.
#
# Available in API version 30.0 and later.
#
# Example: metadataResponse = client.read_metadata(:custom_object, ["Test__c"])
def read_metadata(type, fullNames)
type = type.to_s.camelize
call(:read_metadata, message: { type: type, full_names: fullNames })
end

# Updates one or more metadata components in your organization
# synchronously.
#
# Available in API version 30.0 and later.
#
# Example: metadataResponse = client.update_metadata(:profile, :fieldPermissions => [:field => 'Contact.'+get_namespace+'Test__c', :editable => true, :readable => true], :fullName => 'Admin')
def update_metadata(type, metadata={})
type = type.to_s.camelize
call(:update_metadata, message: { metadata: prepare(metadata) }.merge(attributes!(type)))
end

# Deletes one or more metadata components from your organization
# synchronously.
#
# Available in API version 30.0 and later.
#
# Example: metadataResponse = client.delete_metadata(:custom_object, ["Test__c"])
def delete_metadata(type, fullNames)
type = type.to_s.camelize
call(:delete_metadata, message: { type: type, full_names: fullNames })
end

# Renames a metadata component in your organization synchronously.
#
# Available in API version 30.0 and later.
#
# Example: metadataResponse = client.rename_metadata(:custom_object, 'Test__c', 'TestTest__c')
def rename_metadata(type, oldFullName, newFullName)
type = type.to_s.camelize
call :rename_metadata do |soap|
soap.body = {
:type => type,
:old_full_name => oldFullName,
:new_full_name => newFullName,
}
end
end

def create(*args)
Job::CRUD.new(self, :_create, args)
end
Expand Down Expand Up @@ -79,7 +139,6 @@ def prepare(metadata)
def encode_content(metadata)
metadata[:content] = Base64.encode64(metadata[:content]) if metadata.has_key?(:content)
end

end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/metaforce/metadata/client/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module File
# #=> ["ContractContactRole", "Solution", "Invoice_Statements__c", ... ]
def list_metadata(*args)
queries = args.map(&:to_s).map(&:camelize).map { |t| {:type => t} }
request :list_metadata do |soap|
call :list_metadata do |soap|
soap.body = { :queries => queries }
end
end
Expand All @@ -31,7 +31,7 @@ def list_metadata(*args)
# client.describe.metadata_objects.collect { |t| t.xml_name }
# #=> ["CustomLabels", "StaticResource", "Scontrol", "ApexComponent", ... ]
def describe(version=nil)
request :describe_metadata do |soap|
call :describe_metadata do |soap|
soap.body = { :api_version => version } unless version.nil?
end
end
Expand All @@ -49,7 +49,7 @@ def status(ids, type=nil)
method = :check_status
method = :"check_#{type}_status" if type
ids = [ids] unless ids.respond_to?(:each)
request method do |soap|
call method do |soap|
soap.body = { :ids => ids }
end
end
Expand All @@ -61,7 +61,7 @@ def status(ids, type=nil)
#
# Returns the AsyncResult
def _deploy(zip_file, options={})
request :deploy do |soap|
call :deploy do |soap|
soap.body = { :zip_file => zip_file, :deploy_options => options }
end
end
Expand All @@ -70,7 +70,7 @@ def _deploy(zip_file, options={})
#
# Returns the AsyncResult
def _retrieve(options={})
request :retrieve do |soap|
call :retrieve do |soap|
soap.body = { :retrieve_request => options }
end
end
Expand Down
21 changes: 9 additions & 12 deletions lib/metaforce/services/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class Client < Metaforce::AbstractClient
#
# Returns the result.
def send_email(options={})
request :send_email do |soap|
soap.body = {
:messages => options,
:attributes! => { 'ins0:messages' => { 'xsi:type' => 'ins0:SingleEmailMessage' } }
}
end
call(:send_email, message: {
messages: options,
attributes!: { 'ins0:messages' => { 'xsi:type' => 'ins0:SingleEmailMessage' } }
})
end

# Public: Retrieves layout information for the specified sobject.
Expand All @@ -37,10 +35,9 @@ def send_email(options={})
#
# Returns the layout metadata for the sobject.
def describe_layout(sobject, record_type_id=nil)
request :describe_layout do |soap|
soap.body = { 'sObjectType' => sobject }
soap.body.merge!('recordTypeID' => record_type_id) if record_type_id
end
message = { 'sObjectType' => sobject }
message = message.merge('recordTypeID' => record_type_id) if record_type_id
call(:describe_layout, message: message)
end

# Public: Get active picklists for a record type.
Expand Down Expand Up @@ -70,14 +67,14 @@ def inspect
#
# Example: client.services.send(:get_server_timestamp)
def get_server_timestamp
request :get_server_timestamp
call :get_server_timestamp
end

# Public: Retrieves personal information for the user associated
# with the current session.
# Example: client.services.send(:get_user_info)
def get_user_info
request :get_user_info
call :get_user_info
end
end
end
Expand Down
18 changes: 10 additions & 8 deletions metaforce.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ EOL
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ['lib']

s.add_dependency 'savon', '~> 1.2.0'
s.add_dependency 'rubyzip', '~> 1.0'
s.add_dependency 'savon', '~> 2'
s.add_dependency 'rubyzip', '~> 2'
s.add_dependency 'activesupport'
s.add_dependency 'hashie', '~> 1.2.0'
s.add_dependency 'thor', '~> 0.16.0'
s.add_dependency 'listen', '~> 0.6.0'
s.add_dependency 'rb-fsevent', '~> 0.9.1'
s.add_dependency 'hashie', '~> 4'
s.add_dependency 'thor'
s.add_dependency 'listen'
s.add_dependency 'rb-fsevent'

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2.14'
s.add_development_dependency 'rspec-its'
s.add_development_dependency 'rspec'

s.add_development_dependency 'webmock'
s.add_development_dependency 'savon_spec', '~> 1.3.0'
s.add_development_dependency 'savon_spec'
end
2 changes: 1 addition & 1 deletion spec/support/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shared_examples 'a client' do
describe 'when the session id expires' do
let(:exception) { Savon::SOAP::Fault.new(HTTPI::Response.new(403, {}, '')) }
let(:exception) { Savon::SOAPFault.new(HTTPI::Response.new(403, {}, '')) }

before do
client.send(:client).should_receive(:request).once.and_raise(exception)
Expand Down
Loading