spreedly 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +66 -0
- data/README.txt +68 -0
- data/Rakefile +72 -0
- data/lib/spreedly.rb +154 -0
- data/lib/spreedly/common.rb +24 -0
- data/lib/spreedly/mock.rb +113 -0
- data/lib/spreedly/version.rb +3 -0
- data/test/spreedly_gem_test.rb +152 -0
- data/test/test_site.yml +2 -0
- data/vendor/httparty/History +108 -0
- data/vendor/httparty/MIT-LICENSE +20 -0
- data/vendor/httparty/Manifest +55 -0
- data/vendor/httparty/README +35 -0
- data/vendor/httparty/Rakefile +47 -0
- data/vendor/httparty/bin/httparty +98 -0
- data/vendor/httparty/cucumber.yml +1 -0
- data/vendor/httparty/examples/aaws.rb +32 -0
- data/vendor/httparty/examples/basic.rb +11 -0
- data/vendor/httparty/examples/delicious.rb +37 -0
- data/vendor/httparty/examples/google.rb +16 -0
- data/vendor/httparty/examples/rubyurl.rb +14 -0
- data/vendor/httparty/examples/twitter.rb +31 -0
- data/vendor/httparty/examples/whoismyrep.rb +10 -0
- data/vendor/httparty/features/basic_authentication.feature +20 -0
- data/vendor/httparty/features/command_line.feature +7 -0
- data/vendor/httparty/features/deals_with_http_error_codes.feature +26 -0
- data/vendor/httparty/features/handles_multiple_formats.feature +34 -0
- data/vendor/httparty/features/steps/env.rb +15 -0
- data/vendor/httparty/features/steps/httparty_response_steps.rb +26 -0
- data/vendor/httparty/features/steps/httparty_steps.rb +15 -0
- data/vendor/httparty/features/steps/mongrel_helper.rb +55 -0
- data/vendor/httparty/features/steps/remote_service_steps.rb +47 -0
- data/vendor/httparty/features/supports_redirection.feature +22 -0
- data/vendor/httparty/httparty.gemspec +37 -0
- data/vendor/httparty/lib/core_extensions.rb +189 -0
- data/vendor/httparty/lib/httparty.rb +201 -0
- data/vendor/httparty/lib/httparty/cookie_hash.rb +9 -0
- data/vendor/httparty/lib/httparty/exceptions.rb +7 -0
- data/vendor/httparty/lib/httparty/logging.rb +35 -0
- data/vendor/httparty/lib/httparty/module_inheritable_attributes.rb +25 -0
- data/vendor/httparty/lib/httparty/parsers.rb +4 -0
- data/vendor/httparty/lib/httparty/parsers/json.rb +74 -0
- data/vendor/httparty/lib/httparty/parsers/xml.rb +209 -0
- data/vendor/httparty/lib/httparty/request.rb +169 -0
- data/vendor/httparty/lib/httparty/response.rb +17 -0
- data/vendor/httparty/lib/httparty/version.rb +3 -0
- data/vendor/httparty/setup.rb +1585 -0
- data/vendor/httparty/spec/fixtures/delicious.xml +23 -0
- data/vendor/httparty/spec/fixtures/empty.xml +0 -0
- data/vendor/httparty/spec/fixtures/google.html +3 -0
- data/vendor/httparty/spec/fixtures/twitter.json +1 -0
- data/vendor/httparty/spec/fixtures/twitter.xml +403 -0
- data/vendor/httparty/spec/fixtures/undefined_method_add_node_for_nil.xml +2 -0
- data/vendor/httparty/spec/hash_spec.rb +49 -0
- data/vendor/httparty/spec/httparty/cookie_hash_spec.rb +38 -0
- data/vendor/httparty/spec/httparty/parsers/json_spec.rb +44 -0
- data/vendor/httparty/spec/httparty/parsers/xml_spec.rb +454 -0
- data/vendor/httparty/spec/httparty/request_spec.rb +203 -0
- data/vendor/httparty/spec/httparty/response_spec.rb +53 -0
- data/vendor/httparty/spec/httparty_spec.rb +259 -0
- data/vendor/httparty/spec/spec.opts +3 -0
- data/vendor/httparty/spec/spec_helper.rb +21 -0
- data/vendor/httparty/spec/string_spec.rb +29 -0
- data/vendor/httparty/website/css/common.css +47 -0
- data/vendor/httparty/website/index.html +74 -0
- metadata +141 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{httparty}
|
5
|
+
s.version = "0.3.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["John Nunemaker"]
|
9
|
+
s.date = %q{2009-02-10}
|
10
|
+
s.default_executable = %q{httparty}
|
11
|
+
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
12
|
+
s.email = %q{nunemaker@gmail.com}
|
13
|
+
s.executables = ["httparty"]
|
14
|
+
s.extra_rdoc_files = ["bin/httparty", "lib/core_extensions.rb", "lib/httparty/cookie_hash.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/parsers/json.rb", "lib/httparty/parsers/xml.rb", "lib/httparty/parsers.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "README"]
|
15
|
+
s.files = ["bin/httparty", "cucumber.yml", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "features/basic_authentication.feature", "features/command_line.feature", "features/deals_with_http_error_codes.feature", "features/handles_multiple_formats.feature", "features/steps/env.rb", "features/steps/httparty_response_steps.rb", "features/steps/httparty_steps.rb", "features/steps/mongrel_helper.rb", "features/steps/remote_service_steps.rb", "features/supports_redirection.feature", "History", "httparty.gemspec", "lib/core_extensions.rb", "lib/httparty/cookie_hash.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/parsers/json.rb", "lib/httparty/parsers/xml.rb", "lib/httparty/parsers.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "setup.rb", "spec/fixtures/delicious.xml", "spec/fixtures/empty.xml", "spec/fixtures/google.html", "spec/fixtures/twitter.json", "spec/fixtures/twitter.xml", "spec/fixtures/undefined_method_add_node_for_nil.xml", "spec/hash_spec.rb", "spec/httparty/cookie_hash_spec.rb", "spec/httparty/parsers/json_spec.rb", "spec/httparty/parsers/xml_spec.rb", "spec/httparty/request_spec.rb", "spec/httparty/response_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "website/css/common.css", "website/index.html"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://httparty.rubyforge.org}
|
18
|
+
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
19
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Httparty", "--main", "README"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.rubyforge_project = %q{httparty}
|
22
|
+
s.rubygems_version = %q{1.3.1}
|
23
|
+
s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
# Copyright (c) 2008 Sam Smoot.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
class Object #:nodoc:
|
25
|
+
# @return <TrueClass, FalseClass>
|
26
|
+
#
|
27
|
+
# @example [].blank? #=> true
|
28
|
+
# @example [1].blank? #=> false
|
29
|
+
# @example [nil].blank? #=> false
|
30
|
+
#
|
31
|
+
# Returns true if the object is nil or empty (if applicable)
|
32
|
+
def blank?
|
33
|
+
nil? || (respond_to?(:empty?) && empty?)
|
34
|
+
end unless method_defined?(:blank?)
|
35
|
+
end # class Object
|
36
|
+
|
37
|
+
class Numeric #:nodoc:
|
38
|
+
# @return <TrueClass, FalseClass>
|
39
|
+
#
|
40
|
+
# Numerics can't be blank
|
41
|
+
def blank?
|
42
|
+
false
|
43
|
+
end unless method_defined?(:blank?)
|
44
|
+
end # class Numeric
|
45
|
+
|
46
|
+
class NilClass #:nodoc:
|
47
|
+
# @return <TrueClass, FalseClass>
|
48
|
+
#
|
49
|
+
# Nils are always blank
|
50
|
+
def blank?
|
51
|
+
true
|
52
|
+
end unless method_defined?(:blank?)
|
53
|
+
end # class NilClass
|
54
|
+
|
55
|
+
class TrueClass #:nodoc:
|
56
|
+
# @return <TrueClass, FalseClass>
|
57
|
+
#
|
58
|
+
# True is not blank.
|
59
|
+
def blank?
|
60
|
+
false
|
61
|
+
end unless method_defined?(:blank?)
|
62
|
+
end # class TrueClass
|
63
|
+
|
64
|
+
class FalseClass #:nodoc:
|
65
|
+
# False is always blank.
|
66
|
+
def blank?
|
67
|
+
true
|
68
|
+
end unless method_defined?(:blank?)
|
69
|
+
end # class FalseClass
|
70
|
+
|
71
|
+
class String #:nodoc:
|
72
|
+
# @example "".blank? #=> true
|
73
|
+
# @example " ".blank? #=> true
|
74
|
+
# @example " hey ho ".blank? #=> false
|
75
|
+
#
|
76
|
+
# @return <TrueClass, FalseClass>
|
77
|
+
#
|
78
|
+
# Strips out whitespace then tests if the string is empty.
|
79
|
+
def blank?
|
80
|
+
strip.empty?
|
81
|
+
end unless method_defined?(:blank?)
|
82
|
+
|
83
|
+
def snake_case
|
84
|
+
return self.downcase if self =~ /^[A-Z]+$/
|
85
|
+
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
|
86
|
+
return $+.downcase
|
87
|
+
end unless method_defined?(:snake_case)
|
88
|
+
end # class String
|
89
|
+
|
90
|
+
class Hash #:nodoc:
|
91
|
+
# @return <String> This hash as a query string
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# { :name => "Bob",
|
95
|
+
# :address => {
|
96
|
+
# :street => '111 Ruby Ave.',
|
97
|
+
# :city => 'Ruby Central',
|
98
|
+
# :phones => ['111-111-1111', '222-222-2222']
|
99
|
+
# }
|
100
|
+
# }.to_params
|
101
|
+
# #=> "name=Bob&address[city]=Ruby Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111 Ruby Ave."
|
102
|
+
def to_params
|
103
|
+
params = self.map { |k,v| normalize_param(k,v) }.join
|
104
|
+
params.chop! # trailing &
|
105
|
+
params
|
106
|
+
end
|
107
|
+
|
108
|
+
# @param key<Object> The key for the param.
|
109
|
+
# @param value<Object> The value for the param.
|
110
|
+
#
|
111
|
+
# @return <String> This key value pair as a param
|
112
|
+
#
|
113
|
+
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
|
114
|
+
def normalize_param(key, value)
|
115
|
+
param = ''
|
116
|
+
stack = []
|
117
|
+
|
118
|
+
if value.is_a?(Array)
|
119
|
+
param << value.map { |element| normalize_param("#{key}[]", element) }.join
|
120
|
+
elsif value.is_a?(Hash)
|
121
|
+
stack << [key,value]
|
122
|
+
else
|
123
|
+
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
124
|
+
end
|
125
|
+
|
126
|
+
stack.each do |parent, hash|
|
127
|
+
hash.each do |key, value|
|
128
|
+
if value.is_a?(Hash)
|
129
|
+
stack << ["#{parent}[#{key}]", value]
|
130
|
+
else
|
131
|
+
param << normalize_param("#{parent}[#{key}]", value)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
param
|
137
|
+
end
|
138
|
+
|
139
|
+
# @return <String> The hash as attributes for an XML tag.
|
140
|
+
#
|
141
|
+
# @example
|
142
|
+
# { :one => 1, "two"=>"TWO" }.to_xml_attributes
|
143
|
+
# #=> 'one="1" two="TWO"'
|
144
|
+
def to_xml_attributes
|
145
|
+
map do |k,v|
|
146
|
+
%{#{k.to_s.snake_case.sub(/^(.{1,1})/) { |m| m.downcase }}="#{v}"}
|
147
|
+
end.join(' ')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class BlankSlate #:nodoc:
|
152
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ }
|
153
|
+
end
|
154
|
+
|
155
|
+
case RUBY_VERSION
|
156
|
+
when '1.8.6'
|
157
|
+
# 1.8.6 has mistyping of transitive in if statement
|
158
|
+
require "rexml/document"
|
159
|
+
module REXML #:nodoc:
|
160
|
+
class Document < Element #:nodoc:
|
161
|
+
undef :write
|
162
|
+
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
163
|
+
if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
|
164
|
+
output = Output.new( output, xml_decl.encoding )
|
165
|
+
end
|
166
|
+
formatter = if indent > -1
|
167
|
+
if transitive
|
168
|
+
REXML::Formatters::Transitive.new( indent, ie_hack )
|
169
|
+
else
|
170
|
+
REXML::Formatters::Pretty.new( indent, ie_hack )
|
171
|
+
end
|
172
|
+
else
|
173
|
+
REXML::Formatters::Default.new( ie_hack )
|
174
|
+
end
|
175
|
+
formatter.write( self, output )
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# clean up "using default DH parameters" warning for https
|
181
|
+
require 'net/https'
|
182
|
+
class Net::HTTP
|
183
|
+
alias :old_use_ssl= :use_ssl=
|
184
|
+
def use_ssl= flag
|
185
|
+
self.old_use_ssl = flag
|
186
|
+
@ssl_context.tmp_dh_callback = proc {} if @ssl_context
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'core_extensions'
|
6
|
+
require 'httparty/module_inheritable_attributes'
|
7
|
+
|
8
|
+
module HTTParty
|
9
|
+
|
10
|
+
AllowedFormats = {
|
11
|
+
'text/xml' => :xml,
|
12
|
+
'application/xml' => :xml,
|
13
|
+
'application/json' => :json,
|
14
|
+
'text/json' => :json,
|
15
|
+
'application/javascript' => :json,
|
16
|
+
'text/javascript' => :json,
|
17
|
+
'text/html' => :html,
|
18
|
+
'application/x-yaml' => :yaml,
|
19
|
+
'text/yaml' => :yaml
|
20
|
+
} unless defined?(AllowedFormats)
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.extend ClassMethods
|
24
|
+
base.send :include, HTTParty::ModuleInheritableAttributes
|
25
|
+
base.send(:mattr_inheritable, :default_options)
|
26
|
+
base.instance_variable_set("@default_options", {})
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
# Allows setting http proxy information to be used
|
31
|
+
#
|
32
|
+
# class Foo
|
33
|
+
# include HTTParty
|
34
|
+
# http_proxy 'http://foo.com', 80
|
35
|
+
# end
|
36
|
+
def http_proxy(addr=nil, port = nil)
|
37
|
+
default_options[:http_proxyaddr] = addr
|
38
|
+
default_options[:http_proxyport] = port
|
39
|
+
end
|
40
|
+
|
41
|
+
# Allows setting a base uri to be used for each request.
|
42
|
+
# Will normalize uri to include http, etc.
|
43
|
+
#
|
44
|
+
# class Foo
|
45
|
+
# include HTTParty
|
46
|
+
# base_uri 'twitter.com'
|
47
|
+
# end
|
48
|
+
def base_uri(uri=nil)
|
49
|
+
return default_options[:base_uri] unless uri
|
50
|
+
default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Allows setting basic authentication username and password.
|
54
|
+
#
|
55
|
+
# class Foo
|
56
|
+
# include HTTParty
|
57
|
+
# basic_auth 'username', 'password'
|
58
|
+
# end
|
59
|
+
def basic_auth(u, p)
|
60
|
+
default_options[:basic_auth] = {:username => u, :password => p}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Allows setting default parameters to be appended to each request.
|
64
|
+
# Great for api keys and such.
|
65
|
+
#
|
66
|
+
# class Foo
|
67
|
+
# include HTTParty
|
68
|
+
# default_params :api_key => 'secret', :another => 'foo'
|
69
|
+
# end
|
70
|
+
def default_params(h={})
|
71
|
+
raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
|
72
|
+
default_options[:default_params] ||= {}
|
73
|
+
default_options[:default_params].merge!(h)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Allows setting a base uri to be used for each request.
|
77
|
+
#
|
78
|
+
# class Foo
|
79
|
+
# include HTTParty
|
80
|
+
# headers 'Accept' => 'text/html'
|
81
|
+
# end
|
82
|
+
def headers(h={})
|
83
|
+
raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash)
|
84
|
+
default_options[:headers] ||= {}
|
85
|
+
default_options[:headers].merge!(h)
|
86
|
+
end
|
87
|
+
|
88
|
+
def cookies(h={})
|
89
|
+
raise ArgumentError, 'Cookies must be a hash' unless h.is_a?(Hash)
|
90
|
+
default_options[:cookies] ||= CookieHash.new
|
91
|
+
default_options[:cookies].add_cookies(h)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Allows setting the format with which to parse.
|
95
|
+
# Must be one of the allowed formats ie: json, xml
|
96
|
+
#
|
97
|
+
# class Foo
|
98
|
+
# include HTTParty
|
99
|
+
# format :json
|
100
|
+
# end
|
101
|
+
def format(f)
|
102
|
+
raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.join(', ')}" unless AllowedFormats.value?(f)
|
103
|
+
default_options[:format] = f
|
104
|
+
end
|
105
|
+
|
106
|
+
# Allows making a get request to a url.
|
107
|
+
#
|
108
|
+
# class Foo
|
109
|
+
# include HTTParty
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# # Simple get with full url
|
113
|
+
# Foo.get('http://foo.com/resource.json')
|
114
|
+
#
|
115
|
+
# # Simple get with full url and query parameters
|
116
|
+
# # ie: http://foo.com/resource.json?limit=10
|
117
|
+
# Foo.get('http://foo.com/resource.json', :query => {:limit => 10})
|
118
|
+
def get(path, options={})
|
119
|
+
perform_request Net::HTTP::Get, path, options
|
120
|
+
end
|
121
|
+
|
122
|
+
# Allows making a post request to a url.
|
123
|
+
#
|
124
|
+
# class Foo
|
125
|
+
# include HTTParty
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# # Simple post with full url and setting the body
|
129
|
+
# Foo.post('http://foo.com/resources', :body => {:bar => 'baz'})
|
130
|
+
#
|
131
|
+
# # Simple post with full url using :query option,
|
132
|
+
# # which gets set as form data on the request.
|
133
|
+
# Foo.post('http://foo.com/resources', :query => {:bar => 'baz'})
|
134
|
+
def post(path, options={})
|
135
|
+
perform_request Net::HTTP::Post, path, options
|
136
|
+
end
|
137
|
+
|
138
|
+
def put(path, options={})
|
139
|
+
perform_request Net::HTTP::Put, path, options
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete(path, options={})
|
143
|
+
perform_request Net::HTTP::Delete, path, options
|
144
|
+
end
|
145
|
+
|
146
|
+
def default_options #:nodoc:
|
147
|
+
@default_options
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
def perform_request(http_method, path, options) #:nodoc:
|
152
|
+
process_cookies(options)
|
153
|
+
Request.new(http_method, path, default_options.dup.merge(options)).perform
|
154
|
+
end
|
155
|
+
|
156
|
+
def process_cookies(options) #:nodoc:
|
157
|
+
return unless options[:cookies] || default_options[:cookies]
|
158
|
+
options[:headers] ||= {}
|
159
|
+
options[:headers]["cookie"] = cookies(options[:cookies] || {}).to_cookie_string
|
160
|
+
|
161
|
+
default_options.delete(:cookies)
|
162
|
+
options.delete(:cookies)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.normalize_base_uri(url) #:nodoc:
|
167
|
+
use_ssl = (url =~ /^https/) || url.include?(':443')
|
168
|
+
ends_with_slash = url =~ /\/$/
|
169
|
+
|
170
|
+
url.chop! if ends_with_slash
|
171
|
+
url.gsub!(/^https?:\/\//i, '')
|
172
|
+
|
173
|
+
"http#{'s' if use_ssl}://#{url}"
|
174
|
+
end
|
175
|
+
|
176
|
+
class Basement #:nodoc:
|
177
|
+
include HTTParty
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.get(*args)
|
181
|
+
Basement.get(*args)
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.post(*args)
|
185
|
+
Basement.post(*args)
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.put(*args)
|
189
|
+
Basement.put(*args)
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.delete(*args)
|
193
|
+
Basement.delete(*args)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
require 'httparty/cookie_hash'
|
198
|
+
require 'httparty/exceptions'
|
199
|
+
require 'httparty/request'
|
200
|
+
require 'httparty/response'
|
201
|
+
require 'httparty/parsers'
|