Class: RubyCurl

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycurl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RubyCurl

Takes url and returns result with .body and follows redirect if any.

Example RubyCurl.new (‘apple.com’)



6
7
8
# File 'lib/rubycurl.rb', line 6

def initialize(url)
	@result = %x"curl '#{url}' -L"
end

Class Method Details

.auth(username, password, url) ⇒ Object

Takes username, password, url , then returns result and follows redirect if any.

Example RubyCurl.auth (‘username’, ‘password’, “twitter.com/statuses/friends_timeline.xml” )



13
14
15
# File 'lib/rubycurl.rb', line 13

def self.auth(username, password, url)
	@result = %x"curl -u #{username}:#{password} '#{url}' -L"
end

.post(params, url) ⇒ Object

Uses HTTP post to post a form using params and returns the html, text or xml and follows redirect if any.

Example RubyCurl.post(=> ‘param1text’,‘param2’ => ‘param2text’, ‘example.com’ )



20
21
22
23
24
# File 'lib/rubycurl.rb', line 20

def self.post(params, url)
	curlparam = ""  
	params.each_pair {|key, value| curlparam << "#{key}=#{value}" }	
	@result = %x"curl -d #{curlparam} '#{url}' -L"
end

.post_with_auth(auth, params, url) ⇒ Object

Uses HTTP post to post a form using params and authentication

Example RubyCurl.post_with_auth(=> ‘yourusername’, ‘password’ => ‘yourpassword’, => ‘param1text’,‘param2’ => ‘param2text’, ‘example.com’ )



29
30
31
32
33
# File 'lib/rubycurl.rb', line 29

def self.post_with_auth(auth, params, url)
	curlparam = "" 
	params.each_pair {|key, value| curlparam << "#{key}=#{value}" }	
	@result = %x"curl -u #{auth['username']}:#{auth['password']} -d #{curlparam} '#{url}' -L"
end

Instance Method Details

#bodyObject

Returns result of .new in string

Example @test = RubyCurl.new (‘apple.com’) puts @test.body



39
40
41
# File 'lib/rubycurl.rb', line 39

def body
	"#{@result}"
end