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.7'
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.
-
#verify_mode=(verify_mode) ⇒ Object
Set verify_mode.
Constructor Details
#initialize ⇒ TinyGrabber
Initialize a new TinyGrabber user agent.
16 17 18 |
# File 'lib/tiny_grabber.rb', line 16 def initialize @agent = TinyGrabber::Agent.new end |
Class Method Details
.get(url, config = {}) ⇒ Object
Singleton > HTTP::GET request
50 51 52 53 |
# File 'lib/tiny_grabber.rb', line 50 def self.get url, config = {} initialize config @agent.fetch url, :get end |
.initialize(config = {}) ⇒ Object
Singleton > Initialize a new TinyGrabber user agent.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tiny_grabber.rb', line 23 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
72 73 74 75 |
# File 'lib/tiny_grabber.rb', line 72 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
140 141 142 |
# File 'lib/tiny_grabber.rb', line 140 def basic_auth username, password @agent.basic_auth = { username: username, password: password } end |
#cookies ⇒ Object
Read COOKIES agent attribute
163 164 165 |
# File 'lib/tiny_grabber.rb', line 163 def @agent. end |
#cookies=(cookies) ⇒ Object
Set COOKIES agent attribute
172 173 174 |
# File 'lib/tiny_grabber.rb', line 172 def @agent. = end |
#debug=(debug) ⇒ Object
Set DEBUG flag
82 83 84 |
# File 'lib/tiny_grabber.rb', line 82 def debug= debug @agent.debug = debug end |
#get(url, headers = {}) ⇒ Object
HTTP::GET request
41 42 43 |
# File 'lib/tiny_grabber.rb', line 41 def get url, headers = {} @agent.fetch url, :get, headers end |
#headers ⇒ Object
Read HEADERS agent attribute
147 148 149 |
# File 'lib/tiny_grabber.rb', line 147 def headers @agent.headers end |
#headers=(headers) ⇒ Object
Set HEADERS agent attribute
156 157 158 |
# File 'lib/tiny_grabber.rb', line 156 def headers= headers @agent.headers = headers end |
#post(url, params = {}, headers = {}) ⇒ Object
HTTP::POST request
62 63 64 |
# File 'lib/tiny_grabber.rb', line 62 def post url, params = {}, headers = {} @agent.fetch url, :post, headers, params end |
#proxy ⇒ Object
Read PROXY agent attribute
121 122 123 |
# File 'lib/tiny_grabber.rb', line 121 def proxy @agent.proxy end |
#proxy=(proxy) ⇒ Object
Set PROXY agent attribute
130 131 132 |
# File 'lib/tiny_grabber.rb', line 130 def proxy= proxy @agent.proxy = proxy end |
#read_timeout ⇒ Object
Read READ_TIMEOUT agent attribute
89 90 91 |
# File 'lib/tiny_grabber.rb', line 89 def read_timeout @agent.read_timeout end |
#read_timeout=(read_timeout) ⇒ Object
Set READ_TIMEOUT agent attribute
98 99 100 |
# File 'lib/tiny_grabber.rb', line 98 def read_timeout= read_timeout @agent.read_timeout = read_timeout end |
#reset ⇒ Object
Call RESET agent method
178 179 180 |
# File 'lib/tiny_grabber.rb', line 178 def reset @agent.reset end |
#user_agent ⇒ Object
Read USER_AGENT agent attribute
105 106 107 |
# File 'lib/tiny_grabber.rb', line 105 def user_agent @agent.user_agent end |
#user_agent=(user_agent) ⇒ Object
Set USER_AGENT agent attribute
114 115 116 |
# File 'lib/tiny_grabber.rb', line 114 def user_agent= user_agent @agent.user_agent = user_agent end |
#verify_mode=(verify_mode) ⇒ Object
Set verify_mode
187 188 189 |
# File 'lib/tiny_grabber.rb', line 187 def verify_mode= verify_mode @agent.verify_mode = verify_mode end |