class Shortly::Clients::Snim
Attributes
apiKey[RW]
login = “<your login>” apiKey = “<your apiKey>”
login[RW]
login = “<your login>” apiKey = “<your apiKey>”
Public Class Methods
analytics(short_id, options = {})
click to toggle source
gets analytics
# File lib/shortly/clients/snim.rb, line 53 def self.analytics(short_id, options = {}) options = {:snipapi => self.apiKey,:snipuser => self.login, :snipid => short_id}.merge(options) validate!(options) response = post("/getsnipdetails", post_params(options)) OpenStruct.new(unescape_url(response)["snip"]) end
expand(short_url, options = {})
click to toggle source
expands provided url by making call to bitly api with given options.
# File lib/shortly/clients/snim.rb, line 48 def self.expand(short_url, options = {}) analytics(short_url.gsub('http://sn.im/', ''), options) end
shorten(url, options = {})
click to toggle source
shorts provided url by making call to bitly api with given options.
# File lib/shortly/clients/snim.rb, line 39 def self.shorten(url, options = {}) validate_uri!(url) options = {:snipapi => self.apiKey,:snipuser => self.login, :sniplink => url}.merge(options) validate!(options) response = post("/getsnip", post_params(options)) OpenStruct.new(response["snip"].merge(:shortUrl => response["snip"]["id"])) end
Private Class Methods
unescape_url(response)
click to toggle source
# File lib/shortly/clients/snim.rb, line 67 def self.unescape_url(response) response["snip"]["url"] = CGI.unescape(response["snip"]["url"]) if response["snip"] response end
validate!(options)
click to toggle source
# File lib/shortly/clients/snim.rb, line 62 def self.validate!(options) raise NotAuthorizedError.new("Credentials required(login and apiKey)") unless options.authenticable?(:snipapi, :snipuser) end