Class: Bitly::Client

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

Constant Summary collapse

BASE_URI =
"http://api.bit.ly/v3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login, api_key, options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/providers/bitly/client.rb', line 11

def initialize(, api_key, options={})
  @login =  
  @api_key = api_key
  @format = options[:format] || :json
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/providers/bitly/client.rb', line 7

def api_key
  @api_key
end

#formatObject

Returns the value of attribute format.



7
8
9
# File 'lib/providers/bitly/client.rb', line 7

def format
  @format
end

#loginObject

Returns the value of attribute login.



7
8
9
# File 'lib/providers/bitly/client.rb', line 7

def 
  @login
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/providers/bitly/client.rb', line 7

def response
  @response
end

Class Method Details

.connection(options = {}) ⇒ Object

creates a connection with default loaded.



34
35
36
# File 'lib/providers/bitly/client.rb', line 34

def self.connection(options={})
  @connection ||= Bitly::Client.new(Bitly::Config., Bitly::Config.api_key, options)
end

Instance Method Details

#default_paramsObject



17
18
19
# File 'lib/providers/bitly/client.rb', line 17

def default_params
  {:login => , :apiKey => api_key, :format => format}
end

#get(end_point, options = {}) ⇒ Object



21
22
23
# File 'lib/providers/bitly/client.rb', line 21

def get(end_point, options={})
  RestClient.get(BASE_URI + end_point, :params => default_params.merge(options))
end

#shorten(url) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/providers/bitly/client.rb', line 25

def shorten(url)
  response = get("/shorten", :longUrl => url)
  @response = ShortenResponse.new(response)
  @response.url
rescue
   nil
end