class TinyGrabber

Main class for TinyGrabber

Net::HTTP agent for TinyGrabber Initialize connect with Resource Setting connect attributes

Constants

VERSION

Version number

Public Class Methods

get(url, config = {}) click to toggle source

Singleton > HTTP::GET request

@param url Resource link @param headers Request header

# File lib/tiny_grabber.rb, line 48
def self.get(url, config = {})
  initialize config
  @agent.fetch url, :get
end
initialize(config = {}) click to toggle source

Singleton > Initialize a new TinyGrabber user agent.

# File lib/tiny_grabber.rb, line 21
def self.initialize(config = {})
  @agent = TinyGrabber::Agent.new

  @agent.perfect_url = config[:perfect_url] if config[:perfect_url]
  @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.cookies = config[:cookies] if config[:cookies]
end
new() click to toggle source

Initialize a new TinyGrabber user agent.

# File lib/tiny_grabber.rb, line 15
def initialize
  @agent = TinyGrabber::Agent.new
end
post(url, params = {}, config = {}) click to toggle source

Singleton > HTTP::GET request

@param url Resource link @param headers Request header

# File lib/tiny_grabber.rb, line 68
def self.post(url, params = {}, config = {})
  initialize config
  @agent.fetch url, :post, {}, params
end

Public Instance Methods

basic_auth(username, password) click to toggle source

Set BASIC_AUTH agent attribute

@param username Authentification username @param password Authentification password

# File lib/tiny_grabber.rb, line 143
def basic_auth(username, password)
  @agent.basic_auth = { username: username, password: password }
end
cookies() click to toggle source

Read COOKIES agent attribute

# File lib/tiny_grabber.rb, line 163
def cookies
  @agent.cookies
end
cookies=(cookies) click to toggle source

Set COOKIES agent attribute

@param cookies Request cookies

# File lib/tiny_grabber.rb, line 171
def cookies=(cookies)
  @agent.cookies = cookies
end
debug=(debug) click to toggle source

Set DEBUG flag

@param debug Flag to start debug

# File lib/tiny_grabber.rb, line 77
def debug=(debug)
  @agent.debug = debug
end
follow_location=(follow_location) click to toggle source

Set follow_location

@param follow_location Follow location flag

# File lib/tiny_grabber.rb, line 193
def follow_location=(follow_location)
  @agent.follow_location = follow_location
end
get(url, headers = {}) click to toggle source

HTTP::GET request

@param url Resource link @param headers Request header

# File lib/tiny_grabber.rb, line 39
def get(url, headers = {})
  @agent.fetch url, :get, headers
end
headers() click to toggle source

Read HEADERS agent attribute

# File lib/tiny_grabber.rb, line 149
def headers
  @agent.headers.to_hash
end
headers=(headers) click to toggle source

Set HEADERS agent attribute

@param headers Request headers

# File lib/tiny_grabber.rb, line 157
def headers=(headers)
  @agent.headers = headers
end
perfect_url() click to toggle source

Read perfect_url agent attribute

# File lib/tiny_grabber.rb, line 83
def perfect_url
  @agent.perfect_url
end
perfect_url=(perfect_url) click to toggle source

Set perfect_url agent attribute

@param perfect_url Removes additional processing url

# File lib/tiny_grabber.rb, line 91
def perfect_url=(perfect_url)
  @agent.perfect_url = perfect_url
end
post(url, params = {}, headers = {}) click to toggle source

HTTP::POST request

@param url Resource link @param params Request post data @param headers Request header

# File lib/tiny_grabber.rb, line 59
def post(url, params = {}, headers = {})
  @agent.fetch url, :post, headers, params
end
proxy() click to toggle source

Read PROXY agent attribute

# File lib/tiny_grabber.rb, line 126
def proxy
  @agent.proxy
end
proxy=(proxy) click to toggle source

Set PROXY agent attribute

@param proxy Proxy configuration

# File lib/tiny_grabber.rb, line 134
def proxy=(proxy)
  @agent.proxy = proxy
end
read_timeout() click to toggle source

Read READ_TIMEOUT agent attribute

# File lib/tiny_grabber.rb, line 98
def read_timeout
  @agent.read_timeout
end
read_timeout=(read_timeout) click to toggle source

Set READ_TIMEOUT agent attribute

@param read_timeout Waiting time to reading

# File lib/tiny_grabber.rb, line 106
def read_timeout=(read_timeout)
  @agent.read_timeout = read_timeout
end
reset() click to toggle source

Call RESET agent method

# File lib/tiny_grabber.rb, line 177
def reset
  @agent.reset
end
uri() click to toggle source

Read URI

# File lib/tiny_grabber.rb, line 199
def uri
  @agent.uri
end
user_agent() click to toggle source

Read USER_AGENT agent attribute

# File lib/tiny_grabber.rb, line 112
def user_agent
  @agent.user_agent
end
user_agent=(user_agent) click to toggle source

Set USER_AGENT agent attribute

@param user_agent Web browser name

# File lib/tiny_grabber.rb, line 120
def user_agent=(user_agent)
  @agent.user_agent = user_agent
end
verify_mode=(verify_mode) click to toggle source

Set verify_mode

@param verify_mode SSL verify mode

# File lib/tiny_grabber.rb, line 185
def verify_mode=(verify_mode)
  @agent.verify_mode = verify_mode
end