play_store_info 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cab2e61da7eecca73560055b1ae10126febad9b6
4
- data.tar.gz: 09af52f4a401e558a5af0f3be47d745cc99a117a
3
+ metadata.gz: 9bdf278a90892bf8f090036d1202d4bdc8c717eb
4
+ data.tar.gz: 1ce7f35554e71d30d044ef8cd7e1ba6fe63ffd2d
5
5
  SHA512:
6
- metadata.gz: cae8dc44688e1ff4c8e9cd873da07c994f3afe9a1127cb15d3c3ea9201d51f58c2ea7ec374530c82b9cf9cd392c3453a0579fdfa8e5a13e6ed0c63fffbe05cb5
7
- data.tar.gz: eb6db666221f6769df649389d50a242b05fa39762e6ed7cfe013dbb49762e42d5f08aba977cb4a509a2595943df176392c3d0c67fd95911f6e3928596aabf21f
6
+ metadata.gz: 3c4fa2abfeffb2a3d16dac7c121b70af0c21ad20e258e0dda6d5b110d84d267c5495f5fd9ba580bec9e9b17d8d573484bbdc8bfea7aaf6fc62068e2a2edfd606
7
+ data.tar.gz: 570ae485848a267a604ba92042eb7d285fcce26828c869ae550424c69ef9296c366a44844c2e135b9e618a8f8672cd9a2d26f29e8022c81e9a7f9a9813848694
data/.travis.yml CHANGED
@@ -1,7 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.2.2
6
3
  - 2.3.0
7
4
  before_install: gem install bundler -v 1.10.6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- play_store_info (1.0.0)
4
+ play_store_info (1.0.1)
5
5
  metainspector (~> 5.1.1)
6
6
  sanitize (~> 4.0.1)
7
7
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/hugocore/app_store_info.svg)](https://travis-ci.org/hugocore/app_store_info)
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.icon_url # => "http://lh6.ggpht.com/4jnm0-_9TBUdvNtQpefYE0T33..."
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
 
@@ -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).parse
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 'ostruct'
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
- def parse
11
- OpenStruct.new(to_hash)
12
- end
13
+ scrape_data
13
14
 
14
- def to_hash
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 read_app_name
26
- @app_name ||= begin
27
- name = @body.xpath('//div[@itemprop="name"]/div/text()').text
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
- raise AppNotFound if name.empty?
27
+ raise AppNotFound if name.empty?
30
28
 
31
- # get the app proper name in case the title contains some description
32
- name.split(' - ').first.strip
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 read_logo_url
37
- @app_logo ||= begin
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
- # add the HTTP protocol if the image source is lacking http:// because it starts with //
41
- url.match(%r{^https?:\/\/}).nil? ? "http://#{url.gsub(%r{\A\/\/}, '')}" : url
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
- @app_description ||= begin
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
- description.nil? ? '' : Sanitize.fragment(description).strip
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
@@ -1,3 +1,3 @@
1
1
  module PlayStoreInfo
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  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.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-28 00:00:00.000000000 Z
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