Project

phearb

0.0
No commit activity in last 3 years
No release in over 3 years
Simplified connection to phear servers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 9.0
~> 10.0
~> 3.0
~> 2.0

Runtime

 Project Readme

Phearb

Gem Version Build Status

Phearb is a library for handling connections to phear servers. It allows ruby apps to easy fetch sites source code using phear.

Installation

Add this line to your application's Gemfile:

gem 'phearb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install phearb

Configuration

Put these lines in the configuration section of you app. In rails you should probably add an initializer or put in one of your environment files:

Phearb.configure do |config|
  config.host = <host> # Defaults to 'localhost'
  config.port = <port> # Defaults to 8100
  config.timeout <timeout_in_seconds> # Defaults to 60
end

Usage

response = Phearb.fetch('http://www.google.com')
puts response.content if response.success

Simply calling Phearb.fetch(<url>) will do the job. It returns an Phearb::Response object wrapping the phearb server response with one method per key:

{
  "success": true,
  "input_url": "http://such-website.com",
  "final_url": "http://www.such-website.com/",
  "had_js_errors": false,
  "content": "<html>rendered</html>",
  "request_headers": {},
  "response_headers": {
    "date": "Sun, 08 Feb 2015 15:11:22 GMT",
    "content-encoding": "gzip",
    "cache-control": "max-age=60",
    "content-type": "text/html; charset=utf-8"
  }
}

Then if you need access to the final_url you can call response.final_url.

Passing options

As phear support optional parameters, so does the gem. The fetch method call supports passing an second parameter with a hash of options. For a list of available options see phear's README since the names are consistent.

Phearb.fetch('http://www.google.com', force: true, parse_delay: 500)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/joaquinrulin/phearb.