Created
September 4, 2012 10:40
-
-
Save ffeldhaus/3619933 to your computer and use it in GitHub Desktop.
Diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/occi/api/client.rb b/lib/occi/api/client.rb | |
index 13875ff..59ca9af 100644 | |
--- a/lib/occi/api/client.rb | |
+++ b/lib/occi/api/client.rb | |
@@ -7,6 +7,7 @@ module OCCI | |
# HTTParty for raw HTTP requests | |
include HTTParty | |
+ debug_output $stderr | |
headers 'Accept' => 'application/occi+json,text/plain;q=0.5' | |
# a few attributes which should be visible outside the client | |
@@ -71,20 +72,28 @@ module OCCI | |
# @param [Hash] Logging options | |
# @param [Boolean] Enable autoconnect? | |
# @return [OCCI:Client] Client instance | |
- def initialize(endpoint = "http://localhost:3000/", auth_options = {:type => "none"}, log_options = { :out => STDERR, :level => Logger::WARN }, auto_connect = true) | |
+ def initialize(endpoint = "http://localhost:3000/", auth_options = {:type => "none"}, log_options = { :out => STDERR, :level => Logger::WARN }, auto_connect = true, media_type=nil) | |
# pass auth options to HTTParty | |
change_auth auth_options | |
# check the validity and canonize the endpoint URI | |
prepare_endpoint endpoint | |
+ # get accepted media types from HTTParty | |
+ set_media_type | |
+ | |
+ if media_type | |
+ self.class.headers 'Accept' => media_type | |
+ puts "Headers: #{self.class.headers}" | |
+ @media_type = media_type | |
+ end | |
+ | |
+ puts "Media Type: #{@media_type}" | |
+ | |
# get model information from the endpoint | |
# and create OCCI::Model instance | |
set_model | |
- # get accepted media types from HTTParty | |
- set_media_type | |
- | |
# set OCCI::Log | |
set_logger log_options | |
@@ -404,8 +413,7 @@ module OCCI | |
categories = filter.categories.collect { |category| category.to_text }.join(',') | |
attributes = filter.entities.collect { |entity| entity.attributes.combine.collect { |k, v| k + '=' + v } }.join(',') | |
self.class.get(@endpoint + path, | |
- :headers => { 'Accept' => 'application/occi+json,text/plain;q=0.5', | |
- 'Content-Type' => 'text/occi', | |
+ :headers => { 'Content-Type' => 'text/occi', | |
'Category' => categories, | |
'X-OCCI-Attributes' => attributes }) | |
else | |
@@ -449,9 +457,9 @@ module OCCI | |
def put(path, collection) | |
path = path.reverse.chomp('/').reverse | |
response = if @media_type == 'application/occi+json' | |
- self.class.post(@endpoint + path, :body => collection.to_json, :headers => { 'Accept' => 'application/occi+json,text/plain;q=0.5', 'Content-Type' => 'application/occi+json' }) | |
+ self.class.post(@endpoint + path, :body => collection.to_json, :headers => { 'Content-Type' => 'application/occi+json' }) | |
else | |
- self.class.post(@endpoint + path, { :body => collection.to_text, :headers => { 'Accept' => 'application/occi+json,text/plain;q=0.5', 'Content-Type' => 'text/plain' } }) | |
+ self.class.post(@endpoint + path, { :body => collection.to_text, :headers => { 'Content-Type' => 'text/plain' } }) | |
end | |
response_msg = response_message response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment