-
-
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.
Merge branch 'master' of github.com:jnunemaker/twitter
- Loading branch information
Showing
17 changed files
with
207 additions
and
252 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require File.expand_path('../connection', __FILE__) | ||
require File.expand_path('../request', __FILE__) | ||
require File.expand_path('../authentication', __FILE__) | ||
|
||
module Twitter | ||
class API | ||
attr_accessor *Configuration::VALID_OPTIONS_KEYS | ||
|
||
def initialize(options={}) | ||
options = Twitter.options.merge(options) | ||
Configuration::VALID_OPTIONS_KEYS.each do |key| | ||
send("#{key}=", options[key]) | ||
end | ||
end | ||
|
||
include Connection | ||
include Request | ||
include Authentication | ||
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,18 @@ | ||
module Twitter | ||
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 |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
require 'faraday_middleware' | ||
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f} | ||
|
||
module Twitter | ||
module Connection | ||
private | ||
|
||
def connection(raw=false) | ||
options = { | ||
:headers => {:user_agent => user_agent}, | ||
:ssl => {:verify => false}, | ||
:url => api_endpoint | ||
} | ||
|
||
Faraday::Connection.new(options) do |builder| | ||
builder.use Faraday::Request::Multipart | ||
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 |
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,38 @@ | ||
module Twitter | ||
module Request | ||
def get(path, options={}, raw=false) | ||
request(:get, path, options, raw) | ||
end | ||
|
||
def post(path, options={}, raw=false) | ||
request(:post, path, options, raw) | ||
end | ||
|
||
def put(path, options={}, raw=false) | ||
request(:put, path, options, raw) | ||
end | ||
|
||
def delete(path, options={}, raw=false) | ||
request(:delete, path, options, raw) | ||
end | ||
|
||
private | ||
|
||
def request(method, path, options, raw) | ||
response = connection(raw).send(method) do |request| | ||
case method | ||
when :get, :delete | ||
request.url(formatted_path(path), options) | ||
when :post, :put | ||
request.path = formatted_path(path) | ||
request.body = options | ||
end | ||
end | ||
raw ? response : response.body | ||
end | ||
|
||
def formatted_path(path) | ||
[path, format].compact.join('.') | ||
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.