mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Changing symbol syntax inside hashes - take 2
This commit is contained in:
parent
660abf5966
commit
5f9eedcfda
28 changed files with 259 additions and 259 deletions
|
@ -1,7 +1,7 @@
|
|||
rspec_options = {
|
||||
:version => 1,
|
||||
:all_after_pass => false,
|
||||
:all_on_start => false,
|
||||
version: 1,
|
||||
all_after_pass: false,
|
||||
all_on_start: false,
|
||||
}
|
||||
|
||||
guard 'rspec', rspec_options do
|
||||
|
|
2
History
2
History
|
@ -167,7 +167,7 @@
|
|||
|
||||
* minor enhancements
|
||||
* Timeout option added; will raise a Timeout::Error after the timeout has elapsed (attack). Closes #17
|
||||
HTTParty.get "http://github.com", :timeout => 1
|
||||
HTTParty.get "http://github.com", timeout: 1
|
||||
* Building gem with Jeweler
|
||||
|
||||
== 0.4.4 2009-07-19
|
||||
|
|
|
@ -28,7 +28,7 @@ class StackExchange
|
|||
base_uri 'api.stackexchange.com'
|
||||
|
||||
def initialize(service, page)
|
||||
@options = { :query => {:site => service, :page => page} }
|
||||
@options = { query: {site: service, page: page} }
|
||||
end
|
||||
|
||||
def questions
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -9,4 +9,4 @@ end
|
|||
require 'cucumber/rake/task'
|
||||
Cucumber::Rake::Task.new(:features)
|
||||
|
||||
task :default => [:spec, :features]
|
||||
task default: [:spec, :features]
|
||||
|
|
|
@ -7,9 +7,9 @@ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
|||
require "httparty"
|
||||
|
||||
opts = {
|
||||
:action => :get,
|
||||
:headers => {},
|
||||
:verbose => false
|
||||
action: :get,
|
||||
headers: {},
|
||||
verbose: false
|
||||
}
|
||||
|
||||
OptionParser.new do |o|
|
||||
|
@ -51,7 +51,7 @@ OptionParser.new do |o|
|
|||
o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
|
||||
abort "Invalid credentials format. Must be user:password" unless u =~ /.*:.+/
|
||||
user, password = u.split(':')
|
||||
opts[:basic_auth] = { :username => user, :password => password }
|
||||
opts[:basic_auth] = { username: user, password: password }
|
||||
end
|
||||
|
||||
o.on("-r", "--response-code", "Command fails if response code >= 400") do
|
||||
|
|
|
@ -16,11 +16,11 @@ class Partay
|
|||
end
|
||||
|
||||
options = {
|
||||
:body => {
|
||||
:pear => { # your resource
|
||||
:foo => '123', # your columns/data
|
||||
:bar => 'second',
|
||||
:baz => 'last thing'
|
||||
body: {
|
||||
pear: { # your resource
|
||||
foo: '123', # your columns/data
|
||||
bar: 'second',
|
||||
baz: 'last thing'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,4 @@ class Rep
|
|||
end
|
||||
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', :query => {:zip => 46544})
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: {zip: 46544})
|
||||
|
|
|
@ -8,16 +8,16 @@ class Delicious
|
|||
base_uri 'https://api.del.icio.us/v1'
|
||||
|
||||
def initialize(u, p)
|
||||
@auth = {:username => u, :password => p}
|
||||
@auth = {username: u, password: p}
|
||||
end
|
||||
|
||||
# query params that filter the posts are:
|
||||
# tag (optional). Filter by this tag.
|
||||
# dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
|
||||
# url (optional). Filter by this url.
|
||||
# ie: posts(:query => {:tag => 'ruby'})
|
||||
# ie: posts(query: {tag: 'ruby'})
|
||||
def posts(options={})
|
||||
options.merge!({:basic_auth => @auth})
|
||||
options.merge!({basic_auth: @auth})
|
||||
self.class.get('/posts/get', options)
|
||||
end
|
||||
|
||||
|
@ -25,13 +25,13 @@ class Delicious
|
|||
# tag (optional). Filter by this tag.
|
||||
# count (optional). Number of items to retrieve (Default:15, Maximum:100).
|
||||
def recent(options={})
|
||||
options.merge!({:basic_auth => @auth})
|
||||
options.merge!({basic_auth: @auth})
|
||||
self.class.get('/posts/recent', options)
|
||||
end
|
||||
end
|
||||
|
||||
delicious = Delicious.new(config['username'], config['password'])
|
||||
pp delicious.posts(:query => {:tag => 'ruby'})
|
||||
pp delicious.posts(query: {tag: 'ruby'})
|
||||
pp delicious.recent
|
||||
|
||||
delicious.recent['posts']['post'].each { |post| puts post['href'] }
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
require 'httparty'
|
||||
|
||||
APPLICATION_NAME = "Httparty"
|
||||
response = HTTParty.get('http://example.com', :headers => {"User-Agent" => APPLICATION_NAME})
|
||||
response = HTTParty.get('http://example.com', headers: {"User-Agent" => APPLICATION_NAME})
|
||||
|
|
|
@ -7,7 +7,7 @@ class Rubyurl
|
|||
base_uri 'rubyurl.com'
|
||||
|
||||
def self.shorten( website_url )
|
||||
post( '/api/links.json', :query => { :link => { :website_url => website_url } } )
|
||||
post( '/api/links.json', query: { link: { website_url: website_url } } )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,17 +11,17 @@ class TripIt
|
|||
response = self.class.get('/account/login')
|
||||
response = self.class.post(
|
||||
'/account/login',
|
||||
:body => {
|
||||
:login_email_address => email,
|
||||
:login_password => password
|
||||
body: {
|
||||
login_email_address: email,
|
||||
login_password: password
|
||||
},
|
||||
:headers => {'Cookie' => response.headers['Set-Cookie']}
|
||||
headers: {'Cookie' => response.headers['Set-Cookie']}
|
||||
)
|
||||
@cookie = response.request.options[:headers]['Cookie']
|
||||
end
|
||||
|
||||
def account_settings
|
||||
self.class.get('/account/edit', :headers => {'Cookie' => @cookie})
|
||||
self.class.get('/account/edit', headers: {'Cookie' => @cookie})
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
|
|
|
@ -8,24 +8,24 @@ class Twitter
|
|||
base_uri 'twitter.com'
|
||||
|
||||
def initialize(u, p)
|
||||
@auth = {:username => u, :password => p}
|
||||
@auth = {username: u, password: p}
|
||||
end
|
||||
|
||||
# which can be :friends, :user or :public
|
||||
# options[:query] can be things like since, since_id, count, etc.
|
||||
def timeline(which=:friends, options={})
|
||||
options.merge!({:basic_auth => @auth})
|
||||
options.merge!({basic_auth: @auth})
|
||||
self.class.get("/statuses/#{which}_timeline.json", options)
|
||||
end
|
||||
|
||||
def post(text)
|
||||
options = { :query => {:status => text}, :basic_auth => @auth }
|
||||
options = { query: {status: text}, basic_auth: @auth }
|
||||
self.class.post('/statuses/update.json', options)
|
||||
end
|
||||
end
|
||||
|
||||
twitter = Twitter.new(config['email'], config['password'])
|
||||
pp twitter.timeline
|
||||
# pp twitter.timeline(:friends, :query => {:since_id => 868482746})
|
||||
# pp twitter.timeline(:friends, :query => 'since_id=868482746')
|
||||
# pp twitter.timeline(:friends, query: {since_id: 868482746})
|
||||
# pp twitter.timeline(:friends, query: 'since_id=868482746')
|
||||
# pp twitter.post('this is a test of 0.2.0')
|
||||
|
|
|
@ -7,4 +7,4 @@ class Rep
|
|||
end
|
||||
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', :query => {:zip => 46544})
|
||||
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: {zip: 46544})
|
|
@ -30,7 +30,7 @@ When /I call HTTParty#get with '(.*)' and a basic_auth hash:/ do |url, auth_tabl
|
|||
h = auth_table.hashes.first
|
||||
@response_from_httparty = HTTParty.get(
|
||||
"http://#{@host_and_port}#{url}",
|
||||
:basic_auth => { :username => h["username"], :password => h["password"] }
|
||||
basic_auth: { username: h["username"], password: h["password"] }
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -38,6 +38,6 @@ When /I call HTTParty#get with '(.*)' and a digest_auth hash:/ do |url, auth_tab
|
|||
h = auth_table.hashes.first
|
||||
@response_from_httparty = HTTParty.get(
|
||||
"http://#{@host_and_port}#{url}",
|
||||
:digest_auth => { :username => h["username"], :password => h["password"] }
|
||||
digest_auth: { username: h["username"], password: h["password"] }
|
||||
)
|
||||
end
|
||||
|
|
|
@ -116,7 +116,7 @@ module HTTParty
|
|||
# basic_auth 'username', 'password'
|
||||
# end
|
||||
def basic_auth(u, p)
|
||||
default_options[:basic_auth] = {:username => u, :password => p}
|
||||
default_options[:basic_auth] = {username: u, password: p}
|
||||
end
|
||||
|
||||
# Allows setting digest authentication username and password.
|
||||
|
@ -126,14 +126,14 @@ module HTTParty
|
|||
# digest_auth 'username', 'password'
|
||||
# end
|
||||
def digest_auth(u, p)
|
||||
default_options[:digest_auth] = {:username => u, :password => p}
|
||||
default_options[:digest_auth] = {username: u, password: p}
|
||||
end
|
||||
|
||||
# Do not send rails style query strings.
|
||||
# Specically, don't use bracket notation when sending an array
|
||||
#
|
||||
# For a query:
|
||||
# get '/', :query => {:selected_ids => [1,2,3]}
|
||||
# get '/', query: {selected_ids: [1,2,3]}
|
||||
#
|
||||
# The default query string looks like this:
|
||||
# /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
||||
|
@ -156,7 +156,7 @@ module HTTParty
|
|||
#
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# default_params :api_key => 'secret', :another => 'foo'
|
||||
# default_params api_key: 'secret', another: 'foo'
|
||||
# end
|
||||
def default_params(h={})
|
||||
raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
|
||||
|
@ -320,7 +320,7 @@ module HTTParty
|
|||
# Helpful for overriding the default rails normalization of Array queries.
|
||||
#
|
||||
# For a query:
|
||||
# get '/', :query => {:selected_ids => [1,2,3]}
|
||||
# get '/', query: {selected_ids: [1,2,3]}
|
||||
#
|
||||
# The default query string normalizer returns:
|
||||
# /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
||||
|
@ -428,7 +428,7 @@ module HTTParty
|
|||
# @example provide optional configuration for your connection_adapter
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# connection_adapter Proc.new {|uri, options| ... }, {:foo => :bar}
|
||||
# connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}
|
||||
# end
|
||||
#
|
||||
# @see HTTParty::ConnectionAdapter
|
||||
|
@ -452,7 +452,7 @@ module HTTParty
|
|||
#
|
||||
# # Simple get with full url and query parameters
|
||||
# # ie: http://foo.com/resource.json?limit=10
|
||||
# Foo.get('http://foo.com/resource.json', :query => {:limit => 10})
|
||||
# Foo.get('http://foo.com/resource.json', query: {limit: 10})
|
||||
def get(path, options={}, &block)
|
||||
perform_request Net::HTTP::Get, path, options, &block
|
||||
end
|
||||
|
@ -464,11 +464,11 @@ module HTTParty
|
|||
# end
|
||||
#
|
||||
# # Simple post with full url and setting the body
|
||||
# Foo.post('http://foo.com/resources', :body => {:bar => 'baz'})
|
||||
# Foo.post('http://foo.com/resources', body: {bar: 'baz'})
|
||||
#
|
||||
# # Simple post with full url using :query option,
|
||||
# # which gets set as form data on the request.
|
||||
# Foo.post('http://foo.com/resources', :query => {:bar => 'baz'})
|
||||
# Foo.post('http://foo.com/resources', query: {bar: 'baz'})
|
||||
def post(path, options={}, &block)
|
||||
perform_request Net::HTTP::Post, path, options, &block
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ module HTTParty
|
|||
# @return <String> This hash as a query string
|
||||
#
|
||||
# @example
|
||||
# { :name => "Bob",
|
||||
# :address => {
|
||||
# :street => '111 Ruby Ave.',
|
||||
# :city => 'Ruby Central',
|
||||
# :phones => ['111-111-1111', '222-222-2222']
|
||||
# { name: "Bob",
|
||||
# address: {
|
||||
# street: '111 Ruby Ave.',
|
||||
# city: 'Ruby Central',
|
||||
# phones: ['111-111-1111', '222-222-2222']
|
||||
# }
|
||||
# }.to_params
|
||||
# #=> "name=Bob&address[city]=Ruby Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111 Ruby Ave."
|
||||
|
|
|
@ -33,12 +33,12 @@ module HTTParty
|
|||
self.http_method = http_method
|
||||
self.path = path
|
||||
self.options = {
|
||||
:limit => o.delete(:no_follow) ? 1 : 5,
|
||||
:assume_utf16_is_big_endian => true,
|
||||
:default_params => {},
|
||||
:follow_redirects => true,
|
||||
:parser => Parser,
|
||||
:connection_adapter => ConnectionAdapter
|
||||
limit: o.delete(:no_follow) ? 1 : 5,
|
||||
assume_utf16_is_big_endian: true,
|
||||
default_params: {},
|
||||
follow_redirects: true,
|
||||
parser: Parser,
|
||||
connection_adapter: ConnectionAdapter
|
||||
}.merge(o)
|
||||
end
|
||||
|
||||
|
@ -263,7 +263,7 @@ module HTTParty
|
|||
else
|
||||
body = body || last_response.body
|
||||
body = encode_body(body)
|
||||
Response.new(self, last_response, lambda { parse_response(body) }, :body => body)
|
||||
Response.new(self, last_response, lambda { parse_response(body) }, body: body)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
it "sets the options" do
|
||||
options = {:foo => :bar}
|
||||
options = {foo: :bar}
|
||||
adapter = HTTParty::ConnectionAdapter.new(uri, options)
|
||||
adapter.options.should be options
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
describe ".call" do
|
||||
it "generates an HTTParty::ConnectionAdapter instance with the given uri and options" do
|
||||
HTTParty::ConnectionAdapter.should_receive(:new).with(@uri, @options).and_return(stub(:connection => nil))
|
||||
HTTParty::ConnectionAdapter.should_receive(:new).with(@uri, @options).and_return(stub(connection: nil))
|
||||
HTTParty::ConnectionAdapter.call(@uri, @options)
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
adapter = mock('Adapter')
|
||||
connection = mock('Connection')
|
||||
adapter.should_receive(:connection).and_return(connection)
|
||||
HTTParty::ConnectionAdapter.stub(:new => adapter)
|
||||
HTTParty::ConnectionAdapter.stub(new: adapter)
|
||||
HTTParty::ConnectionAdapter.call(@uri, @options).should be connection
|
||||
end
|
||||
end
|
||||
|
@ -76,7 +76,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context "should use the specified cert store, when one is given" do
|
||||
let(:custom_cert_store) { mock('custom_cert_store') }
|
||||
let(:options) { {:cert_store => custom_cert_store} }
|
||||
let(:options) { {cert_store: custom_cert_store} }
|
||||
it { should use_cert_store(custom_cert_store) }
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
|
||||
context "when ssl version is set" do
|
||||
let(:options) { {:ssl_version => :TLSv1} }
|
||||
let(:options) { {ssl_version: :TLSv1} }
|
||||
|
||||
it "sets ssl version" do
|
||||
subject.ssl_version.should == :TLSv1
|
||||
|
@ -113,7 +113,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context "specifying ciphers" do
|
||||
let(:options) { {:ciphers => 'RC4-SHA' } }
|
||||
let(:options) { {ciphers: 'RC4-SHA' } }
|
||||
|
||||
it "should set the ciphers on the connection" do
|
||||
subject.ciphers.should == 'RC4-SHA'
|
||||
|
@ -122,10 +122,10 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context "when timeout is not set" do
|
||||
it "doesn't set the timeout" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_not_receive(:open_timeout=)
|
||||
http.should_not_receive(:read_timeout=)
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
|
||||
adapter.connection
|
||||
end
|
||||
|
@ -133,20 +133,20 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context "when setting timeout" do
|
||||
context "to 5 seconds" do
|
||||
let(:options) { {:timeout => 5} }
|
||||
let(:options) { {timeout: 5} }
|
||||
|
||||
its(:open_timeout) { should == 5 }
|
||||
its(:read_timeout) { should == 5 }
|
||||
end
|
||||
|
||||
context "and timeout is a string" do
|
||||
let(:options) { {:timeout => "five seconds"} }
|
||||
let(:options) { {timeout: "five seconds"} }
|
||||
|
||||
it "doesn't set the timeout" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_not_receive(:open_timeout=)
|
||||
http.should_not_receive(:read_timeout=)
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
|
||||
adapter.connection
|
||||
end
|
||||
|
@ -154,57 +154,57 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context "when timeout is not set and read_timeout is set to 6 seconds" do
|
||||
let(:options) { {:read_timeout => 6} }
|
||||
let(:options) { {read_timeout: 6} }
|
||||
|
||||
its(:read_timeout) { should == 6 }
|
||||
|
||||
it "should not set the open_timeout" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_not_receive(:open_timeout=)
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
|
||||
context "when timeout is set and read_timeout is set to 6 seconds" do
|
||||
let(:options) { {:timeout => 5, :read_timeout => 6} }
|
||||
let(:options) { {timeout: 5, read_timeout: 6} }
|
||||
|
||||
its(:open_timeout) { should == 5 }
|
||||
its(:read_timeout) { should == 6 }
|
||||
|
||||
it "should override the timeout option" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_receive(:open_timeout=)
|
||||
http.should_receive(:read_timeout=).twice
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
|
||||
context "when timeout is not set and open_timeout is set to 7 seconds" do
|
||||
let(:options) { {:open_timeout => 7} }
|
||||
let(:options) { {open_timeout: 7} }
|
||||
|
||||
its(:open_timeout) { should == 7 }
|
||||
|
||||
it "should not set the read_timeout" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_not_receive(:read_timeout=)
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
|
||||
context "when timeout is set and open_timeout is set to 7 seconds" do
|
||||
let(:options) { {:timeout => 5, :open_timeout => 7} }
|
||||
let(:options) { {timeout: 5, open_timeout: 7} }
|
||||
|
||||
its(:open_timeout) { should == 7 }
|
||||
its(:read_timeout) { should == 5 }
|
||||
|
||||
it "should override the timeout option" do
|
||||
http = mock("http", :null_object => true)
|
||||
http = mock("http", null_object: true)
|
||||
http.should_receive(:open_timeout=).twice
|
||||
http.should_receive(:read_timeout=)
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
|
@ -212,11 +212,11 @@ describe HTTParty::ConnectionAdapter do
|
|||
context "when debug_output" do
|
||||
let(:http) { Net::HTTP.new(uri) }
|
||||
before do
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
end
|
||||
|
||||
context "is set to $stderr" do
|
||||
let(:options) { {:debug_output => $stderr} }
|
||||
let(:options) { {debug_output: $stderr} }
|
||||
it "has debug output set" do
|
||||
http.should_receive(:set_debug_output).with($stderr)
|
||||
adapter.connection
|
||||
|
@ -232,7 +232,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context 'when providing proxy address and port' do
|
||||
let(:options) { {:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080} }
|
||||
let(:options) { {http_proxyaddr: '1.2.3.4', http_proxyport: 8080} }
|
||||
|
||||
it { should be_a_proxy }
|
||||
its(:proxy_address) { should == '1.2.3.4' }
|
||||
|
@ -240,8 +240,8 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context 'as well as proxy user and password' do
|
||||
let(:options) do
|
||||
{:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080,
|
||||
:http_proxyuser => 'user', :http_proxypass => 'pass'}
|
||||
{http_proxyaddr: '1.2.3.4', http_proxyport: 8080,
|
||||
http_proxyuser: 'user', http_proxypass: 'pass'}
|
||||
end
|
||||
its(:proxy_user) { should == 'user' }
|
||||
its(:proxy_pass) { should == 'pass' }
|
||||
|
@ -259,7 +259,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context 'when providing a local bind address and port' do
|
||||
let(:options) { {:local_host => "127.0.0.1", :local_port => 12345 } }
|
||||
let(:options) { {local_host: "127.0.0.1", local_port: 12345 } }
|
||||
|
||||
its(:local_host) { should == '127.0.0.1' }
|
||||
its(:local_port) { should == 12345 }
|
||||
|
@ -267,7 +267,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context "when providing PEM certificates" do
|
||||
let(:pem) { :pem_contents }
|
||||
let(:options) { {:pem => pem, :pem_password => "password"} }
|
||||
let(:options) { {pem: pem, pem_password: "password"} }
|
||||
|
||||
context "when scheme is https" do
|
||||
let(:uri) { URI 'https://google.com' }
|
||||
|
@ -289,7 +289,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context "when options include verify_peer=false" do
|
||||
let(:options) { {:pem => pem, :pem_password => "password", :verify_peer => false} }
|
||||
let(:options) { {pem: pem, pem_password: "password", verify_peer: false} }
|
||||
|
||||
it "should not verify the certificate" do
|
||||
subject.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
||||
|
@ -302,7 +302,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
let(:http) { Net::HTTP.new(uri) }
|
||||
|
||||
before do
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
OpenSSL::X509::Certificate.should_not_receive(:new).with(pem)
|
||||
OpenSSL::PKey::RSA.should_not_receive(:new).with(pem, "password")
|
||||
http.should_not_receive(:cert=)
|
||||
|
@ -318,11 +318,11 @@ describe HTTParty::ConnectionAdapter do
|
|||
|
||||
context "when providing PKCS12 certificates" do
|
||||
let(:p12) { :p12_contents }
|
||||
let(:options) { {:p12 => p12, :p12_password => "password"} }
|
||||
let(:options) { {p12: p12, p12_password: "password"} }
|
||||
|
||||
context "when scheme is https" do
|
||||
let(:uri) { URI 'https://google.com' }
|
||||
let(:pkcs12) { mock("OpenSSL::PKCS12", :certificate => cert, :key => key) }
|
||||
let(:pkcs12) { mock("OpenSSL::PKCS12", certificate: cert, key: key) }
|
||||
let(:cert) { mock("OpenSSL::X509::Certificate") }
|
||||
let(:key) { mock("OpenSSL::PKey::RSA") }
|
||||
|
||||
|
@ -340,7 +340,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
|
||||
context "when options include verify_peer=false" do
|
||||
let(:options) { {:p12 => p12, :p12_password => "password", :verify_peer => false} }
|
||||
let(:options) { {p12: p12, p12_password: "password", verify_peer: false} }
|
||||
|
||||
it "should not verify the certificate" do
|
||||
subject.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
||||
|
@ -353,7 +353,7 @@ describe HTTParty::ConnectionAdapter do
|
|||
let(:http) { Net::HTTP.new(uri) }
|
||||
|
||||
before do
|
||||
Net::HTTP.stub(:new => http)
|
||||
Net::HTTP.stub(new: http)
|
||||
OpenSSL::PKCS12.new.should_not_receive(:new).with(p12, "password")
|
||||
http.should_not_receive(:cert=)
|
||||
http.should_not_receive(:key=)
|
||||
|
|
|
@ -8,14 +8,14 @@ describe HTTParty::CookieHash do
|
|||
describe "#add_cookies" do
|
||||
describe "with a hash" do
|
||||
it "should add new key/value pairs to the hash" do
|
||||
@cookie_hash.add_cookies(:foo => "bar")
|
||||
@cookie_hash.add_cookies(:rofl => "copter")
|
||||
@cookie_hash.add_cookies(foo: "bar")
|
||||
@cookie_hash.add_cookies(rofl: "copter")
|
||||
@cookie_hash.length.should eql(2)
|
||||
end
|
||||
|
||||
it "should overwrite any existing key" do
|
||||
@cookie_hash.add_cookies(:foo => "bar")
|
||||
@cookie_hash.add_cookies(:foo => "copter")
|
||||
@cookie_hash.add_cookies(foo: "bar")
|
||||
@cookie_hash.add_cookies(foo: "copter")
|
||||
@cookie_hash.length.should eql(1)
|
||||
@cookie_hash[:foo].should eql("copter")
|
||||
end
|
||||
|
@ -57,8 +57,8 @@ describe HTTParty::CookieHash do
|
|||
# a hardcoded string was randomly failing.
|
||||
describe "#to_cookie_string" do
|
||||
before(:each) do
|
||||
@cookie_hash.add_cookies(:foo => "bar")
|
||||
@cookie_hash.add_cookies(:rofl => "copter")
|
||||
@cookie_hash.add_cookies(foo: "bar")
|
||||
@cookie_hash.add_cookies(rofl: "copter")
|
||||
@s = @cookie_hash.to_cookie_string
|
||||
end
|
||||
|
||||
|
@ -69,13 +69,13 @@ describe HTTParty::CookieHash do
|
|||
end
|
||||
|
||||
it "should not include client side only cookies" do
|
||||
@cookie_hash.add_cookies(:path => "/")
|
||||
@cookie_hash.add_cookies(path: "/")
|
||||
@s = @cookie_hash.to_cookie_string
|
||||
@s.should_not match(/path=\//)
|
||||
end
|
||||
|
||||
it "should not include client side only cookies even when attributes use camal case" do
|
||||
@cookie_hash.add_cookies(:Path => "/")
|
||||
@cookie_hash.add_cookies(Path: "/")
|
||||
@s = @cookie_hash.to_cookie_string
|
||||
@s.should_not match(/Path=\//)
|
||||
end
|
||||
|
|
|
@ -7,11 +7,11 @@ describe HTTParty::Logger::ApacheLogger do
|
|||
log_message = "[HTTParty] [#{request_time}] 302 \"GET http://my.domain.com/my_path\" - "
|
||||
|
||||
request_double = double(
|
||||
:http_method => Net::HTTP::Get,
|
||||
:path => "http://my.domain.com/my_path"
|
||||
http_method: Net::HTTP::Get,
|
||||
path: "http://my.domain.com/my_path"
|
||||
)
|
||||
response_double = double(
|
||||
:code => 302,
|
||||
code: 302,
|
||||
:[] => nil
|
||||
)
|
||||
|
||||
|
|
|
@ -9,14 +9,14 @@ describe HTTParty::Parser do
|
|||
|
||||
describe ".call" do
|
||||
it "generates an HTTParty::Parser instance with the given body and format" do
|
||||
HTTParty::Parser.should_receive(:new).with('body', :plain).and_return(stub(:parse => nil))
|
||||
HTTParty::Parser.should_receive(:new).with('body', :plain).and_return(stub(parse: nil))
|
||||
HTTParty::Parser.call('body', :plain)
|
||||
end
|
||||
|
||||
it "calls #parse on the parser" do
|
||||
parser = mock('Parser')
|
||||
parser.should_receive(:parse)
|
||||
HTTParty::Parser.stub(:new => parser)
|
||||
HTTParty::Parser.stub(new: parser)
|
||||
parser = HTTParty::Parser.call('body', :plain)
|
||||
end
|
||||
end
|
||||
|
@ -52,12 +52,12 @@ describe HTTParty::Parser do
|
|||
|
||||
describe ".supports_format?" do
|
||||
it "returns true for a supported format" do
|
||||
HTTParty::Parser.stub(:supported_formats => [:json])
|
||||
HTTParty::Parser.stub(supported_formats: [:json])
|
||||
HTTParty::Parser.supports_format?(:json).should be_true
|
||||
end
|
||||
|
||||
it "returns false for an unsupported format" do
|
||||
HTTParty::Parser.stub(:supported_formats => [])
|
||||
HTTParty::Parser.stub(supported_formats: [])
|
||||
HTTParty::Parser.supports_format?(:json).should be_false
|
||||
end
|
||||
end
|
||||
|
@ -68,33 +68,33 @@ describe HTTParty::Parser do
|
|||
end
|
||||
|
||||
it "attempts to parse supported formats" do
|
||||
@parser.stub(:supports_format? => true)
|
||||
@parser.stub(supports_format: true)
|
||||
@parser.should_receive(:parse_supported_format)
|
||||
@parser.parse
|
||||
end
|
||||
|
||||
it "returns the unparsed body when the format is unsupported" do
|
||||
@parser.stub(:supports_format? => false)
|
||||
@parser.stub(supports_format: false)
|
||||
@parser.parse.should == @parser.body
|
||||
end
|
||||
|
||||
it "returns nil for an empty body" do
|
||||
@parser.stub(:body => '')
|
||||
@parser.stub(body: '')
|
||||
@parser.parse.should be_nil
|
||||
end
|
||||
|
||||
it "returns nil for a nil body" do
|
||||
@parser.stub(:body => nil)
|
||||
@parser.stub(body: nil)
|
||||
@parser.parse.should be_nil
|
||||
end
|
||||
|
||||
it "returns nil for a 'null' body" do
|
||||
@parser.stub(:body => "null")
|
||||
@parser.stub(body: "null")
|
||||
@parser.parse.should be_nil
|
||||
end
|
||||
|
||||
it "returns nil for a body with spaces only" do
|
||||
@parser.stub(:body => " ")
|
||||
@parser.stub(body: " ")
|
||||
@parser.parse.should be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|||
|
||||
describe HTTParty::Request do
|
||||
before do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml)
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml)
|
||||
end
|
||||
|
||||
describe "::NON_RAILS_QUERY_STRING_NORMALIZER" do
|
||||
|
@ -16,19 +16,19 @@ describe HTTParty::Request do
|
|||
context "when the query is an array" do
|
||||
|
||||
it "doesn't include brackets" do
|
||||
query_string = normalizer[{:page => 1, :foo => %w(bar baz)}]
|
||||
query_string = normalizer[{page: 1, foo: %w(bar baz)}]
|
||||
URI.unescape(query_string).should == "foo=bar&foo=baz&page=1"
|
||||
end
|
||||
|
||||
it "URI encodes array values" do
|
||||
query_string = normalizer[{:people => ["Otis Redding", "Bob Marley", "Tim & Jon"], :page => 1, :xyzzy => 3}]
|
||||
query_string = normalizer[{people: ["Otis Redding", "Bob Marley", "Tim & Jon"], page: 1, xyzzy: 3}]
|
||||
query_string.should == "page=1&people=Otis%20Redding&people=Bob%20Marley&people=Tim%20%26%20Jon&xyzzy=3"
|
||||
end
|
||||
end
|
||||
|
||||
context "when the query is a hash" do
|
||||
it "correctly handles nil values" do
|
||||
query_string = normalizer[{:page => 1, :per_page => nil}]
|
||||
query_string = normalizer[{page: 1, per_page: nil}]
|
||||
query_string.should == "page=1&per_page"
|
||||
end
|
||||
end
|
||||
|
@ -42,7 +42,7 @@ describe HTTParty::Request do
|
|||
|
||||
it "sets parser to the optional parser" do
|
||||
my_parser = lambda {}
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', :parser => my_parser)
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', parser: my_parser)
|
||||
request.parser.should == my_parser
|
||||
end
|
||||
|
||||
|
@ -53,7 +53,7 @@ describe HTTParty::Request do
|
|||
|
||||
it "sets connection_adapter to the optional connection_adapter" do
|
||||
my_adapter = lambda {}
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', :connection_adapter => my_adapter)
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', connection_adapter: my_adapter)
|
||||
request.connection_adapter.should == my_adapter
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ describe HTTParty::Request do
|
|||
describe "#format" do
|
||||
context "request yet to be made" do
|
||||
it "returns format option" do
|
||||
request = HTTParty::Request.new 'get', '/', :format => :xml
|
||||
request = HTTParty::Request.new 'get', '/', format: :xml
|
||||
request.format.should == :xml
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ describe HTTParty::Request do
|
|||
|
||||
context "request has been made" do
|
||||
it "returns format option" do
|
||||
request = HTTParty::Request.new 'get', '/', :format => :xml
|
||||
request = HTTParty::Request.new 'get', '/', format: :xml
|
||||
request.last_response = stub
|
||||
request.format.should == :xml
|
||||
end
|
||||
|
@ -91,16 +91,16 @@ describe HTTParty::Request do
|
|||
|
||||
context "options" do
|
||||
it "should use basic auth when configured" do
|
||||
@request.options[:basic_auth] = {:username => 'foobar', :password => 'secret'}
|
||||
@request.options[:basic_auth] = {username: 'foobar', password: 'secret'}
|
||||
@request.send(:setup_raw_request)
|
||||
@request.instance_variable_get(:@raw_request)['authorization'].should_not be_nil
|
||||
end
|
||||
|
||||
it "should use digest auth when configured" do
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v1",
|
||||
:www_authenticate => 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
|
||||
www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
|
||||
|
||||
@request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
|
||||
@request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
|
||||
@request.send(:setup_raw_request)
|
||||
|
||||
raw_request = @request.instance_variable_get(:@raw_request)
|
||||
|
@ -108,13 +108,13 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "should use the right http method for digest authentication" do
|
||||
@post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml)
|
||||
@post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', format: :xml)
|
||||
FakeWeb.register_uri(:post, "http://api.foo.com/v1", {})
|
||||
|
||||
http = @post_request.send(:http)
|
||||
@post_request.should_receive(:http).and_return(http)
|
||||
http.should_not_receive(:head).and_return({'www-authenticate' => nil})
|
||||
@post_request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
|
||||
@post_request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
|
||||
@post_request.send(:setup_raw_request)
|
||||
end
|
||||
|
||||
|
@ -136,7 +136,7 @@ describe HTTParty::Request do
|
|||
it "respects the query string normalization proc" do
|
||||
empty_proc = lambda {|qs| ""}
|
||||
@request.options[:query_string_normalizer] = empty_proc
|
||||
@request.options[:query] = {:foo => :bar}
|
||||
@request.options[:query] = {foo: :bar}
|
||||
URI.unescape(@request.uri.query).should == ""
|
||||
end
|
||||
|
||||
|
@ -147,14 +147,14 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "does not duplicate query string parameters when uri is called twice" do
|
||||
@request.options[:query] = {:foo => :bar}
|
||||
@request.options[:query] = {foo: :bar}
|
||||
@request.uri
|
||||
@request.uri.query.should == "foo=bar"
|
||||
end
|
||||
|
||||
context "when representing an array" do
|
||||
it "returns a Rails style query string" do
|
||||
@request.options[:query] = {:foo => %w(bar baz)}
|
||||
@request.options[:query] = {foo: %w(bar baz)}
|
||||
URI.unescape(@request.uri.query).should == "foo[]=bar&foo[]=baz"
|
||||
end
|
||||
end
|
||||
|
@ -166,7 +166,7 @@ describe HTTParty::Request do
|
|||
context "when query_string_normalizer is set" do
|
||||
it "sets the body to the return value of the proc" do
|
||||
@request.options[:query_string_normalizer] = HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER
|
||||
@request.options[:body] = {:page => 1, :foo => %w(bar baz)}
|
||||
@request.options[:body] = {page: 1, foo: %w(bar baz)}
|
||||
@request.send(:setup_raw_request)
|
||||
body = @request.instance_variable_get(:@raw_request).body
|
||||
URI.unescape(body).should == "foo=bar&foo=baz&page=1"
|
||||
|
@ -178,7 +178,7 @@ describe HTTParty::Request do
|
|||
it "should get a connection from the connection_adapter" do
|
||||
http = Net::HTTP.new('google.com')
|
||||
adapter = mock('adapter')
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'https://api.foo.com/v1:443', :connection_adapter => adapter)
|
||||
request = HTTParty::Request.new(Net::HTTP::Get, 'https://api.foo.com/v1:443', connection_adapter: adapter)
|
||||
adapter.should_receive(:call).with(request.uri, request.options).and_return(http)
|
||||
request.send(:http).should be http
|
||||
end
|
||||
|
@ -371,9 +371,9 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "calls block given to perform with each redirect" do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
|
||||
FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v2", :body => "<hash><foo>bar</foo></hash>")
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
|
||||
FakeWeb.register_uri(:get, "http://test.com/redirect", status: [300, "REDIRECT"], location: "http://api.foo.com/v2")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v2", body: "<hash><foo>bar</foo></hash>")
|
||||
body = ""
|
||||
response = @request.perform { |chunk| body += chunk }
|
||||
body.length.should == 27
|
||||
|
@ -393,10 +393,10 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "handles multiple redirects and relative location headers on different hosts" do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
|
||||
FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v2", :status => [300, "REDIRECT"], :location => "/v3")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v3", :body => "<hash><foo>bar</foo></hash>")
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
|
||||
FakeWeb.register_uri(:get, "http://test.com/redirect", status: [300, "REDIRECT"], location: "http://api.foo.com/v2")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v2", status: [300, "REDIRECT"], location: "/v3")
|
||||
FakeWeb.register_uri(:get, "http://api.foo.com/v3", body: "<hash><foo>bar</foo></hash>")
|
||||
response = @request.perform
|
||||
response.request.base_uri.to_s.should == "http://api.foo.com"
|
||||
response.request.path.to_s.should == "/v3"
|
||||
|
@ -611,7 +611,7 @@ describe HTTParty::Request do
|
|||
context "with POST http method" do
|
||||
it "should raise argument error if query is not a hash" do
|
||||
lambda {
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml, :query => 'astring').perform
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', format: :xml, query: 'astring').perform
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
@ -619,19 +619,19 @@ describe HTTParty::Request do
|
|||
describe "argument validation" do
|
||||
it "should raise argument error if basic_auth and digest_auth are both present" do
|
||||
lambda {
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :basic_auth => {}, :digest_auth => {}).perform
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', basic_auth: {}, digest_auth: {}).perform
|
||||
}.should raise_error(ArgumentError, "only one authentication method, :basic_auth or :digest_auth may be used at a time")
|
||||
end
|
||||
|
||||
it "should raise argument error if basic_auth is not a hash" do
|
||||
lambda {
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :basic_auth => ["foo", "bar"]).perform
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', basic_auth: ["foo", "bar"]).perform
|
||||
}.should raise_error(ArgumentError, ":basic_auth must be a hash")
|
||||
end
|
||||
|
||||
it "should raise argument error if digest_auth is not a hash" do
|
||||
lambda {
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :digest_auth => ["foo", "bar"]).perform
|
||||
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', digest_auth: ["foo", "bar"]).perform
|
||||
}.should raise_error(ArgumentError, ":digest_auth must be a hash")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe HTTParty::Response do
|
|||
@content_length = '1024'
|
||||
@request_object = HTTParty::Request.new Net::HTTP::Get, '/'
|
||||
@response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
||||
@response_object.stub(:body => "{foo:'bar'}")
|
||||
@response_object.stub(body: "{foo:'bar'}")
|
||||
@response_object['last-modified'] = @last_modified
|
||||
@response_object['content-length'] = @content_length
|
||||
@parsed_response = lambda { {"foo" => "bar"} }
|
||||
|
@ -155,46 +155,46 @@ describe HTTParty::Response do
|
|||
|
||||
context "for specific codes" do
|
||||
SPECIFIC_CODES = {
|
||||
:accepted? => Net::HTTPAccepted,
|
||||
:bad_gateway? => Net::HTTPBadGateway,
|
||||
:bad_request? => Net::HTTPBadRequest,
|
||||
:conflict? => Net::HTTPConflict,
|
||||
:continue? => Net::HTTPContinue,
|
||||
:created? => Net::HTTPCreated,
|
||||
:expectation_failed? => Net::HTTPExpectationFailed,
|
||||
:forbidden? => Net::HTTPForbidden,
|
||||
:found? => Net::HTTPFound,
|
||||
:gateway_time_out? => Net::HTTPGatewayTimeOut,
|
||||
:gone? => Net::HTTPGone,
|
||||
:internal_server_error? => Net::HTTPInternalServerError,
|
||||
:length_required? => Net::HTTPLengthRequired,
|
||||
:method_not_allowed? => Net::HTTPMethodNotAllowed,
|
||||
:moved_permanently? => Net::HTTPMovedPermanently,
|
||||
:multiple_choice? => Net::HTTPMultipleChoice,
|
||||
:no_content? => Net::HTTPNoContent,
|
||||
:non_authoritative_information? => Net::HTTPNonAuthoritativeInformation,
|
||||
:not_acceptable? => Net::HTTPNotAcceptable,
|
||||
:not_found? => Net::HTTPNotFound,
|
||||
:not_implemented? => Net::HTTPNotImplemented,
|
||||
:not_modified? => Net::HTTPNotModified,
|
||||
:ok? => Net::HTTPOK,
|
||||
:partial_content? => Net::HTTPPartialContent,
|
||||
:payment_required? => Net::HTTPPaymentRequired,
|
||||
:precondition_failed? => Net::HTTPPreconditionFailed,
|
||||
:proxy_authentication_required? => Net::HTTPProxyAuthenticationRequired,
|
||||
:request_entity_too_large? => Net::HTTPRequestEntityTooLarge,
|
||||
:request_time_out? => Net::HTTPRequestTimeOut,
|
||||
:request_uri_too_long? => Net::HTTPRequestURITooLong,
|
||||
:requested_range_not_satisfiable? => Net::HTTPRequestedRangeNotSatisfiable,
|
||||
:reset_content? => Net::HTTPResetContent,
|
||||
:see_other? => Net::HTTPSeeOther,
|
||||
:service_unavailable? => Net::HTTPServiceUnavailable,
|
||||
:switch_protocol? => Net::HTTPSwitchProtocol,
|
||||
:temporary_redirect? => Net::HTTPTemporaryRedirect,
|
||||
:unauthorized? => Net::HTTPUnauthorized,
|
||||
:unsupported_media_type? => Net::HTTPUnsupportedMediaType,
|
||||
:use_proxy? => Net::HTTPUseProxy,
|
||||
:version_not_supported? => Net::HTTPVersionNotSupported
|
||||
accepted: Net::HTTPAccepted,
|
||||
bad_gateway: Net::HTTPBadGateway,
|
||||
bad_request: Net::HTTPBadRequest,
|
||||
conflict: Net::HTTPConflict,
|
||||
continue: Net::HTTPContinue,
|
||||
created: Net::HTTPCreated,
|
||||
expectation_failed: Net::HTTPExpectationFailed,
|
||||
forbidden: Net::HTTPForbidden,
|
||||
found: Net::HTTPFound,
|
||||
gateway_time_out: Net::HTTPGatewayTimeOut,
|
||||
gone: Net::HTTPGone,
|
||||
internal_server_error: Net::HTTPInternalServerError,
|
||||
length_required: Net::HTTPLengthRequired,
|
||||
method_not_allowed: Net::HTTPMethodNotAllowed,
|
||||
moved_permanently: Net::HTTPMovedPermanently,
|
||||
multiple_choice: Net::HTTPMultipleChoice,
|
||||
no_content: Net::HTTPNoContent,
|
||||
non_authoritative_information: Net::HTTPNonAuthoritativeInformation,
|
||||
not_acceptable: Net::HTTPNotAcceptable,
|
||||
not_found: Net::HTTPNotFound,
|
||||
not_implemented: Net::HTTPNotImplemented,
|
||||
not_modified: Net::HTTPNotModified,
|
||||
ok: Net::HTTPOK,
|
||||
partial_content: Net::HTTPPartialContent,
|
||||
payment_required: Net::HTTPPaymentRequired,
|
||||
precondition_failed: Net::HTTPPreconditionFailed,
|
||||
proxy_authentication_required: Net::HTTPProxyAuthenticationRequired,
|
||||
request_entity_too_large: Net::HTTPRequestEntityTooLarge,
|
||||
request_time_out: Net::HTTPRequestTimeOut,
|
||||
request_uri_too_long: Net::HTTPRequestURITooLong,
|
||||
requested_range_not_satisfiable: Net::HTTPRequestedRangeNotSatisfiable,
|
||||
reset_content: Net::HTTPResetContent,
|
||||
see_other: Net::HTTPSeeOther,
|
||||
service_unavailable: Net::HTTPServiceUnavailable,
|
||||
switch_protocol: Net::HTTPSwitchProtocol,
|
||||
temporary_redirect: Net::HTTPTemporaryRedirect,
|
||||
unauthorized: Net::HTTPUnauthorized,
|
||||
unsupported_media_type: Net::HTTPUnsupportedMediaType,
|
||||
use_proxy: Net::HTTPUseProxy,
|
||||
version_not_supported: Net::HTTPVersionNotSupported
|
||||
}
|
||||
|
||||
# Ruby 2.0, new name for this response.
|
||||
|
|
|
@ -17,7 +17,7 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "should work when no trusted CA list is specified, when the verify option is set to false" do
|
||||
ssl_verify_test(nil, nil, "selfsigned.crt", :verify => false).should == {'success' => true}
|
||||
ssl_verify_test(nil, nil, "selfsigned.crt", verify: false).should == {'success' => true}
|
||||
end
|
||||
|
||||
it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do
|
||||
|
@ -27,7 +27,7 @@ describe HTTParty::Request do
|
|||
end
|
||||
|
||||
it "should work when no trusted CA list is specified, even with a bogus hostname, when the verify option is set to true" do
|
||||
ssl_verify_test(nil, nil, "bogushost.crt", :verify => false).should == {'success' => true}
|
||||
ssl_verify_test(nil, nil, "bogushost.crt", verify: false).should == {'success' => true}
|
||||
end
|
||||
|
||||
it "should work when using ssl_ca_file with a self-signed CA" do
|
||||
|
@ -40,11 +40,11 @@ describe HTTParty::Request do
|
|||
|
||||
it "should work when using ssl_ca_path with a certificate authority" do
|
||||
http = Net::HTTP.new('www.google.com', 443)
|
||||
response = stub(Net::HTTPResponse, :[] => '', :body => '', :to_hash => {})
|
||||
response = stub(Net::HTTPResponse, :[] => '', body: '', to_hash: {})
|
||||
http.stub(:request).and_return(response)
|
||||
Net::HTTP.should_receive(:new).with('www.google.com', 443).and_return(http)
|
||||
http.should_receive(:ca_path=).with('/foo/bar')
|
||||
HTTParty.get('https://www.google.com', :ssl_ca_path => '/foo/bar')
|
||||
HTTParty.get('https://www.google.com', ssl_ca_path: '/foo/bar')
|
||||
end
|
||||
|
||||
it "should fail when using ssl_ca_file and the server uses an unrecognized certificate authority" do
|
||||
|
|
|
@ -140,8 +140,8 @@ describe HTTParty do
|
|||
describe "headers" do
|
||||
def expect_headers(header={})
|
||||
HTTParty::Request.should_receive(:new) \
|
||||
.with(anything, anything, hash_including({ :headers => header })) \
|
||||
.and_return(mock("mock response", :perform => nil))
|
||||
.with(anything, anything, hash_including({ headers: header })) \
|
||||
.and_return(mock("mock response", perform: nil))
|
||||
end
|
||||
|
||||
it "should default to empty hash" do
|
||||
|
@ -149,46 +149,46 @@ describe HTTParty do
|
|||
end
|
||||
|
||||
it "should be able to be updated" do
|
||||
init_headers = {:foo => 'bar', :baz => 'spax'}
|
||||
init_headers = {foo: 'bar', baz: 'spax'}
|
||||
@klass.headers init_headers
|
||||
@klass.headers.should == init_headers
|
||||
end
|
||||
|
||||
it "uses the class headers when sending a request" do
|
||||
expect_headers(:foo => 'bar')
|
||||
@klass.headers(:foo => 'bar')
|
||||
expect_headers(foo: 'bar')
|
||||
@klass.headers(foo: 'bar')
|
||||
@klass.get('')
|
||||
end
|
||||
|
||||
it "merges class headers with request headers" do
|
||||
expect_headers(:baz => 'spax', :foo => 'bar')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.get('', :headers => {:baz => 'spax'})
|
||||
expect_headers(baz: 'spax', foo: 'bar')
|
||||
@klass.headers(foo: 'bar')
|
||||
@klass.get('', headers: {baz: 'spax'})
|
||||
end
|
||||
|
||||
it 'overrides class headers with request headers' do
|
||||
expect_headers(:baz => 'spax', :foo => 'baz')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.get('', :headers => {:baz => 'spax', :foo => 'baz'})
|
||||
expect_headers(baz: 'spax', foo: 'baz')
|
||||
@klass.headers(foo: 'bar')
|
||||
@klass.get('', headers: {baz: 'spax', foo: 'baz'})
|
||||
end
|
||||
|
||||
context "with cookies" do
|
||||
it 'utilizes the class-level cookies' do
|
||||
expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.cookies(:type => 'snickerdoodle')
|
||||
expect_headers(foo: 'bar', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.headers(foo: 'bar')
|
||||
@klass.cookies(type: 'snickerdoodle')
|
||||
@klass.get('')
|
||||
end
|
||||
|
||||
it 'adds cookies to the headers' do
|
||||
expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.get('', :cookies => {:type => 'snickerdoodle'})
|
||||
expect_headers(foo: 'bar', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.headers(foo: 'bar')
|
||||
@klass.get('', cookies: {type: 'snickerdoodle'})
|
||||
end
|
||||
|
||||
it 'adds optional cookies to the optional headers' do
|
||||
expect_headers(:baz => 'spax', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.get('', :cookies => {:type => 'snickerdoodle'}, :headers => {:baz => 'spax'})
|
||||
expect_headers(baz: 'spax', 'cookie' => 'type=snickerdoodle')
|
||||
@klass.get('', cookies: {type: 'snickerdoodle'}, headers: {baz: 'spax'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -196,12 +196,12 @@ describe HTTParty do
|
|||
describe "cookies" do
|
||||
def expect_cookie_header(s)
|
||||
HTTParty::Request.should_receive(:new) \
|
||||
.with(anything, anything, hash_including({ :headers => { "cookie" => s } })) \
|
||||
.and_return(mock("mock response", :perform => nil))
|
||||
.with(anything, anything, hash_including({ headers: { "cookie" => s } })) \
|
||||
.and_return(mock("mock response", perform: nil))
|
||||
end
|
||||
|
||||
it "should not be in the headers by default" do
|
||||
HTTParty::Request.stub!(:new).and_return(stub(nil, :perform => nil))
|
||||
HTTParty::Request.stub!(:new).and_return(stub(nil, perform: nil))
|
||||
@klass.get("")
|
||||
@klass.headers.keys.should_not include("cookie")
|
||||
end
|
||||
|
@ -214,12 +214,12 @@ describe HTTParty do
|
|||
|
||||
it "should allow a cookie to be specified with a one-off request" do
|
||||
expect_cookie_header "type=snickerdoodle"
|
||||
@klass.get("", :cookies => { :type => "snickerdoodle" })
|
||||
@klass.get("", cookies: { type: "snickerdoodle" })
|
||||
end
|
||||
|
||||
describe "when a cookie is set at the class level" do
|
||||
before(:each) do
|
||||
@klass.cookies({ :type => "snickerdoodle" })
|
||||
@klass.cookies({ type: "snickerdoodle" })
|
||||
end
|
||||
|
||||
it "should include that cookie in the request" do
|
||||
|
@ -237,7 +237,7 @@ describe HTTParty do
|
|||
it "should allow the class defaults to be overridden" do
|
||||
expect_cookie_header "type=chocolate_chip"
|
||||
|
||||
@klass.get("", :cookies => { :type => "chocolate_chip" })
|
||||
@klass.get("", cookies: { type: "chocolate_chip" })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -245,11 +245,11 @@ describe HTTParty do
|
|||
before(:each) do
|
||||
@klass.instance_eval do
|
||||
def first_method
|
||||
get("first_method", :cookies => { :first_method_cookie => "foo" })
|
||||
get("first_method", cookies: { first_method_cookie: "foo" })
|
||||
end
|
||||
|
||||
def second_method
|
||||
get("second_method", :cookies => { :second_method_cookie => "foo" })
|
||||
get("second_method", cookies: { second_method_cookie: "foo" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -270,7 +270,7 @@ describe HTTParty do
|
|||
end
|
||||
|
||||
it "should be able to be updated" do
|
||||
new_defaults = {:foo => 'bar', :baz => 'spax'}
|
||||
new_defaults = {foo: 'bar', baz: 'spax'}
|
||||
@klass.default_params new_defaults
|
||||
@klass.default_params.should == new_defaults
|
||||
end
|
||||
|
@ -307,21 +307,21 @@ describe HTTParty do
|
|||
describe "basic http authentication" do
|
||||
it "should work" do
|
||||
@klass.basic_auth 'foobar', 'secret'
|
||||
@klass.default_options[:basic_auth].should == {:username => 'foobar', :password => 'secret'}
|
||||
@klass.default_options[:basic_auth].should == {username: 'foobar', password: 'secret'}
|
||||
end
|
||||
end
|
||||
|
||||
describe "digest http authentication" do
|
||||
it "should work" do
|
||||
@klass.digest_auth 'foobar', 'secret'
|
||||
@klass.default_options[:digest_auth].should == {:username => 'foobar', :password => 'secret'}
|
||||
@klass.default_options[:digest_auth].should == {username: 'foobar', password: 'secret'}
|
||||
end
|
||||
end
|
||||
|
||||
describe "parser" do
|
||||
class CustomParser
|
||||
def self.parse(body)
|
||||
return {:sexy => true}
|
||||
return {sexy: true}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -336,7 +336,7 @@ describe HTTParty do
|
|||
|
||||
it "should be able parse response with custom parser" do
|
||||
@klass.parser parser
|
||||
FakeWeb.register_uri(:get, 'http://twitter.com/statuses/public_timeline.xml', :body => 'tweets')
|
||||
FakeWeb.register_uri(:get, 'http://twitter.com/statuses/public_timeline.xml', body: 'tweets')
|
||||
custom_parsed_response = @klass.get('http://twitter.com/statuses/public_timeline.xml')
|
||||
custom_parsed_response[:sexy].should == true
|
||||
end
|
||||
|
@ -369,7 +369,7 @@ describe HTTParty do
|
|||
end
|
||||
|
||||
it "should set the connection_adapter_options when provided" do
|
||||
options = {:foo => :bar}
|
||||
options = {foo: :bar}
|
||||
@klass.connection_adapter connection_adapter, options
|
||||
@klass.default_options[:connection_adapter_options].should be options
|
||||
end
|
||||
|
@ -380,12 +380,12 @@ describe HTTParty do
|
|||
end
|
||||
|
||||
it "should process a request with a connection from the adapter" do
|
||||
connection_adapter_options = {:foo => :bar}
|
||||
connection_adapter_options = {foo: :bar}
|
||||
connection_adapter.should_receive(:call) do |u,o|
|
||||
o[:connection_adapter_options].should == connection_adapter_options
|
||||
HTTParty::ConnectionAdapter.call(u,o)
|
||||
end.with(URI.parse(uri), kind_of(Hash))
|
||||
FakeWeb.register_uri(:get, uri, :body => 'stuff')
|
||||
FakeWeb.register_uri(:get, uri, body: 'stuff')
|
||||
@klass.connection_adapter connection_adapter, connection_adapter_options
|
||||
@klass.get(uri).should == 'stuff'
|
||||
end
|
||||
|
@ -484,63 +484,63 @@ describe HTTParty do
|
|||
|
||||
describe "with explicit override of automatic redirect handling" do
|
||||
before do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml, :no_follow => true)
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml, no_follow: true)
|
||||
@redirect = stub_response 'first redirect', 302
|
||||
@redirect['location'] = 'http://foo.com/bar'
|
||||
HTTParty::Request.stub(:new => @request)
|
||||
HTTParty::Request.stub(new: @request)
|
||||
end
|
||||
|
||||
it "should fail with redirected GET" do
|
||||
lambda do
|
||||
@error = @klass.get('/foo', :no_follow => true)
|
||||
@error = @klass.get('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected POST" do
|
||||
lambda do
|
||||
@klass.post('/foo', :no_follow => true)
|
||||
@klass.post('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected PATCH" do
|
||||
lambda do
|
||||
@klass.patch('/foo', :no_follow => true)
|
||||
@klass.patch('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected DELETE" do
|
||||
lambda do
|
||||
@klass.delete('/foo', :no_follow => true)
|
||||
@klass.delete('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected MOVE" do
|
||||
lambda do
|
||||
@klass.move('/foo', :no_follow => true)
|
||||
@klass.move('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected COPY" do
|
||||
lambda do
|
||||
@klass.copy('/foo', :no_follow => true)
|
||||
@klass.copy('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected PUT" do
|
||||
lambda do
|
||||
@klass.put('/foo', :no_follow => true)
|
||||
@klass.put('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected HEAD" do
|
||||
lambda do
|
||||
@klass.head('/foo', :no_follow => true)
|
||||
@klass.head('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
|
||||
it "should fail with redirected OPTIONS" do
|
||||
lambda do
|
||||
@klass.options('/foo', :no_follow => true)
|
||||
@klass.options('/foo', no_follow: true)
|
||||
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
||||
end
|
||||
end
|
||||
|
@ -549,20 +549,20 @@ describe HTTParty do
|
|||
before(:each) do
|
||||
@klass.instance_eval do
|
||||
base_uri "http://first.com"
|
||||
default_params :one => 1
|
||||
default_params one: 1
|
||||
end
|
||||
|
||||
@additional_klass = Class.new
|
||||
@additional_klass.instance_eval do
|
||||
include HTTParty
|
||||
base_uri "http://second.com"
|
||||
default_params :two => 2
|
||||
default_params two: 2
|
||||
end
|
||||
end
|
||||
|
||||
it "should not run over each others options" do
|
||||
@klass.default_options.should == { :base_uri => 'http://first.com', :default_params => { :one => 1 } }
|
||||
@additional_klass.default_options.should == { :base_uri => 'http://second.com', :default_params => { :two => 2 } }
|
||||
@klass.default_options.should == { base_uri: 'http://first.com', default_params: { one: 1 } }
|
||||
@additional_klass.default_options.should == { base_uri: 'http://second.com', default_params: { two: 2 } }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -580,32 +580,32 @@ describe HTTParty do
|
|||
end
|
||||
|
||||
it "does not modify each others inherited attributes" do
|
||||
@child1.default_params :joe => "alive"
|
||||
@child2.default_params :joe => "dead"
|
||||
@child1.default_params joe: "alive"
|
||||
@child2.default_params joe: "dead"
|
||||
|
||||
@child1.default_options.should == { :default_params => {:joe => "alive"} }
|
||||
@child2.default_options.should == { :default_params => {:joe => "dead"} }
|
||||
@child1.default_options.should == { default_params: {joe: "alive"} }
|
||||
@child2.default_options.should == { default_params: {joe: "dead"} }
|
||||
|
||||
@parent.default_options.should == { }
|
||||
end
|
||||
|
||||
it "inherits default_options from the superclass" do
|
||||
@parent.basic_auth 'user', 'password'
|
||||
@child1.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
|
||||
@child1.default_options.should == {basic_auth: {username: 'user', password: 'password'}}
|
||||
@child1.basic_auth 'u', 'p' # modifying child1 has no effect on child2
|
||||
@child2.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
|
||||
@child2.default_options.should == {basic_auth: {username: 'user', password: 'password'}}
|
||||
end
|
||||
|
||||
it "doesn't modify the parent's default options" do
|
||||
@parent.basic_auth 'user', 'password'
|
||||
|
||||
@child1.basic_auth 'u', 'p'
|
||||
@child1.default_options.should == {:basic_auth => {:username => 'u', :password => 'p'}}
|
||||
@child1.default_options.should == {basic_auth: {username: 'u', password: 'p'}}
|
||||
|
||||
@child1.basic_auth 'email', 'token'
|
||||
@child1.default_options.should == {:basic_auth => {:username => 'email', :password => 'token'}}
|
||||
@child1.default_options.should == {basic_auth: {username: 'email', password: 'token'}}
|
||||
|
||||
@parent.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
|
||||
@parent.default_options.should == {basic_auth: {username: 'user', password: 'password'}}
|
||||
end
|
||||
|
||||
it "doesn't modify hashes in the parent's default options" do
|
||||
|
|
|
@ -4,8 +4,8 @@ module HTTParty
|
|||
module SSLTestHelper
|
||||
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
|
||||
options = {
|
||||
:format => :json,
|
||||
:timeout => 30,
|
||||
format: :json,
|
||||
timeout: 30,
|
||||
}.merge(options)
|
||||
|
||||
if mode
|
||||
|
@ -16,8 +16,8 @@ module HTTParty
|
|||
|
||||
begin
|
||||
test_server = SSLTestServer.new(
|
||||
:rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
||||
:cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
||||
rsa_key: File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
||||
cert: File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
||||
|
||||
test_server.start
|
||||
|
||||
|
@ -33,8 +33,8 @@ module HTTParty
|
|||
end
|
||||
|
||||
test_server = SSLTestServer.new({
|
||||
:rsa_key => path.join('server.key').read,
|
||||
:cert => path.join(server_cert_filename).read,
|
||||
rsa_key: path.join('server.key').read,
|
||||
cert: path.join(server_cert_filename).read,
|
||||
})
|
||||
|
||||
test_server.start
|
||||
|
|
|
@ -7,7 +7,7 @@ module HTTParty
|
|||
response = Net::HTTPOK.new("1.1", 200, "Content for you")
|
||||
response.stub!(:body).and_return(data)
|
||||
|
||||
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
|
||||
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: format)
|
||||
http_request.stub_chain(:http, :request).and_return(response)
|
||||
|
||||
HTTParty::Request.should_receive(:new).and_return(http_request)
|
||||
|
@ -20,7 +20,7 @@ module HTTParty
|
|||
@body || chunked_data.each(&block)
|
||||
end
|
||||
|
||||
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => "html")
|
||||
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: "html")
|
||||
http_request.stub_chain(:http, :request).and_yield(response).and_return(response)
|
||||
|
||||
HTTParty::Request.should_receive(:new).and_return(http_request)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
basic_auth 'username', 'password'
|
||||
end
|
||||
|
||||
Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})</code></pre>
|
||||
Twitter.post('/statuses/update.json', query: {status: "It's an HTTParty and everyone is invited!"})</code></pre>
|
||||
|
||||
<p>That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). </p>
|
||||
|
||||
|
@ -44,11 +44,11 @@ Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty an
|
|||
base_uri 'twitter.com'
|
||||
|
||||
def initialize(u, p)
|
||||
@auth = {:username => u, :password => p}
|
||||
@auth = {username: u, password: p}
|
||||
end
|
||||
|
||||
def post(text)
|
||||
options = { :query => {:status => text}, :basic_auth => @auth }
|
||||
options = { query: {status: text}, basic_auth: @auth }
|
||||
self.class.post('/statuses/update.json', options)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue