Class: ZaptIn::Client
- Inherits:
-
Object
- Object
- ZaptIn::Client
- Defined in:
- lib/zapt_in/client.rb
Overview
Client proxy for Zapt.In or 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: “zapt.in/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: "zapt.in/api/links"
[login] - Your login from Zapt.In. See: http://zapt.in/pages/api
[key] - Your key from Zapt.In. See: http://zapt.in/pages/api
13 14 15 16 17 |
# File 'lib/zapt_in/client.rb', line 13 def initialize( = {}) @uri = [:uri] || "http://zapt.in/api/links" @login = [:login] @key = [:key] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/zapt_in/client.rb', line 5 def key @key end |
#login ⇒ Object
Returns the value of attribute login.
5 6 7 |
# File 'lib/zapt_in/client.rb', line 5 def login @login end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/zapt_in/client.rb', line 5 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: “zapt.in/api/links”
-
- login
-
Your login from Zapt.In. See: zapt.in/pages/api
-
- key
-
Your key from Zapt.In. See: zapt.in/pages/api
-
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zapt_in/client.rb', line 25 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 = ZaptIn::Request.get("#{self.uri}/shorten", params) ZaptIn::Url.parse(response) rescue ZaptIn::Error => e ZaptIn::Url.new(:status_code => "ERROR", :errorMessage => e., :error_code => -1) end end |