Class: Abrio::Client
- Inherits:
-
Object
- Object
- Abrio::Client
- Defined in:
- lib/abrio/client.rb
Overview
Client proxy for Abr.io API.
Constant Summary collapse
- DEFAULT_PARAMS =
{:format => "xml", :version => "1.0"}
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#login ⇒ Object
Returns the value of attribute login.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Use the following options to initialize your client: [uri] - Default: “abr.io/api/links” [login] - Your login from Zapt.In.
-
#shorten(long_url, options = {}) ⇒ Object
Shorten an url.
Constructor Details
#initialize(options = {}) ⇒ Client
Use the following options to initialize your client:
[uri] - Default: "abr.io/api/links"
[login] - Your login from Zapt.In. See: http://abr.io/pages/api
[key] - Your key from Zapt.In. See: http://abr.io/pages/api
12 13 14 15 16 |
# File 'lib/abrio/client.rb', line 12 def initialize( = {}) @uri = [:uri] || "http://abr.io/api/links" @login = [:login] @key = [:key] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/abrio/client.rb', line 4 def key @key end |
#login ⇒ Object
Returns the value of attribute login.
4 5 6 |
# File 'lib/abrio/client.rb', line 4 def login @login end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/abrio/client.rb', line 4 def uri @uri end |
Instance Method Details
#shorten(long_url, options = {}) ⇒ Object
Shorten an url.
- long_url
-
url you want to shorten.
- options
-
Optional Hash. You can pass the following keys:
- uri
-
Default: “abr.io/api/links”
-
- login
-
Your login from Zapt.In. See: abr.io/pages/api
-
- key
-
Your key from Zapt.In. See: abr.io/pages/api
-
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/abrio/client.rb', line 24 def shorten(long_url, = {}) return nil if long_url.nil? || long_url == "" @uri = .delete(:uri) || @uri params = {:login => .delete(:login) || @login, :key => .delete(:key) || @key}.merge(DEFAULT_PARAMS) params[:longUrl] = long_url begin response = Abrio::Request.get("#{self.uri}/shorten", params) Abrio::Url.parse(response) rescue Abrio::Error => e Abrio::Url.new(:status_code => "ERROR", :errorMessage => e., :error_code => -1) end end |