-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: Unifity Authentication, Connection, and Request modules Closes #106
- Loading branch information
Showing
9 changed files
with
517 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Twitter | ||
class Search | ||
module Authentication | ||
private | ||
def authentication | ||
{ | ||
:consumer_key => consumer_key, | ||
:consumer_secret => consumer_secret, | ||
:token => oauth_token, | ||
:token_secret => oauth_token_secret | ||
} | ||
end | ||
|
||
def authenticated? | ||
authentication.values.all? | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'faraday' | ||
require 'faraday_middleware' | ||
Dir[File.expand_path('../../../faraday/*.rb', __FILE__)].each{|f| require f} | ||
|
||
module Twitter | ||
class Search | ||
module Connection | ||
private | ||
|
||
def connection(raw=false) | ||
options = { | ||
:headers => {:user_agent => user_agent}, | ||
:ssl => {:verify => false}, | ||
:url => endpoint | ||
} | ||
|
||
Faraday::Connection.new(options) do |builder| | ||
builder.use Faraday::Request::OAuth, authentication if authenticated? | ||
builder.adapter(adapter) | ||
builder.use Faraday::Response::RaiseHttp5xx | ||
builder.use Faraday::Response::Parse unless raw | ||
builder.use Faraday::Response::RaiseHttp4xx | ||
builder.use Faraday::Response::Mashify unless raw | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Twitter | ||
class Search | ||
module Request | ||
def get(path, options={}, raw=false) | ||
request(:get, path, options, raw) | ||
end | ||
|
||
private | ||
|
||
def request(method, path, options, raw) | ||
response = connection(raw).send(method) do |request| | ||
request.url(formatted_path(path), options) | ||
end | ||
raw ? response : response.body | ||
end | ||
|
||
def formatted_path(path) | ||
[path, format].compact.join('.') | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.