Skip to content

Commit

Permalink
faraday 0.8 must have changed the way they handle urls
Browse files Browse the repository at this point in the history
had a bunch of failing tests due to unescaped uris
  • Loading branch information
rauhryan committed May 5, 2012
1 parent fd41b65 commit 9f466a7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ghee.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'yajl-ruby'
s.add_development_dependency 'rake'
s.add_development_dependency 'json_pure'
s.add_development_dependency 'rspec', '~>2.0'
s.add_development_dependency 'rspec', '~>2.9.0'
s.add_development_dependency 'webmock'
s.add_development_dependency 'vcr'
s.add_development_dependency 'ZenTest'
Expand Down
1 change: 1 addition & 0 deletions lib/ghee.rb
@@ -1,6 +1,7 @@
# encoding: UTF-8
require 'ghee/version'
require 'ghee/connection'
require 'ghee/uri_escape'
require 'ghee/resource_proxy'
require 'ghee/state_methods'
require 'ghee/api/authorizations'
Expand Down
1 change: 1 addition & 0 deletions lib/ghee/connection.rb
Expand Up @@ -22,6 +22,7 @@ def initialize(hash={})
super('https://api.github.com') do |builder|
builder.use FaradayMiddleware::EncodeJson
builder.use FaradayMiddleware::ParseJson
# builder.use Ghee::Middleware::UriEscape
builder.adapter Faraday.default_adapter
end

Expand Down
6 changes: 3 additions & 3 deletions lib/ghee/state_methods.rb
Expand Up @@ -6,23 +6,23 @@ module CUD
# return json
#
def create(attributes)
connection.post(path_prefix,attributes).body
connection.post(URI.escape(path_prefix),attributes).body
end

# Patchs
#
# return json
#
def patch(attributes)
connection.patch(path_prefix, attributes).body
connection.patch(URI.escape(path_prefix), attributes).body
end

# Destroys
#
# return boolean
#
def destroy
connection.delete(path_prefix).status == 204
connection.delete(URI.escape(path_prefix)).status == 204
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/ghee/uri_escape.rb
@@ -0,0 +1,11 @@
class Ghee
module Middleware
class UriEscape < Faraday::Middleware
def call(env)

env[:url] = URI.parse(URI.escape(env[:url].to_s))
@app.call(env)
end
end
end
end
1 change: 0 additions & 1 deletion spec/ghee/api/events_spec.rb
Expand Up @@ -12,7 +12,6 @@ def should_be_an_event(event)
EventTypes.should include(event['type'])
event['repo'].should be_instance_of(Hash)
event['actor'].should be_instance_of(Hash)
event['org'].should be_instance_of(Hash)
event['created_at'].should_not be_nil
end

Expand Down

0 comments on commit 9f466a7

Please sign in to comment.