Class: Rerout::Resources::Links
- Inherits:
-
Object
- Object
- Rerout::Resources::Links
- Defined in:
- lib/rerout/links.rb
Overview
Link operations namespace.
Instance Method Summary collapse
-
#create(input) ⇒ Rerout::Models::Link
Create a new short link.
-
#delete(code) ⇒ Hash
Soft-delete a link.
-
#get(code) ⇒ Rerout::Models::Link
Fetch a single link.
-
#initialize(client) ⇒ Links
constructor
A new instance of Links.
-
#list(cursor: nil, limit: nil) ⇒ Rerout::Models::ListLinksResult
Paginated list of links.
-
#stats(code, days: 30) ⇒ Rerout::Models::LinkStats
Per-link click stats.
-
#update(code, input) ⇒ Rerout::Models::Link
Update a link.
Constructor Details
#initialize(client) ⇒ Links
Returns a new instance of Links.
10 11 12 |
# File 'lib/rerout/links.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#create(input) ⇒ Rerout::Models::Link
Create a new short link.
18 19 20 21 22 |
# File 'lib/rerout/links.rb', line 18 def create(input) body = coerce_input(input) response = @client.request(method: :post, path: '/v1/links', body: body) Models::Link.from_hash(response) end |
#delete(code) ⇒ Hash
Soft-delete a link.
69 70 71 |
# File 'lib/rerout/links.rb', line 69 def delete(code) @client.request(method: :delete, path: link_path(code)) end |
#get(code) ⇒ Rerout::Models::Link
Fetch a single link.
41 42 43 44 |
# File 'lib/rerout/links.rb', line 41 def get(code) response = @client.request(method: :get, path: link_path(code)) Models::Link.from_hash(response) end |
#list(cursor: nil, limit: nil) ⇒ Rerout::Models::ListLinksResult
Paginated list of links.
29 30 31 32 33 34 35 |
# File 'lib/rerout/links.rb', line 29 def list(cursor: nil, limit: nil) query = {} query['cursor'] = cursor unless cursor.nil? query['limit'] = limit unless limit.nil? response = @client.request(method: :get, path: '/v1/links', query: query) Models::ListLinksResult.from_hash(response) end |
#stats(code, days: 30) ⇒ Rerout::Models::LinkStats
Per-link click stats. Defaults to 30 days.
78 79 80 81 82 83 84 85 |
# File 'lib/rerout/links.rb', line 78 def stats(code, days: 30) response = @client.request( method: :get, path: "#{link_path(code)}/stats", query: { 'days' => days } ) Models::LinkStats.from_hash(response) end |
#update(code, input) ⇒ Rerout::Models::Link
Update a link. Only fields set on ‘input` are sent.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rerout/links.rb', line 51 def update(code, input) raise ArgumentError, 'input must be a Rerout::UpdateLinkInput' unless input.is_a?(UpdateLinkInput) if input.empty? raise Error.new( code: 'empty_update', message: 'UpdateLinkInput has no fields set; refusing to send empty PATCH.', status: 0 ) end response = @client.request(method: :patch, path: link_path(code), body: input.to_h) Models::Link.from_hash(response) end |