Class: Yourls::Client
- Inherits:
-
Object
- Object
- Yourls::Client
- Includes:
- HTTParty
- Defined in:
- lib/yourls/client.rb
Instance Method Summary (collapse)
- - (Object) expand(short_url, options = {})
- - (Object) get(action, query = {})
-
- (Client) initialize(host, api_key, options = {})
constructor
A new instance of Client.
- - (Object) shorten(long_url, options = {})
- - (Object) stats(options = {})
Constructor Details
- (Client) initialize(host, api_key, options = {})
A new instance of Client
7 8 9 10 11 |
# File 'lib/yourls/client.rb', line 7 def initialize(host, api_key, = {}) @host, @api_key = host, api_key @base_uri = File.join(host, 'yourls-api.php') @server_offset = [:offset] || 0.seconds end |
Instance Method Details
- (Object) expand(short_url, options = {})
18 19 20 |
# File 'lib/yourls/client.rb', line 18 def (short_url, = {}) Yourls::Url.new(get('expand', .merge!(:shorturl => short_url)).parsed_response) end |
- (Object) get(action, query = {})
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yourls/client.rb', line 26 def get(action, query = {}) # Prepare the signature = (Time.now + @server_offset).to_i signature = Digest::MD5.hexdigest(.to_s + @api_key) query ||= {} query.merge!(:timestamp => , :signature => signature, :action => action, :format => 'json') response = self.class.get(@base_uri, :query => query) if response.code == 200 return response else raise YourlsError.new(response., response.code) end end |
- (Object) shorten(long_url, options = {})
22 23 24 |
# File 'lib/yourls/client.rb', line 22 def shorten(long_url, = {}) Yourls::Url.new(get('shorturl', .merge!(:url => long_url)).parsed_response) end |
- (Object) stats(options = {})
13 14 15 16 |
# File 'lib/yourls/client.rb', line 13 def stats( = {}) response = get('stats', ) response.parsed_response end |