Class: HttpPage
Instance Attribute Summary
#_, #stylesheet
Instance Method Summary
collapse
#alert, #build_layout, #compile_styles, #history, layout, #name, #navbar, new, #repaint, #setup_wrap, #title, #title=, #view, #view=
#emit, #off, #on
Constructor Details
Returns a new instance of HttpPage.
3
4
5
6
7
8
9
|
# File 'app/pages/http_page.rb', line 3
def initialize
@search = first('#search-form input')
@result = first('img#result')
@locker = Locker.new
first('#search-form button').on(:tap) { search }
end
|
Instance Method Details
#parse_first_image_url(response) ⇒ Object
34
35
36
|
# File 'app/pages/http_page.rb', line 34
def parse_first_image_url(response)
response.json["responseData"]["results"][0]["url"] rescue nil end
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/pages/http_page.rb', line 11
def search
@search.blur
@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
|
#search_url ⇒ Object
26
27
28
29
30
31
32
|
# File 'app/pages/http_page.rb', line 26
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
|