Skip to content

Instantly share code, notes, and snippets.

@drochetti
Created September 18, 2014 15:49
Show Gist options
  • Save drochetti/9f30aa3dbc244dc03f04 to your computer and use it in GitHub Desktop.
Save drochetti/9f30aa3dbc244dc03f04 to your computer and use it in GitHub Desktop.
ruby rest client poc
module Blowout
module Api
Client = RC::Builder.client do
use RC::DefaultSite, 'http://localhost:7272'
use RC::JsonResponse, true
use Blowout::Api::HashResponse
end
end
end
class Blowout::Api::Client
def spiders
endpoint = class << Blowout::Api::Spider
# def self.resource_name
# super
# end
end
puts endpoint
puts endpoint.inspect
puts endpoint.methods
endpoint.set_client self
endpoint
end
end
@drochetti
Copy link
Author

The idea would be to use the client like this:

client = Blowout::Api::Client.new url: 'http://api.owndomain.com'

spider = client.spiders.find 123 # will send a GET request to /spiders/123
spider = Blowout::Api::Spider.find 123 # or if you want to use the default client/domain
puts spider # instance of Spider
puts spider.name # can access hash properties of the JSON response because of Hashie::Mash
spider.update(name: 'test') # will send a PUT request to /spiders/123

@drochetti
Copy link
Author

The main problem is how to 'inject' different instances of Client as a class variable of each Resource/Model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment