Class: LinkShrink::Shrinkers::Google

Inherits:
Base
  • Object
show all
Defined in:
lib/link_shrink/shrinkers/google.rb

Overview

Implements Google’s URL Shortener API

Author:

Instance Attribute Summary

Attributes inherited from Base

#url

Instance Method Summary collapse

Methods inherited from Base

#api_key, #api_key?, #api_url, collection, #content_type, error, #generate_chart_url, inherited, response_options, #sanitize_url, short_url

Instance Method Details

#api_query_parameterString

Returns URL query parameters

Returns:

  • (String)

    query parameters to be used in request



21
22
23
# File 'lib/link_shrink/shrinkers/google.rb', line 21

def api_query_parameter
  "?key=#{api_key}"
end

#base_urlString

Returns URL base for API

Returns:

  • (String)

    api base url



15
16
17
# File 'lib/link_shrink/shrinkers/google.rb', line 15

def base_url
  'https://www.googleapis.com/urlshortener/v1/url'
end

#body_parameters(new_url = nil) ⇒ String

Returns body parameters used in request header

Returns:

  • (String)

    body parameters to be used in request header



27
28
29
# File 'lib/link_shrink/shrinkers/google.rb', line 27

def body_parameters(new_url = nil)
  { 'longUrl' => url }.to_json
end

#http_methodSymbol

Returns HTTP method to be used in request

Returns:

  • (Symbol)

    post http method



33
34
35
# File 'lib/link_shrink/shrinkers/google.rb', line 33

def http_method
  :post
end