Class: Budurl::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/budurl/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, response = nil) ⇒ Url

Create a Url with values filled in from a Client response.



9
10
11
12
13
14
15
16
17
# File 'lib/budurl/url.rb', line 9

def initialize(client, response = nil)
  @client = client

  if response && response.is_a?(Hash)
    @link = response['link']
    @long_url = response['long_url']
    @hash = response['hash']
  end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



6
7
8
# File 'lib/budurl/url.rb', line 6

def hash
  @hash
end

Returns the value of attribute link.



6
7
8
# File 'lib/budurl/url.rb', line 6

def link
  @link
end

#long_urlObject

Returns the value of attribute long_url.



6
7
8
# File 'lib/budurl/url.rb', line 6

def long_url
  @long_url
end

Instance Method Details

#clicks(daily = false, date_from = nil, date_to = nil) ⇒ Object

Retrieve click counts for this shorturl. daily flag allows day-by-day breakdowns. date_from and date_to are Date objects which allow filtering.



22
23
24
25
26
27
28
29
# File 'lib/budurl/url.rb', line 22

def clicks(daily=false, date_from=nil, date_to=nil)
  opts = { :daily => daily ? 1 : 0 }
  opts.merge!(:date_from => date_from.to_s) if date_from
  opts.merge!(:date_to => date_to.to_s) if date_to

  response = @client.clicks(@link, opts)
  daily ? response['dates'] : response['count']
end