Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xijo/orthrus
Orthrus extends Typhoeus with remote method handling, since it is deprecated in Typhoeus itself.
https://github.com/xijo/orthrus
Last synced: about 2 months ago
JSON representation
Orthrus extends Typhoeus with remote method handling, since it is deprecated in Typhoeus itself.
- Host: GitHub
- URL: https://github.com/xijo/orthrus
- Owner: xijo
- License: other
- Created: 2011-06-15T19:07:02.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-03-21T11:10:04.000Z (almost 12 years ago)
- Last Synced: 2024-10-10T23:05:56.611Z (3 months ago)
- Language: Ruby
- Homepage: http://rubydoc.info/github/xijo/orthrus/master/frames
- Size: 160 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG.markdown
- License: LICENSE
Awesome Lists containing this project
README
# Orthrus
http://github.com/xijo/orthrus
In Greek mythology, Orthrus (Greek: Όρθρος) was a two-headed dog and son of Typhoeus.
He was charged with guarding Geryon's herd of red cattle in Erytheia.[![Build Status](https://secure.travis-ci.org/xijo/orthrus.png?branch=master)](https://travis-ci.org/xijo/orthrus) [![Gem Version](https://badge.fury.io/rb/orthrus.png)](http://badge.fury.io/rb/orthrus)
## Typhoeus
Thanks to the guys who are developing Typhoeus (http://github.com/typhoeus/typhoeus)
Orthrus is a small extension inspired by the original remote method API from Paul Dix
which is deprecated in the current Typhoeus release.It can be used to encapsulate remote method calls in a clean way and provide an
easy interface to work with. All of its functionality is covered by tests as well.## Installation
gem install orthrus
## Usage
In general, Orthrus will accept all options that Typhoeus does. Here are some
examples how to use it:### Simple Example: OpenLibrary
require 'rubygems'
require 'typhoeus'
require 'orthrus'class OpenLibrary
include Orthrus
remote_defaults :base_uri => "http://openlibrary.org/api", :format => "json"define_remote_method :book, :path => '/books'
endbook = OpenLibrary.book(:params => {:bibkeys => "ISBN:0451526538"})
puts book.inspect # Typhoeus::Response### Advanced: Twitter Example with JSON handling and path interpolation
require 'rubygems'
require 'typhoeus'
require 'orthrus'
require 'json'class Twitter
include Orthrus
remote_defaults :on_success => lambda { |response| JSON.parse(response.body) },
:on_failure => lambda { |response| puts "error code: #{response.code}"; {} },
:base_uri => "http://api.twitter.com",
:version => 1define_remote_method :search, :path => "/:version/search.json"
define_remote_method :trends, :path => "/:version/trends/:time_frame.json"
define_remote_method :tweet, :path => "/:version/statuses/update.json",
:method => :post
end# Get all tweets mentioning pluto
tweets = Twitter.search(:params => {:q => "pluto"})# Get all current trends
trends = Twitter.trends(:time_frame => :current)# Submit a tweet. Authentication skipped in example.
Twitter.tweet(:params => {:status => "I #love #planets! :)"})### Hydra
To use Typhoeus' hydra to perform multiple request parallel, you can set the `return_request` option
in `remote_defaults`, `define_remote_method` or even on per request basis to `true`.
Orthrus will return the crafted Typhoeus::Request, including the success and error handling.require 'rubygems'
require 'typhoeus'
require 'orthrus'class WeatherInformation
include Orthrus
remote_defaults :base_uri => "http://wackyweather.test",
:return_request => truedefine_remote_method :city, :path => "/city/:name"
endhydra = Typhoeus::Hydra.new
hydra.queue new_york = WeatherInformation.city(:name => "new_york")
hydra.queue berlin = WeatherInformation.city(:name => "berlin")
hydra.runputs berlin.handled_response
For more information about the hydra feature, visit: http://github.com/dbalatero/typhoeus
## TODO
- no cache handling yet.
## Author
Johannes Opper
## License
Published under the Ruby License. For detailed information see
http://www.ruby-lang.org/en/LICENSE.txt and http://www.ruby-lang.org/en/COPYING.txt