#160 - Add option to set encoding of response body
This commit is contained in:
1 parent
91ae01aa83
commit
fda7288859
5 files changed
+650
No files matched your search
@@ -23,6 +23,8 @@ require 'compat/multi_json'
|
||||
require 'signet/oauth_1/client'
|
||||
require 'google/api_client'
|
||||
|
||||
fixtures_path = File.expand_path('../../../fixtures', __FILE__)
|
||||
|
||||
RSpec.describe Google::APIClient do
|
||||
include ConnectionHelpers
|
||||
CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
|
||||
@@ -70,6 +72,15 @@ RSpec.describe Google::APIClient do
|
||||
expect(CLIENT.preferred_version('bogus')).to eq(nil)
|
||||
end
|
||||
|
||||
describe 'with zoo API' do
|
||||
it 'should return API instance registered from file' do
|
||||
zoo_json = File.join(fixtures_path, 'files', 'zoo.json')
|
||||
contents = File.open(zoo_json, 'rb') { |io| io.read }
|
||||
api = CLIENT.register_discovery_document('zoo', 'v1', contents)
|
||||
expect(api).to be_kind_of(Google::APIClient::API)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with the prediction API' do
|
||||
before do
|
||||
CLIENT.authorization = nil
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# Encoding: utf-8
|
||||
# Copyright 2012 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -20,6 +21,7 @@ RSpec.describe Google::APIClient::Gzip do
|
||||
|
||||
def create_connection(&block)
|
||||
Faraday.new do |b|
|
||||
b.response :charset
|
||||
b.response :gzip
|
||||
b.adapter :test do |stub|
|
||||
stub.get '/', &block
|
||||
@@ -43,6 +45,17 @@ RSpec.describe Google::APIClient::Gzip do
|
||||
expect(result.body).to eq("Hello world\n")
|
||||
end
|
||||
|
||||
it 'should inflate with the correct charset encoding' do
|
||||
conn = create_connection do |env|
|
||||
[200,
|
||||
{ 'Content-Encoding' => 'deflate', 'Content-Type' => 'application/json;charset=BIG5'},
|
||||
Base64.decode64('eJxb8nLp7t2VAA8fBCI=')]
|
||||
end
|
||||
result = conn.get('/')
|
||||
expect(result.body.encoding).to eq(Encoding::BIG5)
|
||||
expect(result.body).to eq('日本語'.encode("BIG5"))
|
||||
end
|
||||
|
||||
describe 'with API Client' do
|
||||
|
||||
before do
|
||||
|
||||
Reference in new issue
Block a user