Sha256: e7bf5db6f527dad8d2b4a70657812bcee70971ea9a25c98420f004f20a712129
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
require 'savon' class MBService extend MBMeta #Sets up the service WSDL endpoint given a Mindbody service name def self.service(service_name) @@endpoint = self.wsdl_url(service_name) end attr_accessor :client, :src_creds, :usr_creds def initialize(options = {}) @client = nil @src_creds = options[:source_credentials] @usr_creds = options[:user_credentials] @client = Savon::Client.new @@endpoint if @@endpoint end #Builds the inner XML of the Mindbody SOAP call def build_request(options = {}) request_body = { "PageSize" => 10, "XMLDetail" => "Bare", "CurrentPageIndex" => 0 } request_body["SourceCredentials"] = @src_creds.to_hash if @src_creds request_body["UserCredentials"] = @usr_creds.to_hash if @usr_creds return request_body.deep_merge!(options) end #Build a Mindbody SOAP request for the given service def get_service(service_symbol, options) raise "No SOAP client instantiated" unless @client raise "No SourceCredentials supplied" if !@src_creds && !options[:source_credentials] response = @client.request MBMeta::NS, service_symbol do soap.body = { "Request" => build_request(options) } end end #Allows services to be called directly on the service and rerouted to #the client def method_missing(m_name, *args, &block) options = args[0] get_service m_name.to_sym, options.is_a?(Hash) ? options : {} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mindbody-0.0.1 | lib/mindbody/mb_service.rb |