codes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e83694b359055c33e751fb29b7608b00eda2a0aa
4
+ data.tar.gz: 0a02e356e9583f3cc5d4aeb271a1dbfde6717962
5
+ SHA512:
6
+ metadata.gz: 619d4af7951e38461db2588f349db1da65711b4a1b3116b7455252e5deaf4d97a23f1e96388cab723056c147814ce0003396b41e334ed84ed5a3907f2b8d073a
7
+ data.tar.gz: d9c337066cc52eacedd409f94522ff9cb161d16fd48a1c8db00ffe13f02786bbf525ac57d34782263b9090c18f64fc85197e1f15c3b5882d6744157e39afb226
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Felix Krause
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ <h3 align="center">
2
+ <a href="https://github.com/KrauseFx/fastlane">
3
+ <img src="assets/fastlane.png" width="150" />
4
+ <br />
5
+ fastlane
6
+ </a>
7
+ </h3>
8
+ <p align="center">
9
+ <a href="https://github.com/KrauseFx/deliver">deliver</a> &bull;
10
+ <a href="https://github.com/KrauseFx/snapshot">snapshot</a> &bull;
11
+ <a href="https://github.com/KrauseFx/frameit">frameit</a> &bull;
12
+ <a href="https://github.com/KrauseFx/pem">PEM</a> &bull;
13
+ <a href="https://github.com/KrauseFx/sigh">sigh</a> &bull;
14
+ <a href="https://github.com/KrauseFx/produce">produce</a> &bull;
15
+ <a href="https://github.com/KrauseFx/cert">cert</a> &bull;
16
+ <b>codes</b>
17
+ </p>
18
+ -------
19
+
20
+ <p align="center">
21
+ <img src="assets/codes.png">
22
+ </p>
23
+
24
+ codes
25
+ ============
26
+
27
+ [![Twitter: @KauseFx](https://img.shields.io/badge/contact-@KrauseFx-blue.svg?style=flat)](https://twitter.com/KrauseFx)
28
+ [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/KrauseFx/cert/blob/master/LICENSE)
29
+ [![Gem](https://img.shields.io/gem/v/codes.svg?style=flat)](http://rubygems.org/gems/codes)
30
+
31
+ ###### Create promo codes for iOS Apps using the command line
32
+ or
33
+ ###### Automatically lose money by giving away your app for free...
34
+
35
+
36
+ ##### This tool was sponsored by [Max Bäumle](http://maxbaeumle.com) and [Textastic Code Editor](http://www.textasticapp.com)
37
+
38
+ Get in contact with the developers of `codes` on Twitter: [@KrauseFx](https://twitter.com/KrauseFx), [@acrooow](https://twitter.com/acrooow)
39
+
40
+ -------
41
+ <p align="center">
42
+ <a href="#installation">Installation</a> &bull;
43
+ <a href="#why">Why?</a> &bull;
44
+ <a href="#usage">Usage</a> &bull;
45
+ <a href="#tips">Tips</a> &bull;
46
+ <a href="#considerations">Considerations</a> &bull;
47
+ <a href="#need-help">Need help?</a>
48
+ </p>
49
+
50
+ -------
51
+
52
+ <h5 align="center"><code>codes</code> is part of <a href="http://fastlane.tools">fastlane</a>: connect all deployment tools into one streamlined workflow.</h5>
53
+
54
+
55
+
56
+ # Installation
57
+ sudo gem install codes
58
+
59
+ # Why?
60
+
61
+ `codes` can help you automate sending promo codes to journalists and create promo codes for tons of apps with the press of a button.
62
+
63
+ # Usage
64
+
65
+ code [num] [-a app_identifier] [-u user_name] [-i app_id] [-o output_file]
66
+
67
+ All parameters are optional.
68
+
69
+ `code` will print out the promo codes and store them in a file called `codes_[your app identifier].txt` in the current directory by default.
70
+
71
+ Example:
72
+
73
+ code 3 -a com.example.myApp
74
+
75
+ Will generate 3 promo codes for the the App with the Bundle Identifier `com.example.myApp`.
76
+
77
+ If you don't pass any paramaters, `code` will generate a single promo code and print it on the command line.
78
+
79
+ ##### [Get informed about new fastlane tools and features](https://tinyletter.com/krausefx)
80
+
81
+ ## Environment Variables
82
+ In case you prefer environment variables:
83
+
84
+ - ```CODES_USERNAME``` (Your iTunes Connect username)
85
+ - ```CODES_APP_IDENTIFIER``` (Your App's Bundle ID)
86
+ - ```CODES_APP_ID```(Your App's internal iTunes Connect App ID)
87
+
88
+ # Tips
89
+
90
+ ## [`fastlane`](http://fastlane.tools) Toolchain
91
+
92
+ - [`fastlane`](http://fastlane.tools): Connect all deployment tools into one streamlined workflow
93
+ - [`deliver`](https://github.com/KrauseFx/deliver): Upload screenshots, metadata and your app to the App Store using a single command
94
+ - [`snapshot`](https://github.com/KrauseFx/snapshot): Automate taking localized screenshots of your iOS app on every device
95
+ - [`frameit`](https://github.com/KrauseFx/frameit): Quickly put your screenshots into the right device frames
96
+ - [`PEM`](https://github.com/KrauseFx/pem): Automatically generate and renew your push notification profiles
97
+ - [`sigh`](https://github.com/KrauseFx/sigh): Because you would rather spend your time building stuff than fighting provisioning
98
+ - [`produce`](https://github.com/KrauseFx/produce): Create new iOS apps on iTunes Connect and Dev Portal using the command line
99
+ - [`cert`](https://github.com/KrauseFx/cert): Create new iOS signing certificates
100
+
101
+ ##### [Get informed about new fastlane tools and features](https://tinyletter.com/krausefx)
102
+
103
+ # Considerations
104
+ As part of the process of downloading promo codes from iTunes Connect, the user would normally have to accept a contract every single time. Since there is no way to check with iTunes if this contract was accepted manually before, `codes` agrees to this contract automatically. Before using `codes` for the first time, we advise you to go to iTunes Connect and go through the process of creating promo codes manually at least once and to read the contract when it comes up.
105
+
106
+ # Need help?
107
+ - If there is a technical problem with ```codes```, submit an issue.
108
+ - I'm available for contract work - drop me an email: codes@krausefx.com
109
+
110
+ # License
111
+ This project is licensed under the terms of the MIT license. See the LICENSE file.
112
+
113
+ # Contributing
114
+
115
+ 1. Create an issue to discuss about your idea
116
+ 2. Fork it (https://github.com/KrauseFx/codes/fork)
117
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
119
+ 5. Push to the branch (`git push origin my-new-feature`)
120
+ 6. Create a new Pull Request
data/bin/codes ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("../../lib", __FILE__)
4
+
5
+ require 'codes'
6
+ require 'commander'
7
+ require 'credentials_manager/appfile_config'
8
+ require 'fastlane_core'
9
+
10
+ HighLine.track_eof = false
11
+
12
+ class CodesApplication
13
+ include Commander::Methods
14
+
15
+ def run
16
+ program :version, Codes::VERSION
17
+ program :description, 'CLI for \'codes\' - Create promo codes for iOS Apps using the command line'
18
+ program :help, 'Author', 'Felix Krause <codes@krausefx.com>'
19
+ program :help, 'Website', 'http://fastlane.tools'
20
+ program :help, 'GitHub', 'https://github.com/krausefx/codes'
21
+ program :help_formatter, :compact
22
+
23
+ always_trace!
24
+
25
+ global_option '-u', '--username STRING', 'Your iTunes Connect username'
26
+ global_option '-a', '--app_identifier STRING', 'The bundle ID to download promo codes for'
27
+ global_option '-i', '--apple_id STRING', 'The App ID to download promo codes for'
28
+ global_option '-o', '--output_file STRING', 'The name of the file that should be written to disk. If the file exists, the new codes will be appended.'
29
+
30
+
31
+ command :download do |c|
32
+ c.syntax = "cert download [num]"
33
+ c.description = "Download [num] new promo codes from iTunes Connect"
34
+
35
+ c.action do |args, options|
36
+ user = username options
37
+ number_of_codes = count(args)
38
+ apple_id = apple_id(options)
39
+ app_identifier = bundle_id(options, apple_id)
40
+
41
+ Codes::CodesRunner.run(number_of_codes: number_of_codes, app_identifier: app_identifier, apple_id: apple_id, output_file_path: options.output_file)
42
+ end
43
+ end
44
+
45
+ default_command :download
46
+
47
+ def count(args)
48
+ [args[0].to_i, 1].max # minimum of 1 code
49
+ end
50
+
51
+ def username(options)
52
+ user = options.username
53
+ user ||= ENV["CODES_USERNAME"]
54
+ user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
55
+
56
+
57
+ CredentialsManager::PasswordManager.shared_manager(user) if user
58
+
59
+ user
60
+ end
61
+
62
+ def bundle_id(options, apple_id)
63
+ app_identifier = options.app_identifier
64
+ app_identifier ||= ENV["CODES_APP_IDENTIFIER"]
65
+ app_identifier ||= CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
66
+ app_identifier ||= (FastlaneCore::ItunesSearchApi.fetch(apple_id)['bundleId'] rescue nil) if apple_id
67
+ app_identifier ||= ask("App Identifier (Bundle ID, e.g. com.krausefx.app): ")
68
+ app_identifier
69
+ end
70
+
71
+ def apple_id(options)
72
+ apple_id = options.apple_id
73
+ apple_id ||= ENV["CODES_APP_ID"]
74
+ end
75
+
76
+ run!
77
+ end
78
+ end
79
+
80
+ CodesApplication.new.run
data/lib/codes.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'codes/version'
2
+ require 'codes/dependency_checker'
3
+ require 'codes/codes_runner'
4
+ require 'codes/itunes_connect'
5
+
6
+ require 'fastlane_core'
7
+
8
+ module Codes
9
+ Helper = FastlaneCore::Helper
10
+
11
+ FastlaneCore::UpdateChecker.verify_latest_version('codes', Codes::VERSION)
12
+ DependencyChecker.check_dependencies
13
+ end
@@ -0,0 +1,7 @@
1
+ module Codes
2
+ class CodesRunner
3
+ def self.run(args)
4
+ FastlaneCore::ItunesConnect.new.run args
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Codes
2
+ class DependencyChecker
3
+ def self.check_dependencies
4
+ true # we don't have any dependencies currently, method is implemented for consistency with other fastlane tools
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,76 @@
1
+ require 'fastlane_core/itunes_connect/itunes_connect'
2
+ require 'deliver'
3
+ require 'deliver/app'
4
+
5
+ module FastlaneCore
6
+ class ItunesConnect
7
+
8
+ PROMO_URL = "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa/LCAppPage/viewPromoCodes?adamId="
9
+
10
+ def run(args)
11
+ number_of_codes = args[:number_of_codes]
12
+
13
+ code_or_codes = number_of_codes == 1 ? "code" : "codes"
14
+ Helper.log.info "Downloading #{number_of_codes} promo #{code_or_codes}..."
15
+
16
+
17
+ app_id = args[:apple_id]
18
+ app_id ||= (FastlaneCore::ItunesSearchApi.fetch_by_identifier(args[:app_identifier])['trackId'] rescue nil)
19
+
20
+ app_identifier = args[:app_identifier]
21
+
22
+ if app_id.to_i == 0 or app_identifier.to_s.length == 0
23
+ raise "Could not find app using the following information: #{args}. Maybe the app is not in the store. Pass the Apple ID of the app as well!".red
24
+ end
25
+
26
+ # Use Pathname because it correctly handles the distinction between relative paths vs. absolute paths
27
+ output_file_path = Pathname.new(args[:output_file_path]) if args[:output_file_path]
28
+ output_file_path ||= Pathname.new(File.join(Dir.getwd, "#{app_identifier || app_id}_codes.txt"))
29
+ raise "Insufficient permissions to write to output file".red if File.exists?(output_file_path) and not File.writable?(output_file_path)
30
+ visit PROMO_URL << app_id.to_s
31
+
32
+ begin
33
+ text_fields = wait_for_elements("input[type=text]")
34
+ rescue
35
+ raise "Could not open details page for app #{app_identifier}. Are you sure you are using the correct apple account and have access to this app?".red
36
+ end
37
+ raise "There should only be a single text input field to specify the number of codes".red unless text_fields.count == 1
38
+
39
+ text_fields.first.set(number_of_codes.to_s)
40
+ click_next
41
+ Helper.log.debug "Accepting the App Store Volume Custom Code Agreement"
42
+ wait_for_elements("input[type=checkbox]").first.click
43
+ click_next
44
+
45
+ # the find(:xpath, "..") gets the parent element of the previous expression
46
+ download_url = wait_for_elements("a > img").first.find(:xpath, '..')['href']
47
+
48
+ codes = download_codes download_url
49
+
50
+ bytes_written = File.write(output_file_path.to_s, codes, mode: "a+")
51
+ Helper.log.warn "Could not write your codes to the codes.txt file, but you can still access them from iTunes Connect later" if bytes_written == 0
52
+ Helper.log.info "Added generated codes to '#{output_file_path.to_s}'".green unless bytes_written == 0
53
+
54
+ Helper.log.info "Your codes were succesfully downloaded:".green
55
+ puts codes
56
+ end
57
+
58
+ def click_next
59
+ wait_for_elements("input.continueActionButton").first.click
60
+ end
61
+
62
+ def download_codes(url)
63
+ host = Capybara.current_session.current_host
64
+ url = URI.join(host, url)
65
+ Helper.log.debug "Downloading promo code file from #{url}"
66
+
67
+ cookie_string = ""
68
+ page.driver.cookies.each do |key, cookie|
69
+ cookie_string << "#{cookie.name}=#{cookie.value};"
70
+ end
71
+
72
+ open(url, "Cookie" => cookie_string).read
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module Codes
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felix Krause
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fastlane_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.7.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.7.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.19.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.19.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: codeclimate-test-reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Create promo codes for iOS Apps using the command line
126
+ email:
127
+ - codes@krausefx.com
128
+ executables:
129
+ - codes
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - LICENSE
134
+ - README.md
135
+ - bin/codes
136
+ - lib/codes.rb
137
+ - lib/codes/codes_runner.rb
138
+ - lib/codes/dependency_checker.rb
139
+ - lib/codes/itunes_connect.rb
140
+ - lib/codes/version.rb
141
+ homepage: http://fastlane.tools
142
+ licenses:
143
+ - MIT
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: 2.0.0
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.2.2
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Create promo codes for iOS Apps using the command line
165
+ test_files: []
166
+ has_rdoc: