lib/google_apis/api/base/instance_methods.rb in google-apis-0.1.4 vs lib/google_apis/api/base/instance_methods.rb in google-apis-0.1.5

- old
+ new

@@ -9,19 +9,19 @@ config, params = options.symbolize_keys.partition{|(k, v)| [:email_address, :private_key].include?(k)}.collect{|x| Hash[x]} @connection = config.empty? ? GoogleApis.connection : GoogleApis::Connection.new(config) raise Error, "Please ensure a Google API connection" unless @connection - params = GoogleApis.config.merge(params).inject({}){|h, (k, v)| h[k.to_s.gsub(/_(.)/){$1.upcase}.to_sym] = v if v; h} + params = correct_params(GoogleApis.config.merge(params)) @discovered_api = connection.discover_api self.class.api, self.class.version @default_params = params.select{|k, v| self.class.default_parameters.include?(k)} end def execute(api_method, *params) - params[0] = (params[0] || {}).symbolize_keys - params[0].reverse_merge!(default_params) + params[0] = correct_params(params[0]) + params[0].reverse_merge! default_params(api_method) connection.execute self.class, api_method, *params end def download(uri, to = nil) connection.download self.class, uri, to @@ -39,11 +39,16 @@ end end private - def default_params - @default_params + def default_params(api_method = nil) + parameters = api_method.parameters.collect(&:to_sym) if api_method + parameters ? @default_params.slice(*parameters) : @default_params + end + + def correct_params(params) + params ? params.inject({}){|h, (k, v)| h[k.to_s.gsub(/_(.)/){$1.upcase}.to_sym] = v if v; h} : {} end def find(name) discovered_api.discovered_resources.detect{|x| x.name == name.to_s} end