Class: TinyGrabber
- Inherits:
-
Object
- Object
- TinyGrabber
- Defined in:
- lib/tiny_grabber.rb,
lib/tiny_grabber/version.rb
Overview
Main class for TinyGrabber
Defined Under Namespace
Classes: Agent
Constant Summary collapse
- VERSION =
Version number
"0.2.2"
Class Method Summary collapse
-
.get(url, config = {}) ⇒ Object
Singleton > HTTP::GET request.
-
.initialize(config = {}) ⇒ Object
Singleton > Initialize a new TinyGrabber user agent.
-
.post(url, params = {}, config = {}) ⇒ Object
Singleton > HTTP::GET request.
Instance Method Summary collapse
-
#basic_auth(username, password) ⇒ Object
Set BASIC_AUTH agent attribute.
-
#cookies ⇒ Object
Read COOKIES agent attribute.
-
#cookies=(cookies) ⇒ Object
Set COOKIES agent attribute.
-
#debug=(debug) ⇒ Object
Set DEBUG flag.
-
#get(url, headers = {}) ⇒ Object
HTTP::GET request.
-
#headers ⇒ Object
Read HEADERS agent attribute.
-
#headers=(headers) ⇒ Object
Set HEADERS agent attribute.
-
#initialize ⇒ TinyGrabber
constructor
Initialize a new TinyGrabber user agent.
-
#post(url, params = {}, headers = {}) ⇒ Object
HTTP::POST request.
-
#proxy ⇒ Object
Read PROXY agent attribute.
-
#proxy=(proxy) ⇒ Object
Set PROXY agent attribute.
-
#read_timeout ⇒ Object
Read READ_TIMEOUT agent attribute.
-
#read_timeout=(read_timeout) ⇒ Object
Set READ_TIMEOUT agent attribute.
-
#reset ⇒ Object
Call RESET agent method.
-
#user_agent ⇒ Object
Read USER_AGENT agent attribute.
-
#user_agent=(user_agent) ⇒ Object
Set USER_AGENT agent attribute.
Constructor Details
#initialize ⇒ TinyGrabber
Initialize a new TinyGrabber user agent.
17 18 19 |
# File 'lib/tiny_grabber.rb', line 17 def initialize @agent = TinyGrabber::Agent.new end |
Class Method Details
.get(url, config = {}) ⇒ Object
Singleton > HTTP::GET request
51 52 53 54 |
# File 'lib/tiny_grabber.rb', line 51 def self.get url, config = {} initialize config @agent.fetch url, :get end |
.initialize(config = {}) ⇒ Object
Singleton > Initialize a new TinyGrabber user agent.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tiny_grabber.rb', line 24 def self.initialize config = {} @agent = TinyGrabber::Agent.new @agent.debug = config[:debug] if config[:debug] @agent.read_timeout = config[:read_timeout] if config[:read_timeout] @agent.user_agent = config[:user_agent] if config[:user_agent] @agent.proxy = config[:proxy] if config[:proxy] @agent.basic_auth = config[:basic_auth] if config[:basic_auth] @agent.headers = config[:headers] if config[:headers] @agent. = config[:cookies] if config[:cookies] end |
.post(url, params = {}, config = {}) ⇒ Object
Singleton > HTTP::GET request
73 74 75 76 |
# File 'lib/tiny_grabber.rb', line 73 def self.post url, params = {}, config = {} initialize config @agent.fetch url, :post, {}, params end |
Instance Method Details
#basic_auth(username, password) ⇒ Object
Set BASIC_AUTH agent attribute
149 150 151 |
# File 'lib/tiny_grabber.rb', line 149 def basic_auth username, password @agent.basic_auth = { username: username, password: password } end |
#cookies ⇒ Object
Read COOKIES agent attribute
172 173 174 |
# File 'lib/tiny_grabber.rb', line 172 def @agent. end |
#cookies=(cookies) ⇒ Object
Set COOKIES agent attribute
181 182 183 |
# File 'lib/tiny_grabber.rb', line 181 def @agent. = end |
#debug=(debug) ⇒ Object
Set DEBUG flag
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tiny_grabber.rb', line 83 def debug= debug if debug.is_a?(TrueClass) || debug.is_a?(FalseClass) @agent.debug = debug @agent.debug_destination = :print @agent.debug_save_html = false elsif debug.is_a? Hash @agent.debug = debug[:active] @agent.debug_destination = debug[:destination] @agent.debug_save_html = debug[:save_html] end end |
#get(url, headers = {}) ⇒ Object
HTTP::GET request
42 43 44 |
# File 'lib/tiny_grabber.rb', line 42 def get url, headers = {} @agent.fetch url, :get, headers end |
#headers ⇒ Object
Read HEADERS agent attribute
156 157 158 |
# File 'lib/tiny_grabber.rb', line 156 def headers @agent.headers end |
#headers=(headers) ⇒ Object
Set HEADERS agent attribute
165 166 167 |
# File 'lib/tiny_grabber.rb', line 165 def headers= headers @agent.headers = headers end |
#post(url, params = {}, headers = {}) ⇒ Object
HTTP::POST request
63 64 65 |
# File 'lib/tiny_grabber.rb', line 63 def post url, params = {}, headers = {} @agent.fetch url, :post, headers, params end |
#proxy ⇒ Object
Read PROXY agent attribute
130 131 132 |
# File 'lib/tiny_grabber.rb', line 130 def proxy @agent.proxy end |
#proxy=(proxy) ⇒ Object
Set PROXY agent attribute
139 140 141 |
# File 'lib/tiny_grabber.rb', line 139 def proxy= proxy @agent.proxy = proxy end |
#read_timeout ⇒ Object
Read READ_TIMEOUT agent attribute
98 99 100 |
# File 'lib/tiny_grabber.rb', line 98 def read_timeout @agent.read_timeout end |
#read_timeout=(read_timeout) ⇒ Object
Set READ_TIMEOUT agent attribute
107 108 109 |
# File 'lib/tiny_grabber.rb', line 107 def read_timeout= read_timeout @agent.read_timeout = read_timeout end |
#reset ⇒ Object
Call RESET agent method
187 188 189 |
# File 'lib/tiny_grabber.rb', line 187 def reset @agent.reset end |
#user_agent ⇒ Object
Read USER_AGENT agent attribute
114 115 116 |
# File 'lib/tiny_grabber.rb', line 114 def user_agent @agent.user_agent end |
#user_agent=(user_agent) ⇒ Object
Set USER_AGENT agent attribute
123 124 125 |
# File 'lib/tiny_grabber.rb', line 123 def user_agent= user_agent @agent.user_agent = user_agent end |