play_store_info 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/play_store_info.rb +1 -1
- data/lib/play_store_info/app_parser.rb +22 -29
- data/lib/play_store_info/readers.rb +35 -0
- data/lib/play_store_info/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bdf278a90892bf8f090036d1202d4bdc8c717eb
|
4
|
+
data.tar.gz: 1ce7f35554e71d30d044ef8cd7e1ba6fe63ffd2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4fa2abfeffb2a3d16dac7c121b70af0c21ad20e258e0dda6d5b110d84d267c5495f5fd9ba580bec9e9b17d8d573484bbdc8bfea7aaf6fc62068e2a2edfd606
|
7
|
+
data.tar.gz: 570ae485848a267a604ba92042eb7d285fcce26828c869ae550424c69ef9296c366a44844c2e135b9e618a8f8672cd9a2d26f29e8022c81e9a7f9a9813848694
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/hugocore/
|
1
|
+
[![Build Status](https://travis-ci.org/hugocore/play_store_info.svg)](https://travis-ci.org/hugocore/play_store_info)
|
2
2
|
|
3
3
|
# PlayStoreInfo
|
4
4
|
|
@@ -37,7 +37,7 @@ Then you have some attributes that can be read easily:
|
|
37
37
|
```ruby
|
38
38
|
app.id # => "com.airbnb.android"
|
39
39
|
app.name # => "Airbnb"
|
40
|
-
app.
|
40
|
+
app.artwork # => "http://lh6.ggpht.com/4jnm0-_9TBUdvNtQpefYE0T33..."
|
41
41
|
app.description # => "Make travel planning as mobile as you are..."
|
42
42
|
```
|
43
43
|
|
data/lib/play_store_info.rb
CHANGED
@@ -26,7 +26,7 @@ module PlayStoreInfo
|
|
26
26
|
|
27
27
|
raise AppNotFound unless inspector.response.status == 200
|
28
28
|
|
29
|
-
AppParser.new(id, inspector.parsed)
|
29
|
+
AppParser.new(id, inspector.parsed)
|
30
30
|
rescue Faraday::ConnectionFailed, Faraday::SSLError, Errno::ETIMEDOUT
|
31
31
|
raise ConnectionError
|
32
32
|
end
|
@@ -1,53 +1,46 @@
|
|
1
|
-
require '
|
1
|
+
require 'play_store_info/readers'
|
2
2
|
|
3
3
|
module PlayStoreInfo
|
4
4
|
class AppParser
|
5
|
+
include PlayStoreInfo::Readers
|
6
|
+
|
7
|
+
readers %w(id name artwork description)
|
8
|
+
|
5
9
|
def initialize(id, body)
|
6
10
|
@id = id
|
7
11
|
@body = body
|
8
|
-
end
|
9
12
|
|
10
|
-
|
11
|
-
OpenStruct.new(to_hash)
|
12
|
-
end
|
13
|
+
scrape_data
|
13
14
|
|
14
|
-
|
15
|
-
{
|
16
|
-
id: @id,
|
17
|
-
name: read_app_name,
|
18
|
-
icon_url: read_logo_url,
|
19
|
-
description: read_description
|
20
|
-
}
|
15
|
+
self
|
21
16
|
end
|
22
17
|
|
23
18
|
private
|
24
19
|
|
25
|
-
def
|
26
|
-
@
|
27
|
-
|
20
|
+
def read_id
|
21
|
+
@id
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_name
|
25
|
+
name = @body.xpath('//div[@itemprop="name"]/div/text()').text
|
28
26
|
|
29
|
-
|
27
|
+
raise AppNotFound if name.empty?
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
29
|
+
# get the app proper name in case the title contains some description
|
30
|
+
name.split(' - ').first.strip
|
34
31
|
end
|
35
32
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
url = @body.xpath('//img[@itemprop="image"]/@src').first&.value&.strip || ''
|
33
|
+
def read_artwork
|
34
|
+
url = @body.xpath('//img[@itemprop="image"]/@src').first&.value&.strip || ''
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
36
|
+
# add the HTTP protocol if the image source is lacking http:// because it starts with //
|
37
|
+
url.match(%r{^https?:\/\/}).nil? ? "http://#{url.gsub(%r{\A\/\/}, '')}" : url
|
43
38
|
end
|
44
39
|
|
45
40
|
def read_description
|
46
|
-
|
47
|
-
description = @body.xpath('//div[@itemprop="description"]').first&.inner_html&.strip
|
41
|
+
description = @body.xpath('//div[@itemprop="description"]').first&.inner_html&.strip
|
48
42
|
|
49
|
-
|
50
|
-
end
|
43
|
+
description.nil? ? '' : Sanitize.fragment(description).strip
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module PlayStoreInfo
|
4
|
+
module Readers
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
def scrape_data
|
10
|
+
self.class.accessors.each do |field, _|
|
11
|
+
instance_variable_set("@#{field}", send("read_#{field}"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json(*options)
|
16
|
+
to_hash.to_json(*options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
Hash[self.class.accessors.map { |field| [field.to_sym, send(field)] }]
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def readers(readers)
|
25
|
+
readers.map { |field, _| attr_reader field }
|
26
|
+
|
27
|
+
@_readers = readers
|
28
|
+
end
|
29
|
+
|
30
|
+
def accessors
|
31
|
+
@_readers
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: play_store_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Sequeira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: metainspector
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/play_store_info.rb
|
173
173
|
- lib/play_store_info/app_parser.rb
|
174
174
|
- lib/play_store_info/errors.rb
|
175
|
+
- lib/play_store_info/readers.rb
|
175
176
|
- lib/play_store_info/version.rb
|
176
177
|
- play_store_info.gemspec
|
177
178
|
homepage: https://github.com/hugocore/play_store_info
|