Class: BitlyApi::Bitly
- Inherits:
-
Object
- Object
- BitlyApi::Bitly
- Defined in:
- lib/bitly-api/bitly-api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#login ⇒ Object
Returns the value of attribute login.
Instance Method Summary collapse
- #expand(short_url) ⇒ Object
-
#initialize(options = {}) ⇒ Bitly
constructor
A new instance of Bitly.
- #shorten(long_url) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bitly
Returns a new instance of Bitly.
10 11 12 13 14 15 16 17 |
# File 'lib/bitly-api/bitly-api.rb', line 10 def initialize( = {}) raise ArgumentError.new(":login and :api_key are required") if ([:login].nil? or [:api_key].nil?) [:version] = "2.0.1" if [:version].nil? self.login = [:login] self.api_key = [:api_key] self.api_version = [:version] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/bitly-api/bitly-api.rb', line 7 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
8 9 10 |
# File 'lib/bitly-api/bitly-api.rb', line 8 def api_version @api_version end |
#login ⇒ Object
Returns the value of attribute login.
6 7 8 |
# File 'lib/bitly-api/bitly-api.rb', line 6 def login @login end |
Instance Method Details
#expand(short_url) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/bitly-api/bitly-api.rb', line 27 def (short_url) http_response = open(build_url("expand", "shortUrl=#{short_url}")).read data = JSON.parse(http_response) raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK" results = data["results"][short_url] results end |
#shorten(long_url) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/bitly-api/bitly-api.rb', line 19 def shorten(long_url) http_response = open(build_url("shorten", "longUrl=#{long_url}")).read data = JSON.parse(http_response) raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK" results = data["results"][long_url] results end |