Skip to content

Commit

Permalink
Namespace errors and middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Oct 7, 2011
1 parent 384737f commit 1245742
Show file tree
Hide file tree
Showing 41 changed files with 345 additions and 291 deletions.
18 changes: 0 additions & 18 deletions lib/faraday/request/gateway.rb

This file was deleted.

36 changes: 0 additions & 36 deletions lib/faraday/request/multipart_with_file.rb

This file was deleted.

18 changes: 0 additions & 18 deletions lib/faraday/request/phoenix.rb

This file was deleted.

24 changes: 0 additions & 24 deletions lib/faraday/request/twitter_oauth.rb

This file was deleted.

24 changes: 0 additions & 24 deletions lib/faraday/response/mashify.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/faraday/response/parse_json.rb

This file was deleted.

45 changes: 0 additions & 45 deletions lib/faraday/response/raise_http_4xx.rb

This file was deleted.

24 changes: 0 additions & 24 deletions lib/faraday/response/raise_http_5xx.rb

This file was deleted.

4 changes: 1 addition & 3 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'twitter/api'
require 'twitter/client'
require 'twitter/configuration'
require 'twitter/error'
require 'twitter/search'

module Twitter
Expand All @@ -20,7 +18,7 @@ def method_missing(method, *args, &block)
new.send(method, *args, &block)
end

def respond_to?(method, include_private = false)
def respond_to?(method, include_private=false)
new.respond_to?(method, include_private) || super(method, include_private)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/twitter/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
require 'twitter/request'

module Twitter
# @private
class API
include Authentication
include Connection
include Request
include Authentication

# @private
attr_accessor *Configuration::VALID_OPTIONS_KEYS

# Creates a new API
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter/authentication.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Twitter
# @private
module Authentication
private
private

# Authentication hash
#
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'twitter/api'

module Twitter
# Wrapper for the Twitter REST API
#
Expand Down
4 changes: 3 additions & 1 deletion lib/twitter/client/block.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'twitter/error/not_found'

module Twitter
class Client
# Defines methods related to blocking and unblocking users
Expand Down Expand Up @@ -53,7 +55,7 @@ def block?(user, options={})
merge_user_into_options!(user, options)
get("/1/blocks/exists.json", options, :raw => true)
true
rescue Twitter::NotFound
rescue Twitter::Error::NotFound
false
end

Expand Down
5 changes: 4 additions & 1 deletion lib/twitter/client/list_members.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'twitter/error/forbidden'
require 'twitter/error/not_found'

module Twitter
class Client
# Defines methods related to list members
Expand Down Expand Up @@ -183,7 +186,7 @@ def list_member?(*args)
merge_user_into_options!(user_to_check, options)
get("/1/lists/members/show.json", options, :raw => true)
true
rescue Twitter::NotFound, Twitter::Forbidden
rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
false
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/twitter/client/list_subscribers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'twitter/error/forbidden'
require 'twitter/error/not_found'

module Twitter
class Client
# Defines methods related to list subscribers
Expand Down Expand Up @@ -136,7 +139,7 @@ def list_subscriber?(*args)
merge_user_into_options!(user_to_check, options)
get("/1/lists/subscribers/show.json", options, :raw => true)
true
rescue Twitter::NotFound, Twitter::Forbidden
rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
false
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/twitter/client/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'twitter/error/not_found'

module Twitter
class Client
# Defines methods related to users
Expand Down Expand Up @@ -35,7 +37,7 @@ def user?(user, options={})
merge_user_into_options!(user, options)
get("/1/users/show.json", options, :raw => true)
true
rescue Twitter::NotFound
rescue Twitter::Error::NotFound
false
end

Expand Down
4 changes: 1 addition & 3 deletions lib/twitter/client/utils.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- encoding: utf-8 -*-
module Twitter
class Client
# @private
module Utils
private
private

# Returns the configured screen name or the screen name of the authenticated user
#
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module Configuration

DEFAULT_FARADAY_OPTIONS = {}.freeze

# @private
attr_accessor *VALID_OPTIONS_KEYS

# When this module is extended, set all configuration options to their default values
Expand Down
35 changes: 17 additions & 18 deletions lib/twitter/connection.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
require 'faraday/request/gateway'
require 'faraday/request/multipart_with_file'
require 'faraday/request/phoenix'
require 'faraday/request/twitter_oauth'
require 'faraday/response/mashify'
require 'faraday/response/parse_json'
require 'faraday/response/raise_http_4xx'
require 'faraday/response/raise_http_5xx'
require 'twitter/request/gateway'
require 'twitter/request/multipart_with_file'
require 'twitter/request/phoenix'
require 'twitter/request/oauth'
require 'twitter/response/mashify'
require 'twitter/response/parse_json'
require 'twitter/response/raise_http_4xx'
require 'twitter/response/raise_http_5xx'

module Twitter
# @private
module Connection
private
private

def connection(options={})
merged_options = faraday_options.merge({
Expand All @@ -24,18 +23,18 @@ def connection(options={})
})

Faraday.new(merged_options) do |builder|
builder.use Faraday::Request::Phoenix if options[:phoenix]
builder.use Faraday::Request::MultipartWithFile
builder.use Faraday::Request::TwitterOAuth, authentication if authenticated?
builder.use Twitter::Request::Phoenix if options[:phoenix]
builder.use Twitter::Request::MultipartWithFile
builder.use Twitter::Request::TwitterOAuth, authentication if authenticated?
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Faraday::Request::Gateway, gateway if gateway
builder.use Faraday::Response::RaiseHttp4xx
builder.use Twitter::Request::Gateway, gateway if gateway
builder.use Twitter::Response::RaiseHttp4xx
unless options[:raw]
builder.use Faraday::Response::Mashify
builder.use Faraday::Response::ParseJson
builder.use Twitter::Response::Mashify
builder.use Twitter::Response::ParseJson
end
builder.use Faraday::Response::RaiseHttp5xx
builder.use Twitter::Response::RaiseHttp5xx
builder.adapter(adapter)
end
end
Expand Down
Loading

0 comments on commit 1245742

Please sign in to comment.