httparty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe HTTParty::CoreExt::HashConversions do
4
+ it "should convert hash to struct" do
5
+ {'foo' => 'bar'}.to_struct.should == OpenStruct.new(:foo => 'bar')
6
+ end
7
+
8
+ it 'should convert nested hash to struct' do
9
+ {'foo' => {'bar' => 'baz'}}.to_struct.should == OpenStruct.new(:foo => OpenStruct.new(:bar => 'baz'))
10
+ end
11
+ end
@@ -0,0 +1,145 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ class Foo
4
+ include HTTParty
5
+ base_uri 'api.foo.com/v1'
6
+ end
7
+
8
+ class FooWithHttps
9
+ include HTTParty
10
+ base_uri 'api.foo.com/v1:443'
11
+ end
12
+
13
+ describe HTTParty do
14
+
15
+ describe "base uri" do
16
+ it "should be gettable" do
17
+ Foo.base_uri.should == 'http://api.foo.com/v1'
18
+ end
19
+
20
+ it 'should be setable' do
21
+ Foo.base_uri('http://api.foobar.com')
22
+ Foo.base_uri.should == 'http://api.foobar.com'
23
+ end
24
+
25
+ it "should add http if not present for non ssl requests" do
26
+ Foo.base_uri('api.foobar.com')
27
+ Foo.base_uri.should == 'http://api.foobar.com'
28
+ end
29
+
30
+ it "should add https if not present for ssl requests" do
31
+ FooWithHttps.base_uri.should == 'https://api.foo.com/v1:443'
32
+ end
33
+ end
34
+
35
+ describe "headers" do
36
+ it "should default to empty hash" do
37
+ Foo.headers.should == {}
38
+ end
39
+
40
+ it "should be able to be updated" do
41
+ init_headers = {:foo => 'bar', :baz => 'spax'}
42
+ Foo.headers init_headers
43
+ Foo.headers.should == init_headers
44
+ end
45
+ end
46
+
47
+ describe "default params" do
48
+ it "should default to empty hash" do
49
+ Foo.default_params.should == {}
50
+ end
51
+
52
+ it "should be able to be updated" do
53
+ new_defaults = {:foo => 'bar', :baz => 'spax'}
54
+ Foo.default_params new_defaults
55
+ Foo.default_params.should == new_defaults
56
+ end
57
+ end
58
+
59
+ describe "basic http authentication" do
60
+ it "should work" do
61
+ Foo.basic_auth 'foobar', 'secret'
62
+ Foo.instance_variable_get("@auth").should == {:username => 'foobar', :password => 'secret'}
63
+ end
64
+ end
65
+
66
+ describe "format" do
67
+ it "should allow xml" do
68
+ Foo.format :xml
69
+ Foo.instance_variable_get("@format").should == 'xml'
70
+ end
71
+
72
+ it "should allow json" do
73
+ Foo.format :json
74
+ Foo.instance_variable_get("@format").should == 'json'
75
+ end
76
+
77
+ it 'should not allow funky format' do
78
+ lambda do
79
+ Foo.format :foobar
80
+ end.should raise_error(HTTParty::UnsupportedFormat)
81
+ end
82
+ end
83
+
84
+ describe 'http' do
85
+ it "should use ssl for port 443" do
86
+ FooWithHttps.send(:http, URI.parse('https://api.foo.com/v1:443')).use_ssl?.should == true
87
+ end
88
+
89
+ it 'should not use ssl for port 80' do
90
+ Foo.send(:http, URI.parse('http://foobar.com')).use_ssl?.should == false
91
+ end
92
+ end
93
+
94
+ describe "deriving format from path" do
95
+ it "should work if there is extension and extension is an allowed format" do
96
+ %w[xml json].each do |ext|
97
+ Foo.send(:format_from_path, "/foo/bar.#{ext}").should == ext
98
+ end
99
+ end
100
+
101
+ it "should NOT work if there is extension but extention is not allow format" do
102
+ Foo.send(:format_from_path, '/foo/bar.php').should == nil
103
+ end
104
+
105
+ it 'should NOT work if there is no extension' do
106
+ ['', '.'].each do |ext|
107
+ Foo.send(:format_from_path, "/foo/bar#{ext}").should == nil
108
+ end
109
+ end
110
+ end
111
+
112
+ describe 'parsing responses' do
113
+ it 'should handle xml automatically' do
114
+ xml = %q[<books><book><id>1234</id><name>Foo Bar!</name></book></books>]
115
+ Foo.format :xml
116
+ Foo.send(:parse_response, xml).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
117
+ end
118
+
119
+ it 'should handle json automatically' do
120
+ json = %q[{"books": {"book": {"name": "Foo Bar!", "id": "1234"}}}]
121
+ Foo.format :json
122
+ Foo.send(:parse_response, json).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
123
+ end
124
+ end
125
+
126
+ describe "sending requests" do
127
+ it "should not work with request method other than get, post, put, delete" do
128
+ lambda do
129
+ Foo.send(:send_request, 'foo', '/foo')
130
+ end.should raise_error(ArgumentError)
131
+ end
132
+
133
+ it 'should require that :query is a hash if present' do
134
+ lambda do
135
+ Foo.send(:send_request, 'get', '/foo', :query => 'string')
136
+ end.should raise_error(ArgumentError)
137
+ end
138
+
139
+ it 'should require that :headers is a hash if present' do
140
+ lambda do
141
+ Foo.send(:send_request, 'get', '/foo', :headers => 'string')
142
+ end.should raise_error(ArgumentError)
143
+ end
144
+ end
145
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'httparty')
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httparty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Nunemaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-29 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.1"
24
+ version:
25
+ description: Makes http fun! Also, makes consuming restful web services dead easy.
26
+ email:
27
+ - nunemaker@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - License.txt
35
+ - Manifest.txt
36
+ - PostInstall.txt
37
+ - README.txt
38
+ files:
39
+ - History.txt
40
+ - License.txt
41
+ - Manifest.txt
42
+ - PostInstall.txt
43
+ - README.txt
44
+ - Rakefile
45
+ - config/hoe.rb
46
+ - config/requirements.rb
47
+ - examples/aaws.rb
48
+ - examples/delicious.rb
49
+ - examples/twitter.rb
50
+ - examples/whoismyrep.rb
51
+ - httparty.gemspec
52
+ - lib/httparty.rb
53
+ - lib/httparty/core_ext.rb
54
+ - lib/httparty/core_ext/hash.rb
55
+ - lib/httparty/version.rb
56
+ - script/console
57
+ - script/destroy
58
+ - script/generate
59
+ - script/txt2html
60
+ - setup.rb
61
+ - spec/hash_spec.rb
62
+ - spec/httparty_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ - tasks/deployment.rake
66
+ - tasks/environment.rake
67
+ - tasks/website.rake
68
+ has_rdoc: true
69
+ homepage: http://httparty.rubyforge.org
70
+ post_install_message: When you HTTParty, you must party hard!
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: httparty
91
+ rubygems_version: 1.2.0
92
+ signing_key:
93
+ specification_version: 2
94
+ summary: Makes http fun! Also, makes consuming restful web services dead easy.
95
+ test_files: []
96
+