Class: GoogleText::Session

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

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



3
4
5
6
7
8
9
# File 'lib/google_text/session.rb', line 3

def initialize
  @proxy = Curl::Easy.new do |curl|
     curl.headers["User-Agent"] = GoogleText.configuration.user_agent
     curl.follow_location = true
     curl.enable_cookies = true
   end
end

Instance Method Details

#bodyObject



11
12
13
14
# File 'lib/google_text/session.rb', line 11

def body
  body = @proxy.body_str
  body.respond_to?(:force_encoding) ? body.force_encoding('utf-8') : body
end

#get(url) ⇒ Object



16
17
18
19
20
# File 'lib/google_text/session.rb', line 16

def get(url)
  self.url = url
  @proxy.perform
  handle_response
end

#post(url, fields = []) ⇒ Object



22
23
24
25
26
# File 'lib/google_text/session.rb', line 22

def post(url,fields=[])
  self.url = url
  @proxy.http_post fields
  handle_response
end

#response_codeObject



36
37
38
# File 'lib/google_text/session.rb', line 36

def response_code
  @proxy.response_code
end

#urlObject



28
29
30
# File 'lib/google_text/session.rb', line 28

def url
  @proxy.url
end

#url=(url) ⇒ Object



32
33
34
# File 'lib/google_text/session.rb', line 32

def url=(url)
  @proxy.url = url
end