Class: Firefly::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/firefly/client.rb

Overview

Firefly::Client allows you to shorten URLs quickily through a Firefly server.

Usage is easy:

firefly = Firefly::Client.new(url, api_key)
firefly.shorten("http://google.com")

Instance Method Summary collapse

Constructor Details

#initialize(url, api_key) ⇒ Client

Creates a new instance to shorten Firefly URLs

url is the URL to your Firefly server. E.g. “aj.gs”. Note: do not include a trailing slash api_key is your Firefly API Key.



17
18
19
20
# File 'lib/firefly/client.rb', line 17

def initialize(url, api_key)
	@firefly_url = url
	@api_key     = api_key
end

Instance Method Details

#shorten(input) ⇒ Object

shorten([“google.com”, “yahoo.com”]) => { “google.com/” => “aj.gs/7dZ”,

"http://yahoo.com/"  => "http://aj.gs/8Yt" }


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/firefly/client.rb', line 29

def shorten(input)
	if input.is_a?(String)
	  return create_url(input)	
	elsif input.is_a?(Array)
		result = {}
		input.each do |inp|
			result[inp] = create_url(inp)
		end
      return result 
	else
		raise ArgumentError.new('Shorten requires either a url or an array of urls')
	end
end