Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from nacyot/google
Add Google link processor(for URL shortening)
- Loading branch information
Showing
17 changed files
with
369 additions
and
6 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,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require './lib/metalbird/authenticators/google.rb' | ||
|
||
authenticator = Metalbird::Authenticator::Google.new | ||
authenticator.authenticate |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require './bin/authenticator' | ||
require './lib/metalbird/authenticators/twitter.rb' | ||
|
||
Metalbird::Authenticator::Twitter.authenticate | ||
url = 'https://api.twitter.com' | ||
authenticator = Metalbird::Authenticator::Twitter.new(url) | ||
authenticator.authenticate |
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,9 @@ | ||
require 'dotenv' | ||
|
||
require './lib/metalbird' | ||
|
||
Dotenv.load | ||
|
||
prosseor = Metalbird::UrlProcessor::Bitly.new(api_key: ENV['BITLY_API_KEY']) | ||
puts prosseor.generate('https://github.com/nacyot') | ||
# puts prosseor.expand('http://bit.ly/1NLH8zy') |
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,8 @@ | ||
require 'dotenv' | ||
|
||
require './lib/metalbird' | ||
|
||
Dotenv.load | ||
|
||
prosseor = Metalbird::UrlProcessor::Google.new(api_key: ENV['GOOGLE_API_KEY']) | ||
puts prosseor.generate('https://github.com/nacyot') |
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,7 @@ | ||
module Metalbird | ||
module UrlProcessor | ||
autoload :Default, 'metalbird/url_processors/default' | ||
autoload :Google, 'metalbird/url_processors/google' | ||
autoload :Bitly, 'metalbird/url_processors/bitly' | ||
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,45 @@ | ||
require 'bitly' | ||
|
||
Bitly.use_api_version_3 | ||
|
||
module Metalbird | ||
module UrlProcessor | ||
class Bitly | ||
RETRY_LIMIT = 3 | ||
|
||
attr_reader :client | ||
|
||
def initialize(opts) | ||
::Bitly.configure do |config| | ||
config.api_version = 3 | ||
config.access_token = opts[:api_key] | ||
end | ||
|
||
@client = ::Bitly.client | ||
end | ||
|
||
def generate(link) | ||
retry_counter ||= 0 | ||
@client.shorten(link).short_url | ||
rescue => error | ||
Metalbird::Logger.error(error) | ||
retry_counter += 1 | ||
retry if retry_counter <= RETRY_LIMIT | ||
raise URLShortenFailError | ||
end | ||
|
||
def expand(shorten_link) | ||
retry_counter ||= 0 | ||
@client.expand(shorten_link).long_url | ||
rescue => error | ||
Metalbird::Logger.error(error) | ||
retry_counter += 1 | ||
retry if retry_counter <= RETRY_LIMIT | ||
raise URLExpandFailError | ||
end | ||
end | ||
|
||
class URLShortenFailError < StandardError; end | ||
class URLExpandFailError < StandardError; 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,13 @@ | ||
module Metalbird | ||
module UrlProcessor | ||
class Default | ||
def generate(link) | ||
link | ||
end | ||
|
||
def expand(link) | ||
link | ||
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,39 @@ | ||
require 'googl' | ||
|
||
module Metalbird | ||
module UrlProcessor | ||
class Google | ||
RETRY_LIMIT = 3 | ||
|
||
attr_reader :client | ||
|
||
def initialize(opts) | ||
@client = Googl | ||
@key = opts[:api_key] | ||
end | ||
|
||
def generate(link) | ||
retry_counter ||= 0 | ||
Googl.shorten(link, nil, @key).short_url | ||
rescue => error | ||
Metalbird::Logger.error(error) | ||
retry_counter += 1 | ||
retry if retry_counter <= RETRY_LIMIT | ||
raise URLShortenFailError | ||
end | ||
|
||
def expand(shorten_link) | ||
retry_counter ||= 0 | ||
Googl.expand(shorten_link, key: @key).long_url | ||
rescue => error | ||
Metalbird::Logger.error(error) | ||
retry_counter += 1 | ||
retry if retry_counter <= RETRY_LIMIT | ||
raise URLExpandFailError | ||
end | ||
end | ||
|
||
class URLShortenFailError < StandardError; end | ||
class URLExpandFailError < StandardError; 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
Empty file.
Oops, something went wrong.