Created
October 15, 2010 01:55
-
-
Save spiegela/627465 to your computer and use it in GitHub Desktop.
So I wanted to create some default options in my parser. I'm not sure if this is how you would do it, but this is what I figured out...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Burst | |
class MailingList | |
include Typhoeus | |
DEFAULT_KEY = 'SECRET' | |
DEFAULT_HOST = '127.0.0.1' | |
DEFAULT_PORT = 3000 | |
remote_defaults :on_success => lambda {|response| Yajl::Parser.parse(response.body)}, | |
:on_failure => lambda {|response| raise "Error code: #{response.code}"}, | |
:base_uri => "http://" | |
define_remote_method :pull_remote, | |
:params => {:expanded => true, :auth_token => DEFAULT_KEY}, | |
:path => ":host::port/mailing_lists/:id.json" | |
def self.pull(args) | |
args[:host] ||= DEFAULT_HOST | |
args[:port] ||= DEFAULT_PORT | |
raise "Cannot execute with providing an ID" unless args[:id] | |
self.pull_remote(args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment