Class: GoogleMobileFriendly::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/google_mobile_friendly/request.rb

Constant Summary collapse

GOOGLE_TEST_REQUEST_URI =
'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run'

Instance Method Summary collapse

Constructor Details

#initialize(url, api_key) ⇒ Request

Returns a new instance of Request.



9
10
11
12
# File 'lib/google_mobile_friendly/request.rb', line 9

def initialize url, api_key
  @url = url
  @api_key = api_key
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
# File 'lib/google_mobile_friendly/request.rb', line 14

def execute
  uri = URI(GOOGLE_TEST_REQUEST_URI)
  params = {:key => @api_key}
  uri.query = URI.encode_www_form(params)
  http_result = Net::HTTP.post_form(uri, 'url' => @url)
  response = JSON.parse(http_result.body, symbolize_names: true)
  GoogleMobileFriendly::TestPage.new response
end