Class: Budurl::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/budurl/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, uri) ⇒ Client

Returns a Budurl client which can be used to query API services. uri is the base uri for the BudURL API.



13
14
15
16
# File 'lib/budurl/client.rb', line 13

def initialize(api_key, uri)
  self.class.base_uri uri
  @default_query_opts = { :api_key => api_key }
end

Instance Method Details

#clicks(short_url, opts = {}) ⇒ Object

Returns a hash containing click counts since creation. opts allow daily click counts and date filters. For all options, see the BudURL API: budurl.com/page/budurlpro-api



37
38
39
40
# File 'lib/budurl/client.rb', line 37

def clicks(short_url, opts = {})
  query_opts = {:link => short_url}.merge(opts)
  response = get('/clicks/count', :query => query_opts)
end

#expand(short_url) ⇒ Object

Returns a Budurl::Url object containing a longurl.



28
29
30
31
32
# File 'lib/budurl/client.rb', line 28

def expand(short_url)
  query_opts = {:link => short_url}
  response = get('/links/expand', :query => query_opts)
  Budurl::Url.new(self, response)
end

#shorten(url, opts = {}) ⇒ Object

Returns a Budurl::Url object containing a shorturl. opts allow duplicate checking, notes, etc. For all options, see the BudURL API: budurl.com/page/budurlpro-api



21
22
23
24
25
# File 'lib/budurl/client.rb', line 21

def shorten(url, opts = {})
  query_opts = {:long_url => url}.merge(opts)
  response = get('/links/shrink', :query => query_opts)
  Budurl::Url.new(self, response)
end