Class: SearchApi::GoogleNewsPortalRequest
- Inherits:
-
Request
- Object
- Request
- SearchApi::GoogleNewsPortalRequest
show all
- Defined in:
- lib/searchapi/google_news_portal_request.rb
Constant Summary
Constants inherited
from Request
Request::BASE_URI
Instance Method Summary
collapse
Methods inherited from Request
#initialize
Instance Method Details
#publication(publication_token, options = nil, &block) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/searchapi/google_news_portal_request.rb', line 67
def publication( publication_token, options = nil, &block )
if options
options = options.is_a?( GoogleNewsPortalOptions ) ? options : GoogleNewsPortalOptions.build!( options.to_h )
options = options.to_h
else
options = { engine: 'google_news_portal' }
end
options[ :publication_token ] = publication_token.to_s
response = get( "#{ BASE_URI }/search", options, &block )
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
result = if response.success?
GoogleNewsPortalResult.new( attributes || {} )
else
ErrorResult.new( response.status, attributes )
end
ResponseMethods.install( response, result )
end
|
#search(query = nil, options = nil, &block) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/searchapi/google_news_portal_request.rb', line 4
def search( query = nil, options = nil, &block )
if options
options = options.is_a?( GoogleNewsPortalOptions ) ? options : GoogleNewsPortalOptions.build!( options.to_h )
options = options.to_h
else
options = { engine: 'google_news_portal' }
end
options[ :q ] = query.to_s if query
response = get( "#{ BASE_URI }/search", options, &block )
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
result = if response.success?
GoogleNewsPortalResult.new( attributes || {} )
else
ErrorResult.new( response.status, attributes )
end
ResponseMethods.install( response, result )
end
|
#story(story_token, options = nil, &block) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/searchapi/google_news_portal_request.rb', line 25
def story( story_token, options = nil, &block )
if options
options = options.is_a?( GoogleNewsPortalOptions ) ? options : GoogleNewsPortalOptions.build!( options.to_h )
options = options.to_h
else
options = { engine: 'google_news_portal' }
end
options[ :story_token ] = story_token.to_s
response = get( "#{ BASE_URI }/search", options, &block )
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
result = if response.success?
GoogleNewsPortalResult.new( attributes || {} )
else
ErrorResult.new( response.status, attributes )
end
ResponseMethods.install( response, result )
end
|
#topic(topic_token, options = nil, &block) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/searchapi/google_news_portal_request.rb', line 46
def topic( topic_token, options = nil, &block )
if options
options = options.is_a?( GoogleNewsPortalOptions ) ? options : GoogleNewsPortalOptions.build!( options.to_h )
options = options.to_h
else
options = { engine: 'google_news_portal' }
end
options[ :topic_token ] = topic_token.to_s
response = get( "#{ BASE_URI }/search", options, &block )
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
result = if response.success?
GoogleNewsPortalResult.new( attributes || {} )
else
ErrorResult.new( response.status, attributes )
end
ResponseMethods.install( response, result )
end
|