Class: ExpandUrl
- Inherits:
-
Object
- Object
- ExpandUrl
- Defined in:
- lib/expandurl.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
Returns the value of attribute service.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #expand ⇒ Object
- #find_service ⇒ Object
-
#initialize(url) ⇒ ExpandUrl
constructor
A new instance of ExpandUrl.
Constructor Details
#initialize(url) ⇒ ExpandUrl
Returns a new instance of ExpandUrl.
10 11 12 13 14 |
# File 'lib/expandurl.rb', line 10 def initialize(url) self.url = url self.user_agent = 'ExpandUrlGem/1.0' self.service = find_service end |
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
8 9 10 |
# File 'lib/expandurl.rb', line 8 def service @service end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/expandurl.rb', line 8 def url @url end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/expandurl.rb', line 8 def user_agent @user_agent end |
Instance Method Details
#expand ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/expandurl.rb', line 25 def if self.service [1,2].shuffle.each do |api| url = (api) return url if url end end return false end |
#find_service ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/expandurl.rb', line 16 def find_service host = Addressable::URI.parse(self.url).host services = YAML::load_file(File.join(File.dirname(File.(__FILE__)), 'services.yml')) services.each do |service| return host if service == host end return false end |