Class: SerpCheap::SearchResponse
- Inherits:
-
Object
- Object
- SerpCheap::SearchResponse
- Defined in:
- lib/serpcheap/models.rb
Instance Attribute Summary collapse
-
#ads ⇒ Object
readonly
Returns the value of attribute ads.
-
#knowledge_graph ⇒ Object
readonly
Returns the value of attribute knowledge_graph.
-
#organic ⇒ Object
readonly
Returns the value of attribute organic.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#people_also_ask ⇒ Object
readonly
Returns the value of attribute people_also_ask.
-
#related_searches ⇒ Object
readonly
Returns the value of attribute related_searches.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(search:, page:, organic:, knowledge_graph: nil, ads: nil, people_also_ask: nil, related_searches: nil, stats: nil) ⇒ SearchResponse
constructor
A new instance of SearchResponse.
Constructor Details
#initialize(search:, page:, organic:, knowledge_graph: nil, ads: nil, people_also_ask: nil, related_searches: nil, stats: nil) ⇒ SearchResponse
Returns a new instance of SearchResponse.
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/serpcheap/models.rb', line 131 def initialize(search:, page:, organic:, knowledge_graph: nil, ads: nil, people_also_ask: nil, related_searches: nil, stats: nil) @search = search @page = page @organic = organic @knowledge_graph = knowledge_graph @ads = ads @people_also_ask = people_also_ask @related_searches = @stats = stats end |
Instance Attribute Details
#ads ⇒ Object (readonly)
Returns the value of attribute ads.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def ads @ads end |
#knowledge_graph ⇒ Object (readonly)
Returns the value of attribute knowledge_graph.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def knowledge_graph @knowledge_graph end |
#organic ⇒ Object (readonly)
Returns the value of attribute organic.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def organic @organic end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def page @page end |
#people_also_ask ⇒ Object (readonly)
Returns the value of attribute people_also_ask.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def people_also_ask @people_also_ask end |
#related_searches ⇒ Object (readonly)
Returns the value of attribute related_searches.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def @related_searches end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def search @search end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
129 130 131 |
# File 'lib/serpcheap/models.rb', line 129 def stats @stats end |
Class Method Details
.from_hash(d) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/serpcheap/models.rb', line 142 def self.from_hash(d) kg = d["knowledgeGraph"] ads = d["ads"] rs = d["relatedSearches"] new( search: d["search"].to_s, page: (d["page"] || 1).to_i, organic: Array(d["organic"]).map { |o| OrganicResult.from_hash(o) }, knowledge_graph: kg.is_a?(Hash) ? KnowledgeGraph.from_hash(kg) : nil, ads: ads.is_a?(Array) ? ads.map { |a| Ad.from_hash(a) } : nil, people_also_ask: d["peopleAlsoAsk"], related_searches: rs.is_a?(Array) ? rs.map { |r| RelatedSearch.from_hash(r) } : nil, stats: d["stats"].is_a?(Hash) ? SearchStats.from_hash(d["stats"]) : nil ) end |