Class: SignalApi::ShortUrl
- Inherits:
-
SignalHttpApi
- Object
- SignalHttpApi
- SignalApi::ShortUrl
- Includes:
- ApiMock
- Defined in:
- lib/signal_api/short_url.rb,
lib/signal_api/mocks/short_url.rb
Overview
Manage short URLs via Signal’s URL shortening service
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
The domain of the short URL.
-
#id ⇒ Object
readonly
The ID of the shortend URL on the Signal platform.
-
#short_url ⇒ Object
readonly
The shortened URL.
-
#target_url ⇒ Object
readonly
The target URL that was shortened.
Class Method Summary collapse
-
.create(target, domain) ⇒ ShortUrl
Create a short URL for the provided target URL.
Instance Method Summary collapse
-
#initialize(id, target_url, short_url, domain) ⇒ ShortUrl
constructor
A new instance of ShortUrl.
Methods included from ApiMock
Constructor Details
#initialize(id, target_url, short_url, domain) ⇒ ShortUrl
Returns a new instance of ShortUrl.
18 19 20 21 22 23 |
# File 'lib/signal_api/short_url.rb', line 18 def initialize(id, target_url, short_url, domain) @id = id @target_url = target_url @short_url = short_url @domain = domain end |
Instance Attribute Details
#domain ⇒ Object (readonly)
The domain of the short URL
16 17 18 |
# File 'lib/signal_api/short_url.rb', line 16 def domain @domain end |
#id ⇒ Object (readonly)
The ID of the shortend URL on the Signal platform
13 14 15 |
# File 'lib/signal_api/short_url.rb', line 13 def id @id end |
#short_url ⇒ Object (readonly)
The shortened URL
7 8 9 |
# File 'lib/signal_api/short_url.rb', line 7 def short_url @short_url end |
#target_url ⇒ Object (readonly)
The target URL that was shortened
10 11 12 |
# File 'lib/signal_api/short_url.rb', line 10 def target_url @target_url end |
Class Method Details
.create(target, domain) ⇒ ShortUrl
Create a short URL for the provided target URL
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/signal_api/short_url.rb', line 31 def self.create(target, domain) body = <<-END <short_url> <target_url><![CDATA[#{target}]]></target_url> <domain_id>1</domain_id> </short_url> END SignalApi.logger.info "Attempting to create a short URL for #{target}" with_retries do response = post('/api/short_urls.xml', :body => body, :format => :xml, :headers => common_headers) if response.code == 201 data = response.parsed_response['short_url'] new(data['id'], data['target_url'], "http://#{domain}/#{data['slug']}", domain) else handle_api_failure(response) end end end |