Class: Mush::Services::Owly
- Inherits:
-
AuthenticatedService
- Object
- Mush::Service
- AuthenticatedService
- Mush::Services::Owly
- Defined in:
- lib/mush/services/owly.rb
Instance Attribute Summary
Attributes inherited from AuthenticatedService
Class Method Summary collapse
-
.response_parse ⇒ Object
Ow.ly api bug, response is in json, but response type is html so force parse.
Instance Method Summary collapse
Methods inherited from AuthenticatedService
Methods inherited from Mush::Service
Constructor Details
This class inherits a constructor from Mush::AuthenticatedService
Class Method Details
.response_parse ⇒ Object
Ow.ly api bug, response is in json, but response type is html so force parse
12 13 14 15 16 |
# File 'lib/mush/services/owly.rb', line 12 def self.response_parse Proc.new do |body, format| JSON.parse(body) end end |
Instance Method Details
#shorten(url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mush/services/owly.rb', line 19 def shorten(url) invalid_uri_msg = "Please provide a valid URI, including http://" invalid_auth_msg = "Invalid Authorization Data, please provide apikey" raise InvalidURI.new invalid_uri_msg if url.empty? raise InvalidAuthorizationData.new(invalid_auth_msg) if apikey.empty? = {:format => 'json'} [:query] = {:apiKey => self.apikey, :longUrl => url} response = get('/shorten', ) response.code == 200 ? response["results"]["shortUrl"] : response["error"] end |