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?'.freeze
DEFAULT_SEARCH_CONDITION =
{ hl: 'en-US',
count: 20,
category: nil }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(search_condition = DEFAULT_SEARCH_CONDITION) ⇒ Search

Returns a new instance of Search.



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

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

Instance Method Details

#search(keyword) ⇒ Object



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

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