class CloudElementsConnector
Public Class Methods
new(providerName, elementToken, base_url='https://console.cloud-elements.com/elements/api-v1/')
click to toggle source
# File lib/cloud_elements_connector.rb, line 70 def initialize(providerName, elementToken, base_url='https://console.cloud-elements.com/elements/api-v1/') apidocs = HTTMultiParty.get(base_url+providerName) if apidocs.has_key? 'errorMsg' raise APIException.new "Element Hub for #{providerName} does not exist" end method_data = [] method_count = 0 apidocs['apis'].each do |api| method_data[method_count] = Hash.new method_data[method_count][:elementToken] = elementToken method_data[method_count][:providerName] = providerName method_data[method_count][:apiMethodName] = api['path'].split('/')[-1] method_data[method_count][:httpMethod] = api['operations'][0]["httpMethod"].downcase() method_count = method_count + 1 end method_data.each do |data| define_singleton_method data[:apiMethodName] do |params=nil, files=nil| client = ElementsConnector.new return client.invoke(data[:httpMethod], data[:providerName], data[:elementToken], data[:apiMethodName], params, files) end end if self.respond_to? :ping response = self.ping if not response['success'] raise APIException.new response['errorMsg'] end end end