Permalink
Browse files

Added the ability to set the rest_options from the service constructor

  • Loading branch information...
1 parent fe31e95 commit d41ab24c3ddce7a8ff0a2bf9991ebb0954e09a56 @visoft committed Feb 13, 2013
Showing with 28 additions and 1 deletion.
  1. +2 −1 CHANGELOG.md
  2. +1 −0 README.md
  3. +2 −0 lib/ruby_odata/service.rb
  4. +23 −0 spec/service_spec.rb
View
@@ -104,4 +104,5 @@
### 0.1.2
* New Features
* Added support for nokogiri >= 1.5.1 while maintaining backwards compatibility for >=1.4.2
- * Backports requirement is now for >= 2.3.0
+ * Backports requirement is now for >= 2.3.0
+ * Added the ability to pass in :rest_options to the service constructor within the options hash.
View
@@ -29,6 +29,7 @@ There are various options that you can pass when creating an instance of the ser
* username: username for http basic auth
* password: password for http basic auth
* verify_ssl: false if no verification, otherwise mode (OpenSSL::SSL::VERIFY_PEER is default)
+* rest_options: a hash of options that will be passed on to the rest-client calls. The passed in rest_options will be merged with the standard options that are set (username, password, and verify_ssl). This will allow you to set additional SSL settings. See [the rest-client docs](http://rubydoc.info/gems/rest-client/1.6.7/file/README.rdoc#SSL_Client_Certificates) for more information. Note, the options that you pass in will take precedence over the previous 3 options, so it is possible to set/override the username, password, and verify_ssl options directly with this hash.
* additional_params: a hash of query string params that will be passed on all calls (query, new, update, delete, batch)
* namespace: a string based namespace to create your objects in. You can specify the namespace using periods as separators (like .NET, for example `VisoftInc.Sample.Models`) or using double colons as separators (like Ruby `VisoftInc::Sample::Models`). By providing a namespace you can prevent naming collisions in your applications.
@@ -9,6 +9,7 @@ class Service
# @option options [String] :username for http basic auth
# @option options [String] :password for http basic auth
# @option options [Object] :verify_ssl false if no verification, otherwise mode (OpenSSL::SSL::VERIFY_PEER is default)
+ # @option options [Hash] :rest_options a hash of rest-client options that will be passed to all RestClient::Resource.new calls
# @option options [Hash] :additional_params a hash of query string params that will be passed on all calls
# @option options [Boolean, true] :eager_partial true if queries should consume partial feeds until the feed is complete, false if explicit calls to next must be performed
def initialize(service_uri, options = {})
@@ -172,6 +173,7 @@ def set_options!(options)
@options[:eager_partial] = true
end
@rest_options = { :verify_ssl => get_verify_mode, :user => @options[:username], :password => @options[:password] }
+ @rest_options.merge!(options[:rest_options] || {})
@additional_params = options[:additional_params] || {}
@namespace = options[:namespace]
end
View
@@ -36,6 +36,23 @@ module OData
a_request(:get, "http://test.com/test.svc/$metadata?x=1&y=2").should have_been_made
end
end
+
+ describe "rest-client options" do
+ before(:each) do
+ # Required for the build_classes method
+ stub_request(:get, /http:\/\/test\.com\/test\.svc\/\$metadata(?:\?.+)?/).
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/edmx_empty.xml", __FILE__)), :headers => {})
+ end
+ it "should accept in options that will be passed to the rest-client lib" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :rest_options => { :ssl_ca_file => "ca_certificate.pem" } }
+ svc.options[:rest_options].should eq Hash[:ssl_ca_file => "ca_certificate.pem"]
+ end
+ it "should merge the rest options with the built in options" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :rest_options => { :ssl_ca_file => "ca_certificate.pem" } }
+ svc.instance_variable_get(:@rest_options).should eq Hash[:verify_ssl => 1, :user => nil, :password => nil, :ssl_ca_file => "ca_certificate.pem"]
+ end
+ end
end
describe "additional query string parameters" do
before(:each) do
@@ -704,6 +721,12 @@ module OData
end
end
end
+
+ describe "restful options" do
+ it "should allow " do
+
+ end
+ end
end
describe_private OData::Service do

0 comments on commit d41ab24

Please sign in to comment.