Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

Added search functionality #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@
/spec/reports/
/tmp/
.ruby-version
.idea/
1 change: 1 addition & 0 deletions lib/market_bot.rb
Expand Up @@ -12,6 +12,7 @@
require 'market_bot/play/chart/constants'
require 'market_bot/play/chart'
require 'market_bot/play/developer'
require 'market_bot/play/search'

module MarketBot
def self.timeout
Expand Down
31 changes: 31 additions & 0 deletions lib/market_bot/play/search.rb
@@ -0,0 +1,31 @@
module MarketBot
module Play
class Search < MarketBot::Play::Chart
def initialize(query, options={})
super(query, nil, options)
end

def store_urls(options={})
results = []
num = 100

url = "https://play.google.com/store/search?"
url << "q=#{URI.escape(@collection)}&"
url << "c=apps&"
url << "gl=#{@country}&"
url << "hl=#{@lang}"

results << url

return results
end

def update(opts={})
super(opts)
@result.each { |r| r.delete(:rank) }

self
end
end
end
end
97 changes: 97 additions & 0 deletions spec/market_bot/play/data/search-clash-royale.txt

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions spec/market_bot/play/search_spec.rb
@@ -0,0 +1,52 @@
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')

describe MarketBot::Play::Search do
shared_context('parsing a search') do
it 'should be a valid length' do
expect(@parsed.length).to be > 1
end

it 'should have attributes' do
expect(@parsed).to all(have_key(:package)).and \
all(have_key(:title)).and all(have_key(:store_url)).and \
all(have_key(:developer)).and all(have_key(:icon_url))
end
end

describe "(clash royale)" do
include_context 'parsing a search'

before(:all) do
@name = 'clash royale'
@html = read_play_data('search-clash-royale.txt')
@parsed = MarketBot::Play::Chart.parse(@html)
end
end

it 'should generate store_urls' do
name ='clash royale'
dev = MarketBot::Play::Search.new(name)

expect(dev.store_urls.length).to eq(1)

dev.store_urls.each_with_index do |url, i|
msg = "i=#{i}, url=#{url}"
pattern = /\Ahttps:\/\/play\.google\.com\/store\/search\?q=clash%20royale&c=apps&gl=us&hl=en\z/
expect(url).to match(Regexp.new(pattern)), msg
end
end

it 'should update' do
name = 'clash royale'
dev = MarketBot::Play::Search.new(name)
code = 200

dev.store_urls.each_with_index do |url, i|
html = read_play_data('search-clash-royale.txt')
response = Typhoeus::Response.new(code: code, headers: '', body: html)
Typhoeus.stub(url).and_return(response)
end

dev.update
end
end