google_play_scraper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class GooglePlayScraper::Search
|
|
5
5
|
|
6
6
|
include GooglePlayScraper::SearchOptions
|
7
7
|
|
8
|
-
attr_reader :query, :options
|
8
|
+
attr_reader :query, :options, :google_play_reachable
|
9
9
|
|
10
10
|
GOOGLE_PLAY_SEARCH_URL = GooglePlayScraper::GOOGLE_PLAY_BASE_URL + "/store/search"
|
11
11
|
|
@@ -20,6 +20,7 @@ class GooglePlayScraper::Search
|
|
20
20
|
def initialize(query, options = {})
|
21
21
|
@options = DEFAULT_OPTIONS.merge(options)
|
22
22
|
@options['q'] = query
|
23
|
+
@google_play_reachable = true
|
23
24
|
end
|
24
25
|
|
25
26
|
def run
|
@@ -28,11 +29,20 @@ class GooglePlayScraper::Search
|
|
28
29
|
http.use_ssl = true
|
29
30
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
31
|
|
31
|
-
|
32
|
-
response = http.request(request)
|
32
|
+
results = []
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
begin
|
35
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
36
|
+
response = http.request(request)
|
37
|
+
response.value
|
38
|
+
|
39
|
+
parser = GooglePlayScraper::Parser.new(response.body)
|
40
|
+
results = parser.results
|
41
|
+
rescue
|
42
|
+
@google_play_reachable = false
|
43
|
+
end
|
44
|
+
|
45
|
+
results
|
36
46
|
end
|
37
47
|
|
38
48
|
def build_uri
|
@@ -12,6 +12,7 @@ describe GooglePlayScraper::Search do
|
|
12
12
|
results.first.logo_url.should == 'https://lh6.ggpht.com/M9q_Zs_CRt2rbA41nTMhrPqiBxhUEUN8Z1f_mn9m89_TiHbIbUF8hjnc_zwevvLsRIJy=w340'
|
13
13
|
results.first.logo_url_small.should == 'https://lh6.ggpht.com/M9q_Zs_CRt2rbA41nTMhrPqiBxhUEUN8Z1f_mn9m89_TiHbIbUF8hjnc_zwevvLsRIJy=w170'
|
14
14
|
results.first.url.should == 'https://play.google.com/store/apps/details?id=com.rovio.angrybirds'
|
15
|
+
search.google_play_reachable.should be_true
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'should be able to search for the sparq.me scanner' do
|
@@ -24,6 +25,7 @@ describe GooglePlayScraper::Search do
|
|
24
25
|
results.first.logo_url.should == 'https://lh3.ggpht.com/m8vHSrnD8kqMpYkgyQDxWpren2Pi5Vn-Eemj-xyHwcGUsbsi0rcYy0dR5Qzi5B566ig=w340'
|
25
26
|
results.first.logo_url_small.should == 'https://lh3.ggpht.com/m8vHSrnD8kqMpYkgyQDxWpren2Pi5Vn-Eemj-xyHwcGUsbsi0rcYy0dR5Qzi5B566ig=w170'
|
26
27
|
results.first.url.should == 'https://play.google.com/store/apps/details?id=com.sparqcode.sparqeye.android'
|
28
|
+
search.google_play_reachable.should be_true
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'should be able to find keek' do
|
@@ -36,6 +38,36 @@ describe GooglePlayScraper::Search do
|
|
36
38
|
results.first.logo_url.should == 'https://lh3.ggpht.com/SJSSPnOXBAQuz3miopva-ECfwz7YZJkaeTnIGPIYXxF6TCQ393_p1DAEtiEtfeUhDoOu=w340'
|
37
39
|
results.first.logo_url_small.should == 'https://lh3.ggpht.com/SJSSPnOXBAQuz3miopva-ECfwz7YZJkaeTnIGPIYXxF6TCQ393_p1DAEtiEtfeUhDoOu=w170'
|
38
40
|
results.first.url.should == 'https://play.google.com/store/apps/details?id=com.keek'
|
41
|
+
search.google_play_reachable.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'error cases' do
|
45
|
+
after(:each) {
|
46
|
+
pre_value = GooglePlayScraper::Search::GOOGLE_PLAY_SEARCH_URL
|
47
|
+
GooglePlayScraper::Search.send(:remove_const, :GOOGLE_PLAY_SEARCH_URL)
|
48
|
+
GooglePlayScraper::Search.const_set(:GOOGLE_PLAY_SEARCH_URL, pre_value)
|
49
|
+
}
|
50
|
+
it 'should return empty results and indicate when google play returns an invalid http code' do
|
51
|
+
GooglePlayScraper::Search.send(:remove_const, :GOOGLE_PLAY_SEARCH_URL)
|
52
|
+
GooglePlayScraper::Search.const_set(:GOOGLE_PLAY_SEARCH_URL, 'http://www.google.com/asdfasdfasdfasdfasdf')
|
53
|
+
|
54
|
+
search = GooglePlayScraper::Search.new('Angry Birds')
|
55
|
+
results = search.run
|
56
|
+
|
57
|
+
results.size.should == 0
|
58
|
+
search.google_play_reachable.should be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return empty resulta nd indicate when it cannot parse the google play results' do
|
62
|
+
GooglePlayScraper::Search.send(:remove_const, :GOOGLE_PLAY_SEARCH_URL)
|
63
|
+
GooglePlayScraper::Search.const_set(:GOOGLE_PLAY_SEARCH_URL, 'http://www.google.com')
|
64
|
+
|
65
|
+
search = GooglePlayScraper::Search.new('Angry Birds')
|
66
|
+
results = search.run
|
67
|
+
|
68
|
+
results.size.should == 0
|
69
|
+
search.google_play_reachable.should be_false
|
70
|
+
end
|
39
71
|
end
|
40
72
|
end
|
41
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_play_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|