Class: Bitly::Client
- Inherits:
-
Object
- Object
- Bitly::Client
- Defined in:
- lib/providers/bitly/client.rb
Constant Summary collapse
- BASE_URI =
"http://api.bit.ly/v3"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#format ⇒ Object
Returns the value of attribute format.
-
#login ⇒ Object
Returns the value of attribute login.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
-
.connection(options = {}) ⇒ Object
creates a connection with default loaded.
Instance Method Summary collapse
- #default_params ⇒ Object
- #get(end_point, options = {}) ⇒ Object
-
#initialize(login, api_key, options = {}) ⇒ Client
constructor
A new instance of Client.
- #shorten(url) ⇒ Object
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(login, api_key, ={}) @login = login @api_key = api_key @format = [:format] || :json end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/providers/bitly/client.rb', line 7 def api_key @api_key end |
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/providers/bitly/client.rb', line 7 def format @format end |
#login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/providers/bitly/client.rb', line 7 def login @login end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/providers/bitly/client.rb', line 7 def response @response end |
Class Method Details
Instance Method Details
#default_params ⇒ Object
17 18 19 |
# File 'lib/providers/bitly/client.rb', line 17 def default_params {:login => 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, ={}) RestClient.get(BASE_URI + end_point, :params => default_params.merge()) 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 |