Skip to content

Ruby gem for simplifying connection to phear servers

Notifications You must be signed in to change notification settings

joaquinmoreira/phearb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Ruby gem for simplifying connection to phear servers

Resources

Stars

Watchers

Forks

Packages

No packages published