Class: TinyGrabber
- Inherits:
-
Object
- Object
- TinyGrabber
- Defined in:
- lib/tiny_grabber.rb,
lib/tiny_grabber/agent.rb,
lib/tiny_grabber/version.rb
Overview
Net::HTTP agent for TinyGrabber Initialize connect with Resource Setting connect attributes
Defined Under Namespace
Classes: Agent
Constant Summary collapse
- VERSION =
Version number
'0.3.0'.freeze
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.
-
#follow_location=(follow_location) ⇒ Object
Set follow_location.
-
#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.
15 16 17 |
# File 'lib/tiny_grabber.rb', line 15 def initialize @agent = TinyGrabber::Agent.new end |
Class Method Details
.get(url, config = {}) ⇒ Object
Singleton > HTTP::GET request
47 48 49 50 |
# File 'lib/tiny_grabber.rb', line 47 def self.get(url, config = {}) initialize config @agent.fetch url, :get end |
.initialize(config = {}) ⇒ Object
Singleton > Initialize a new TinyGrabber user agent.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tiny_grabber.rb', line 21 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
67 68 69 70 |
# File 'lib/tiny_grabber.rb', line 67 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
127 128 129 |
# File 'lib/tiny_grabber.rb', line 127 def basic_auth(username, password) @agent.basic_auth = { username: username, password: password } end |
#cookies ⇒ Object
Read COOKIES agent attribute
147 148 149 |
# File 'lib/tiny_grabber.rb', line 147 def @agent. end |
#cookies=(cookies) ⇒ Object
Set COOKIES agent attribute
155 156 157 |
# File 'lib/tiny_grabber.rb', line 155 def () @agent. = end |
#debug=(debug) ⇒ Object
Set DEBUG flag
76 77 78 |
# File 'lib/tiny_grabber.rb', line 76 def debug=(debug) @agent.debug = debug end |
#follow_location=(follow_location) ⇒ Object
Set follow_location
177 178 179 |
# File 'lib/tiny_grabber.rb', line 177 def follow_location=(follow_location) @agent.follow_location = follow_location end |
#get(url, headers = {}) ⇒ Object
HTTP::GET request
38 39 40 |
# File 'lib/tiny_grabber.rb', line 38 def get(url, headers = {}) @agent.fetch url, :get, headers end |
#headers ⇒ Object
Read HEADERS agent attribute
133 134 135 |
# File 'lib/tiny_grabber.rb', line 133 def headers @agent.headers end |
#headers=(headers) ⇒ Object
Set HEADERS agent attribute
141 142 143 |
# File 'lib/tiny_grabber.rb', line 141 def headers=(headers) @agent.headers = headers end |
#post(url, params = {}, headers = {}) ⇒ Object
HTTP::POST request
58 59 60 |
# File 'lib/tiny_grabber.rb', line 58 def post(url, params = {}, headers = {}) @agent.fetch url, :post, headers, params end |
#proxy ⇒ Object
Read PROXY agent attribute
110 111 112 |
# File 'lib/tiny_grabber.rb', line 110 def proxy @agent.proxy end |
#proxy=(proxy) ⇒ Object
Set PROXY agent attribute
118 119 120 |
# File 'lib/tiny_grabber.rb', line 118 def proxy=(proxy) @agent.proxy = proxy end |
#read_timeout ⇒ Object
Read READ_TIMEOUT agent attribute
82 83 84 |
# File 'lib/tiny_grabber.rb', line 82 def read_timeout @agent.read_timeout end |
#read_timeout=(read_timeout) ⇒ Object
Set READ_TIMEOUT agent attribute
90 91 92 |
# File 'lib/tiny_grabber.rb', line 90 def read_timeout=(read_timeout) @agent.read_timeout = read_timeout end |
#reset ⇒ Object
Call RESET agent method
161 162 163 |
# File 'lib/tiny_grabber.rb', line 161 def reset @agent.reset end |
#user_agent ⇒ Object
Read USER_AGENT agent attribute
96 97 98 |
# File 'lib/tiny_grabber.rb', line 96 def user_agent @agent.user_agent end |
#user_agent=(user_agent) ⇒ Object
Set USER_AGENT agent attribute
104 105 106 |
# File 'lib/tiny_grabber.rb', line 104 def user_agent=(user_agent) @agent.user_agent = user_agent end |
#verify_mode=(verify_mode) ⇒ Object
Set verify_mode
169 170 171 |
# File 'lib/tiny_grabber.rb', line 169 def verify_mode=(verify_mode) @agent.verify_mode = verify_mode end |