Skip to content

Instantly share code, notes, and snippets.

macten:activeresource sfaxon$ git diff
diff --git a/lib/active_resource/base/base_class_methods.rb b/lib/active_resource/base/base_class_methods.rb
index c90a304..cca30d6 100644
--- a/lib/active_resource/base/base_class_methods.rb
+++ b/lib/active_resource/base/base_class_methods.rb
@@ -292,11 +292,7 @@ module ActiveResource
# middleware.swap(Faraday::Adapter::NetHttp, Faraday::Adapter::NetHttpPersistent)
# this may not stick around, it presents two ways of changing the adapter and format
def middleware
- if connection.builder.locked?
require 'faraday'
require 'debugger'
# require File.join(File.dirname(__FILE__), 'lib/active_resource')
module ActiveResource
module Request
class PerRequestToken < Faraday::Middleware
def initialize(app = nil, options = {})
@per_options = options
require 'faraday'
require 'debugger'
@connection = Faraday.new("http://localhost") do |builder|
# builder.use Faraday::Request::BasicAuthentication.header('user', 'pass')
builder.adapter :test do |stub|
stub.get('/something') {[ 200, {}, 'yay' ]}
end
end
module ActiveResource
module Middleware
class ParseJSON < Faraday::Middleware
# Parse the response body
#
# @param [String] body The response body
# @return [Mixed] the parsed response
def decode(json)
Formats.remove_root(ActiveSupport::JSON.decode(json))
require 'faraday'
module Faraday
class Adapter
# connection = Faraday.new do |builder|
# builder.adapter :instance_test do |stub|
# stub.get('/ebi') {[ 200, {}, 'init stub' ]}
# end
# end
#
@sfaxon
sfaxon / gist:2597181
Created May 4, 2012 19:28
ActiveResource faraday middleware access
diff --git a/Rakefile b/Rakefile
index 2e18dd9..d4e6157 100755
--- a/Rakefile
+++ b/Rakefile
@@ -25,6 +25,13 @@ namespace :test do
end
end
+namespace :test do
+ task :single do
stub.get('/weather.json') {[200, {}, weather.to_json]}
stub.get('/weather.json?degrees=fahrenheit') {[200, {}, weather.merge(:temperature => 100).to_json]}
stub.post('/weather.json') {[201, {'Location' => '/weather.json'}, weather.to_json]}
stub.delete('/weather.json') {[200, {}, nil]}
stub.put('/weather.json') {[204, {}, nil]}
@sfaxon
sfaxon / gist:2511491
Created April 27, 2012 18:15
builder
require 'debugger'
class Builder
def initialize(&block)
@wares = []
@runner = nil
instance_eval(&block) if block_given?
end
def use(middleware, *args, &block)
@wares << if block_given?
@sfaxon
sfaxon / gist:2280859
Created April 2, 2012 04:57
rbx crash
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
[[Backtrace]]
0 rbx 0x000000010194f496 _ZN8rubiniusL12segv_handlerEi + 486
1 libsystem_c.dylib 0x00007fff900e2cfa _sigtramp + 26
2 libcrypto.1.0.0.dylib 0x000000010516431c c2i_ASN1_INTEGER + 476
3 openssl.bundle 0x000000010504e14d ossl_ssl_verify_callback + 45
4 libcrypto.1.0.0.dylib 0x0000000105184099 X509_verify_cert + 1273