appscreens 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03411f3d67faa484d3c00dbf1d1f12327a5d1f85
4
+ data.tar.gz: df820c55dd24fb203bf6590cab1091f3e7a63232
5
+ SHA512:
6
+ metadata.gz: a0d52ab615866fb4106dc94be0c6bf102b5ff2ac392af4d57929f5ce3cab242fcf79b37079144c532e1baa926db72c286cab268fd58c6cf833a1d8b8aaf23557
7
+ data.tar.gz: 1dacfbc30a19a1d418979a7ec1014406f712f37fdbbee5f23677fe8098d4f3817a56133991935fe508a652dbe0d0ced066039ffe9e8cc770b9dfb80f3da6727a
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in appscreens.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dan Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # AppScreens
2
+
3
+ A command-line interface for querying the App Store and downloading app screenshots, and optionally, app icons.
4
+
5
+ ## Installation
6
+
7
+ Run
8
+
9
+ $ gem install appscreens
10
+
11
+ ## Usage
12
+
13
+ $ appscreens grab 333903271 --icon
14
+
15
+ to download Twitter's app screenshots and app icon to a folder named `twitter_screens`.
16
+
17
+ ## Todo
18
+
19
+ * Add `--ipad` option to download the iPad screenshots.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'appscreens/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "appscreens"
8
+ spec.version = Appscreens::VERSION
9
+ spec.authors = ["Dan Williams"]
10
+ spec.email = ["dan@danwilliams.co"]
11
+ spec.summary = %q{A command-line interface for querying the App Store and downloading app screenshots.}
12
+ spec.homepage = "http://github.com/danwilliams64/appscreens"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'colored' # coloured terminal output
21
+ spec.add_dependency 'commander' # CLI parser
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ end
data/bin/appscreens ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'appscreens'
4
+
5
+ require 'commander/import'
6
+ require 'fileutils'
7
+
8
+ HighLine.track_eof = false # Fix for built-in Ruby
9
+ Signal.trap("INT") {} # Suppress backtrace when exiting command
10
+
11
+ program :name, "appscreens"
12
+ program :version, Appscreens::VERSION
13
+ program :description, 'A command-line interface for querying the App Store and downloading app screenshots'
14
+
15
+ program :help, 'Author', 'Dan Williams <dan@danwilliams.co>'
16
+ program :help, 'Website', 'https://github.com/danwilliams64'
17
+ program :help_formatter, :compact
18
+
19
+ default_command :grab
20
+
21
+ command :grab do |c|
22
+ c.syntax = 'appscreens grab APP_ID'
23
+ c.summary = 'Downloads the app\'s screenshots and optionally icon into a new directory named after the app.'
24
+ c.description = 'Appscreens makes it easy to download an app\'s screenshots and icon for editorial use on blogs. '
25
+ c.option '--icon', 'Download the app\'s high resolution artwork in addition to the screen shots.'
26
+
27
+ c.example 'grab', 'appscreens grab 886427730'
28
+
29
+ c.action do |args, options|
30
+ say_error "Missing app ID" and abort unless app_id = args.first
31
+
32
+ begin
33
+ result = client.lookup(app_id)
34
+ if result.empty?
35
+ say_error "Can't find app with id: #{app_id}" and abort
36
+ end
37
+
38
+ dir = FileUtils::mkdir_p("#{result["trackName"].downcase.tr(" ","_")}_screens").first
39
+ client.download_screenshots(app: result, icon: options.icon, destination: dir)
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def client
49
+ @client ||= Appscreens::Client.new
50
+ end
@@ -0,0 +1,54 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+
5
+ module Appscreens
6
+ ITUNES_SEARCH_ENDPOINT = "https://itunes.apple.com/"
7
+ ITUNES_SEARCH_RESULTS_KEY = "results"
8
+ APP_SCREENSHOTS_KEY = "screenshotUrls"
9
+ APP_NAME_KEY = "trackName"
10
+ APP_ICON_KEY = "artworkUrl100"
11
+
12
+ class Client
13
+ def initialize
14
+ @search_url = ITUNES_SEARCH_ENDPOINT
15
+ @country = 'US'
16
+ end
17
+
18
+ def lookup(app_id)
19
+ uri = URI.join(@search_url, "lookup")
20
+ uri.query = URI.encode_www_form( {id: app_id} )
21
+
22
+ json_response_from_uri(uri)[ITUNES_SEARCH_RESULTS_KEY].first
23
+ end
24
+
25
+ def download_screenshots(app:, icon:, destination:)
26
+ screenshots = app[APP_SCREENSHOTS_KEY]
27
+ app_name = app[APP_NAME_KEY].downcase.tr(" ","_")
28
+
29
+ screenshots.each_with_index do |screen_url, index|
30
+ puts "Downloading screenshot #{index + 1} of #{screenshots.length}..."
31
+ file_name = "#{destination}/#{app_name}_#{index + 1}.jpeg"
32
+ File.open(file_name, 'wb') { |fp| fp.write(open(screen_url).read) }
33
+ end
34
+
35
+ if icon
36
+ puts "Downloading app icon..."
37
+ File.open("#{destination}/#{app_name}_icon.png", 'wb') { |fp| fp.write(open(app[APP_ICON_KEY]).read) }
38
+ end
39
+
40
+ puts '#######################################################################'.green
41
+ puts "Finished grabbing artwork for #{app[APP_NAME_KEY]}".green
42
+ puts '#######################################################################'.green
43
+
44
+ end
45
+
46
+ private
47
+
48
+ def json_response_from_uri(uri)
49
+ response = Net::HTTP.get_response(uri)
50
+ JSON.parse(response.body) rescue nil
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Appscreens
2
+ VERSION = "0.1.0"
3
+ end
data/lib/appscreens.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'appscreens/version'
2
+ require 'appscreens/client'
3
+
4
+ # Third party code
5
+ require 'colored'
@@ -0,0 +1,39 @@
1
+ require 'minitest/unit'
2
+ require 'appscreens'
3
+
4
+ class ClientTest < Minitest::Test
5
+
6
+ def setup
7
+ @client = Appscreens::Client.new
8
+ @app_id = "333903271"
9
+ end
10
+
11
+ def teardown
12
+ system("rm -rf /tmp/appscreens")
13
+ end
14
+
15
+ def test_can_lookup_a_given_app_id
16
+ app = @client.lookup @app_id
17
+ assert_instance_of(Hash, app, "App should be instance of Hash")
18
+ end
19
+
20
+ def test_app_should_have_screenshots_key
21
+ app = @client.lookup @app_id
22
+ screenshots = app[Appscreens::APP_SCREENSHOTS_KEY]
23
+ assert(screenshots.length > 0, "Screenshots array should contain screenshots")
24
+ end
25
+
26
+ def test_download_screenshots_to_filesystem
27
+ system("rm -rf /tmp/appscreens")
28
+
29
+ path = "/tmp/appscreens"
30
+ FileUtils::mkdir_p(path)
31
+ app = @client.lookup @app_id
32
+ @client.download_screenshots(app: app, icon: true, destination: path)
33
+
34
+ expected_file_count = app[Appscreens::APP_SCREENSHOTS_KEY].length + 1
35
+ file_count = Dir.glob(File.join(path, '**', '*')).select { |file| File.file?(file) }.count
36
+ assert_equal(expected_file_count, file_count, "Expected #{expected_file_count} files. There was #{file_count}")
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appscreens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colored
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - dan@danwilliams.co
72
+ executables:
73
+ - appscreens
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - appscreens.gemspec
83
+ - bin/appscreens
84
+ - lib/appscreens.rb
85
+ - lib/appscreens/client.rb
86
+ - lib/appscreens/version.rb
87
+ - spec/client_spec.rb
88
+ homepage: http://github.com/danwilliams64/appscreens
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A command-line interface for querying the App Store and downloading app screenshots.
112
+ test_files:
113
+ - spec/client_spec.rb
114
+ has_rdoc: