rubycurl 1.7.3
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/.document +5 -0
- data/.gitignore +5 -0
- data/README.rdoc +40 -0
- data/Rakefile +9 -0
- data/lib/rubycurl.rb +43 -0
- data/rubycurl.gemspec +45 -0
- data/test/rubycurl_test.rb +22 -0
- metadata +61 -0
data/.document
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= RubyCurl
|
2
|
+
|
3
|
+
RubyCurl is a simple way of getting html, xml or other text based files, into a variable, quick.
|
4
|
+
|
5
|
+
|
6
|
+
= Install
|
7
|
+
|
8
|
+
To install RubyCurl simply..
|
9
|
+
|
10
|
+
sudo gem install rubycurl
|
11
|
+
|
12
|
+
|
13
|
+
=Simple Get
|
14
|
+
|
15
|
+
In your controller..
|
16
|
+
|
17
|
+
@curl = RubyCurl.new('http://github.com')
|
18
|
+
|
19
|
+
In your view..
|
20
|
+
|
21
|
+
<%= @curl.body %>
|
22
|
+
|
23
|
+
Even more simply, in your view just put
|
24
|
+
|
25
|
+
<%= RubyCurl.new('http://github.com').body %>
|
26
|
+
|
27
|
+
|
28
|
+
=Posting A Form
|
29
|
+
|
30
|
+
RubyCurl.post({'username' => 'arbarlow','password' => 'arbarlowpassword'}, 'http://example.com' )
|
31
|
+
|
32
|
+
|
33
|
+
=Get With HTTP Authentication
|
34
|
+
|
35
|
+
@curl = RubyCurl.auth ('username', 'password', "http://twitter.com/statuses/friends_timeline.xml" )
|
36
|
+
|
37
|
+
|
38
|
+
=Post With HTTP Authentication
|
39
|
+
|
40
|
+
RubyCurl.post_with_auth({'username' => 'yourusername', 'password' => 'yourpassword'}, {'param1' => 'param1text','param2' => 'param2text'}, 'http://example.com' )
|
data/Rakefile
ADDED
data/lib/rubycurl.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class RubyCurl
|
2
|
+
|
3
|
+
# Takes url and returns result with .body and follows redirect if any.
|
4
|
+
#
|
5
|
+
# Example RubyCurl.new ('http://apple.com')
|
6
|
+
def initialize(url)
|
7
|
+
@result = %x"curl '#{url}' -L"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Takes username, password, url , then returns result and follows redirect if any.
|
11
|
+
#
|
12
|
+
# Example RubyCurl.auth ('username', 'password', "http://twitter.com/statuses/friends_timeline.xml" )
|
13
|
+
def self.auth(username, password, url)
|
14
|
+
@result = %x"curl -u #{username}:#{password} '#{url}' -L"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Uses HTTP post to post a form using params and returns the html, text or xml and follows redirect if any.
|
18
|
+
#
|
19
|
+
# Example RubyCurl.post({'param1' => 'param1text','param2' => 'param2text'}, 'http://example.com' )
|
20
|
+
def self.post(params, url)
|
21
|
+
curlparam = ""
|
22
|
+
params.each_pair {|key, value| curlparam << "#{key}=#{value}" }
|
23
|
+
@result = %x"curl -d #{curlparam} '#{url}' -L"
|
24
|
+
end
|
25
|
+
|
26
|
+
#Uses HTTP post to post a form using params and authentication
|
27
|
+
#
|
28
|
+
# Example RubyCurl.post_with_auth({'username' => 'yourusername', 'password' => 'yourpassword'}, {'param1' => 'param1text','param2' => 'param2text'}, 'http://example.com' )
|
29
|
+
def self.post_with_auth(auth, params, url)
|
30
|
+
curlparam = ""
|
31
|
+
params.each_pair {|key, value| curlparam << "#{key}=#{value}" }
|
32
|
+
@result = %x"curl -u #{auth['username']}:#{auth['password']} -d #{curlparam} '#{url}' -L"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns result of .new in string
|
36
|
+
#
|
37
|
+
# Example @test = RubyCurl.new ('http://apple.com')
|
38
|
+
# puts @test.body
|
39
|
+
def body
|
40
|
+
"#{@result}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/rubycurl.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rubycurl}
|
8
|
+
s.version = "1.7.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["arbarlow"]
|
12
|
+
s.date = %q{2009-09-17}
|
13
|
+
s.description = %q{Easy use of curl for getting html, xml, etc}
|
14
|
+
s.email = %q{alexbarlowis@me.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"lib/rubycurl.rb",
|
24
|
+
"rubycurl.gemspec",
|
25
|
+
"test/rubycurl_test.rb",
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/arbalrow/rubycurl/}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.5}
|
31
|
+
s.summary = %q{Easy use of curl for getting html, xml, etc}
|
32
|
+
s.test_files = [
|
33
|
+
"test/rubycurl_test.rb",
|
34
|
+
]
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
41
|
+
else
|
42
|
+
end
|
43
|
+
else
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubycurl'
|
3
|
+
|
4
|
+
class RubycurlTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
sinatra_app = File.dirname(__FILE__) + '/sinatra_tester.rb'
|
8
|
+
@pid = fork do
|
9
|
+
`shotgun #{sinatra_app}`
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
Process.kill("Shotgun", @pid)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_simple_get
|
18
|
+
simple_test = RubyCurl.new('http://localhost:9393/')
|
19
|
+
assert(simple_test == "Test Succesful")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubycurl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.7.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- arbarlow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-17 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Easy use of curl for getting html, xml, etc
|
17
|
+
email: alexbarlowis@me.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .document
|
26
|
+
- .gitignore
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- lib/rubycurl.rb
|
30
|
+
- rubycurl.gemspec
|
31
|
+
- test/rubycurl_test.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/arbalrow/rubycurl/
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.3.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Easy use of curl for getting html, xml, etc
|
60
|
+
test_files:
|
61
|
+
- test/rubycurl_test.rb
|