forked from gojek/wrest
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding content type plain text support and serialise action for txt
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2009 Sidu Ponnappa | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License | ||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and limitations under the License. | ||
module Wrest | ||
module Components::Translators | ||
module Txt | ||
extend self | ||
|
||
def deserialise(response,options={}) | ||
response.body | ||
end | ||
|
||
def deserialize(response, options = {}) | ||
deserialise(response, options) | ||
end | ||
|
||
def serialise(hash, options = {}) | ||
hash.inspect | ||
end | ||
|
||
def serialize(hash, options = {}) | ||
serialise(hash, options) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "spec_helper" | ||
|
||
module Wrest::Components::Translators | ||
describe Txt do | ||
let(:http_response) { mock('Http Reponse') } | ||
it "should return response body when deserialise" do | ||
http_response.should_receive(:body).and_return("Homebrew is the easiest.") | ||
|
||
Txt.deserialise(http_response).should == "Homebrew is the easiest." | ||
end | ||
|
||
it "should return string version of any object when serialise" do | ||
Txt.serialise({"ooga"=>{"age" => "12"}}).should == "{\"ooga\"=>{\"age\"=>\"12\"}}" | ||
end | ||
|
||
it "has #deserialize delegate to #deserialise" do | ||
Txt.should_receive(:deserialise).with(http_response, :option => :something) | ||
Txt.deserialize(http_response, :option => :something) | ||
end | ||
|
||
it "has #serialize delegate to #serialise" do | ||
Txt.should_receive(:serialise).with({ :hash => :foo }, :option => :something) | ||
Txt.serialize({:hash => :foo}, :option => :something) | ||
end | ||
end | ||
end |