Code Monkey home page Code Monkey logo

phearb's Introduction

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.

phearb's People

Contributors

joaquinmoreira avatar

Stargazers

Tom Aizenberg avatar Rohit Trivedi avatar Alberto Holts avatar Cristóbal Castillo avatar David avatar

Watchers

Daniel Ortega Norambuena avatar

Forkers

rodrigoieh

phearb's Issues

Implement phearb optional arguments on fetch call

Phear current's README states this options are available:

- fetch_url=<url-encoded-string> required The URL to fetch, encoded as it would be by e.g. encodeURIComponent().
- parse_delay=<milliseconds> Time to wait before returning, allowing scripts and AJAX calls to run. Default: as set in config.json.
- force=[false|true] Force a cache refresh. Default: false.
- raw=[false|true] Return the raw body instead of a JSON. Default: false.
- get_requests=[false|true] In the JSON, include all HTTP requests generated by the page. Default: false.
- get_cookies=[false|true] In the JSON, include all cookies generated by the page. Default: false.
- headers=<URL-encoded JSON> Add additional headers to the request. Default: {}.
- cache_namespace=<string> A namespace to use on the cache. Can be useful for multi-client settings. Default: global-.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.