Class: ChromeStoreSearch::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/chrome_store_search/search.rb

Constant Summary collapse

CHROME_STORE_SEARCH_URL =
"https://chrome.google.com/webstore/ajax/item?"
DEFAULT_SEARCH_CONDITION =
{:hl =>"en-US",
:count => 20,
:category => nil}

Instance Method Summary collapse

Constructor Details

#initialize(search_condition = DEFAULT_SEARCH_CONDITION) ⇒ Search

Returns a new instance of Search.



17
18
19
# File 'lib/chrome_store_search/search.rb', line 17

def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
  @search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
end

Instance Method Details

#search(keyword) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/chrome_store_search/search.rb', line 21

def search(keyword)
  @keyword = keyword
  conn = Faraday.new(:url => init_query_url) do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
  res = conn.post '', {}
  AppParser.parse(res.body)
end