Sha256: 92447f952cea4a73c0f55f8eac116762223c33c6e2ee143280c86d1ca8ef3d48
Contents?: true
Size: 823 Bytes
Versions: 1
Compression:
Stored size: 823 Bytes
Contents
class HttpPage < UnderOs::Page def initialize @search = first('#search-form input') @result = first('img#result') @locker = Locker.new first('#search-form button').on(:tap) { search } end def search @search.hide_keyboard @locker.show UnderOs::HTTP.get search_url do |response| if image_url = parse_first_image_url(response) @result.load image_url do @locker.hide end else @locker.hide end end end def search_url query = @search.value query = 'puppy' if query.empty? query = String.new(query).url_encode "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=#{query}" end def parse_first_image_url(response) response.json["responseData"]["results"][0]["url"] rescue nil # ftw! end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
under-os-1.1.0 | app/pages/http_page.rb |