├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin └── firim ├── fastlane-plugin-firim ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── circle.yml ├── fastlane-plugin-firim.gemspec ├── fastlane │ ├── Fastfile │ └── Pluginfile ├── lib │ └── fastlane │ │ └── plugin │ │ ├── firim.rb │ │ └── firim │ │ ├── actions │ │ └── firim_action.rb │ │ ├── helper │ │ └── firim_helper.rb │ │ └── version.rb └── spec │ ├── firim_action_spec.rb │ └── spec_helper.rb ├── firim.gemspec ├── lib ├── assets │ └── FirimfileDefault ├── firim.rb └── firim │ ├── account_manager.rb │ ├── commands_generator.rb │ ├── detect_values.rb │ ├── options.rb │ ├── runner.rb │ ├── setup.rb │ └── version.rb └── test ├── firim_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | .DS_Store 11 | firim*.gem -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: ruby 3 | rvm: 4 | - 2.3.0 5 | before_install: gem install bundler -v 1.12.5 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This code of conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at whlsxl@gmail.com. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 45 | version 1.3.0, available at 46 | [http://contributor-covenant.org/version/1/3/0/][version] 47 | 48 | [homepage]: http://contributor-covenant.org 49 | [version]: http://contributor-covenant.org/version/1/3/0/ -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in firim.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 whlsxl 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ***Important*** 2 | 3 | ***For the reason of fir.im had changed the Base URL, pls set `firim_api_url` to `https://fir-api.fircli.cn/` or `https://api.bq04.com`.*** [issue](https://github.com/whlsxl/firim/issues/26) 4 | 5 | From v0.2.5, the default `firim_api_url` set to `https://api.bq04.com`. 6 | 7 | From firim v0.2.6, add show download url in terminal. [issue](https://github.com/whlsxl/firim/issues/32) 8 | # Firim 9 | 10 | Firim is a command tool to directly upload ipa and change app infomation on fir.im. fir.im is a Beta APP host website, you can upload ipa for AdHoc or InHouse distribution for testing. 11 | 12 | ## Getting Started 13 | 14 | Add this line to your application's Gemfile: 15 | 16 | ```ruby 17 | gem 'firim' 18 | ``` 19 | 20 | And then execute: 21 | 22 | $ bundle 23 | 24 | Or install it yourself as: 25 | 26 | $ gem install firim 27 | 28 | ## Quick Start 29 | 30 | * `cd [your_project_folder]` 31 | * `firim init` 32 | * Enter your fir.im API Token (From [Fir.im](https://fir.im/apps)) 33 | * `firim -i [your_ipa_path]` 34 | 35 | # Usage 36 | 37 | Use with fastlane [fastlane-plugin-firim](fastlane-plugin-firim/) 38 | 39 | You can specify the app infomations in `Firimfile`, To get a list of available options run 40 | 41 | firim --help 42 | 43 | Upload with icon ***NOTICE: Icon must be jpg format*** 44 | 45 | firim -i [your_ipa_path] -l [your_icon_path] 46 | 47 | Use `firim_api_url` to set API URL, if `fir.im` change the Base URL. default is `https://api.fir.im`. 48 | 49 | ## Export environments 50 | 51 | After upload app to fir.im, firim will export some environment variables. 52 | 53 | * `FIRIM_APP_SHORT` app's short path 54 | * `FIRIM_APP_NAME` app's name 55 | * `FIRIM_MASTER_RELEASE_ID` app's master_release_id 56 | * `FIRIM_APP_URL` the download page of the app 57 | 58 | All other App Info export as `FIRIM_#{key}`, like `FIRIM_icon_url` 59 | 60 | # Assign API Token 61 | 62 | There are three ways to assign Firim API Token 63 | 64 | 1. Set `FIRIM_TOKEN` environment variables 65 | 2. Add `token` to `macOS Keychain` 66 | 3. Set in `Firimfile` 67 | 68 | `Firim` will check the value from 1 to 3. Run `Firim` will add `token` to `keychain` in interactive shell. Also can use `firim addtoken` and `firim removetoken` to add or remove `token`. 69 | 70 | 71 | # Need help? 72 | 73 | Please submit an issue on GitHub and provide information about your setup 74 | 75 | 76 | ## Contributing 77 | 78 | Bug reports and pull requests are welcome on GitHub at [https://github.com/whlsxl/firim](https://github.com/whlsxl/firim). This project is intended to be a safe, welcoming space for collaboration. 79 | 80 | 81 | ## License 82 | 83 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 84 | 85 | # TODO 86 | 87 | - [ ] Generate a web page show all the app's link and infomations 88 | - [x] Show the app list, and export all app infomations to a file 89 | - [ ] force reset icon 90 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rake/testtask" 3 | 4 | Rake::TestTask.new(:test) do |t| 5 | t.libs << "test" 6 | t.libs << "lib" 7 | t.test_files = FileList['test/**/*_test.rb'] 8 | end 9 | 10 | task :default => :test 11 | -------------------------------------------------------------------------------- /bin/firim: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $:.push File.expand_path("../../lib", __FILE__) 3 | 4 | require 'firim' 5 | Firim::CommandsGenerator.start -------------------------------------------------------------------------------- /fastlane-plugin-firim/.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | 4 | ## Documentation cache and generated files: 5 | /.yardoc/ 6 | /_yardoc/ 7 | /doc/ 8 | /rdoc/ 9 | fastlane/README.md 10 | fastlane/report.xml 11 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | --color 3 | --format d 4 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/.rubocop.yml: -------------------------------------------------------------------------------- 1 | # kind_of? is a good way to check a type 2 | Style/ClassCheck: 3 | EnforcedStyle: kind_of? 4 | 5 | # It's better to be more explicit about the type 6 | Style/BracesAroundHashParameters: 7 | Enabled: false 8 | 9 | # specs sometimes have useless assignments, which is fine 10 | Lint/UselessAssignment: 11 | Exclude: 12 | - '**/spec/**/*' 13 | 14 | # We could potentially enable the 2 below: 15 | Style/IndentHash: 16 | Enabled: false 17 | 18 | Style/AlignHash: 19 | Enabled: false 20 | 21 | # HoundCI doesn't like this rule 22 | Style/DotPosition: 23 | Enabled: false 24 | 25 | # We allow !! as it's an easy way to convert ot boolean 26 | Style/DoubleNegation: 27 | Enabled: false 28 | 29 | # Sometimes we allow a rescue block that doesn't contain code 30 | Lint/HandleExceptions: 31 | Enabled: false 32 | 33 | # Cop supports --auto-correct. 34 | Lint/UnusedBlockArgument: 35 | Enabled: false 36 | 37 | # Needed for $verbose 38 | Style/GlobalVars: 39 | Enabled: false 40 | 41 | # We want to allow class Fastlane::Class 42 | Style/ClassAndModuleChildren: 43 | Enabled: false 44 | 45 | # $? Exit 46 | Style/SpecialGlobalVars: 47 | Enabled: false 48 | 49 | Metrics/AbcSize: 50 | Enabled: false 51 | 52 | Metrics/MethodLength: 53 | Enabled: false 54 | 55 | Metrics/CyclomaticComplexity: 56 | Enabled: false 57 | 58 | # The %w might be confusing for new users 59 | Style/WordArray: 60 | MinSize: 19 61 | 62 | # raise and fail are both okay 63 | Style/SignalException: 64 | Enabled: false 65 | 66 | # Better too much 'return' than one missing 67 | Style/RedundantReturn: 68 | Enabled: false 69 | 70 | # Having if in the same line might not always be good 71 | Style/IfUnlessModifier: 72 | Enabled: false 73 | 74 | # and and or is okay 75 | Style/AndOr: 76 | Enabled: false 77 | 78 | # Configuration parameters: CountComments. 79 | Metrics/ClassLength: 80 | Max: 320 81 | 82 | 83 | # Configuration parameters: AllowURI, URISchemes. 84 | Metrics/LineLength: 85 | Max: 370 86 | 87 | # Configuration parameters: CountKeywordArgs. 88 | Metrics/ParameterLists: 89 | Max: 17 90 | 91 | Metrics/PerceivedComplexity: 92 | Max: 18 93 | 94 | # Sometimes it's easier to read without guards 95 | Style/GuardClause: 96 | Enabled: false 97 | 98 | # We allow both " and ' 99 | Style/StringLiterals: 100 | Enabled: false 101 | 102 | # something = if something_else 103 | # that's confusing 104 | Style/ConditionalAssignment: 105 | Enabled: false 106 | 107 | # Better to have too much self than missing a self 108 | Style/RedundantSelf: 109 | Enabled: false 110 | 111 | # e.g. 112 | # def self.is_supported?(platform) 113 | # we may never use `platform` 114 | Lint/UnusedMethodArgument: 115 | Enabled: false 116 | 117 | # the let(:key) { ... } 118 | Lint/ParenthesesAsGroupedExpression: 119 | Exclude: 120 | - '**/spec/**/*' 121 | 122 | # This would reject is_ in front of methods 123 | # We use `is_supported?` everywhere already 124 | Style/PredicateName: 125 | Enabled: false 126 | 127 | # We allow the $ 128 | Style/PerlBackrefs: 129 | Enabled: false 130 | 131 | # Disable '+ should be surrounded with a single space' for xcodebuild_spec.rb 132 | Style/SpaceAroundOperators: 133 | Exclude: 134 | - '**/spec/actions_specs/xcodebuild_spec.rb' 135 | 136 | AllCops: 137 | Include: 138 | - '**/fastlane/Fastfile' 139 | Exclude: 140 | - '**/lib/assets/custom_action_template.rb' 141 | - './vendor/**/*' 142 | 143 | # We're not there yet 144 | Style/Documentation: 145 | Enabled: false 146 | 147 | # Added after upgrade to 0.38.0 148 | Style/MutableConstant: 149 | Enabled: false 150 | 151 | # length > 0 is good 152 | Style/ZeroLengthPredicate: 153 | Enabled: false 154 | 155 | # Adds complexity 156 | Style/IfInsideElse: 157 | Enabled: false 158 | 159 | # Sometimes we just want to 'collect' 160 | Style/CollectionMethods: 161 | Enabled: false 162 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/.travis.yml: -------------------------------------------------------------------------------- 1 | # os: osx # enable this if you need macOS support 2 | language: ruby 3 | rvm: 4 | - 2.2.4 5 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') 6 | eval(File.read(plugins_path), binding) if File.exist?(plugins_path) 7 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 whlsxl 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. 22 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/README.md: -------------------------------------------------------------------------------- 1 | # firim plugin 2 | 3 | [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-firim) 4 | 5 | ## Getting Started 6 | 7 | This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-firim`, add it to your project by running: 8 | 9 | ```bash 10 | fastlane add_plugin firim 11 | ``` 12 | 13 | ## Example 14 | 15 | Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`. 16 | 17 | ## About firim 18 | 19 | Directly upload ipa to fir.im in fastlane. 20 | 21 | ## Issues and Feedback 22 | 23 | For any other issues and feedback about this plugin, please submit it to this repository. 24 | 25 | ## Troubleshooting 26 | 27 | If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo. 28 | 29 | ## Using `fastlane` Plugins 30 | 31 | For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md). 32 | 33 | ## About `fastlane` 34 | 35 | `fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools). 36 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | require 'rspec/core/rake_task' 4 | RSpec::Core::RakeTask.new 5 | 6 | require 'rubocop/rake_task' 7 | RuboCop::RakeTask.new(:rubocop) 8 | 9 | task default: [:spec, :rubocop] 10 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/circle.yml: -------------------------------------------------------------------------------- 1 | test: 2 | override: 3 | - bundle exec rake 4 | machine: 5 | ruby: 6 | version: 2.2.4 7 | # Enable xcode below if you need macOS 8 | # xcode: 9 | # version: "7.3" 10 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/fastlane-plugin-firim.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'fastlane/plugin/firim/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'fastlane-plugin-firim' 8 | spec.version = Fastlane::Firim::VERSION 9 | spec.author = %q{whlsxl} 10 | spec.email = %q{whlsxl@gmail.com} 11 | 12 | spec.summary = %q{firim} 13 | spec.homepage = "https://github.com/whlsxl/firim/tree/master/fastlane-plugin-firim" 14 | spec.license = "MIT" 15 | 16 | spec.files = Dir["lib/**/*"] + %w(README.md LICENSE) 17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 18 | spec.require_paths = ['lib'] 19 | 20 | # spec.add_dependency 'your-dependency', '~> 1.0.0' 21 | 22 | # fastlane dependencies 23 | spec.add_dependency 'firim', '~> 0' 24 | 25 | # Development only 26 | spec.add_development_dependency 'pry' 27 | spec.add_development_dependency 'bundler' 28 | spec.add_development_dependency 'rspec' 29 | spec.add_development_dependency 'rake' 30 | spec.add_development_dependency 'rubocop' 31 | spec.add_development_dependency 'fastlane', '>= 1.104.0' 32 | end 33 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | lane :test do 2 | firim 3 | end 4 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/fastlane/Pluginfile: -------------------------------------------------------------------------------- 1 | # Autogenerated by fastlane 2 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/lib/fastlane/plugin/firim.rb: -------------------------------------------------------------------------------- 1 | require 'commander' 2 | require 'fastlane/plugin/firim/version' 3 | 4 | module Fastlane 5 | module Firim 6 | # Return all .rb files inside the "actions" and "helper" directory 7 | def self.all_classes 8 | Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))] 9 | end 10 | end 11 | end 12 | 13 | # By default we want to import all available actions and helpers 14 | # A plugin can contain any number of actions and plugins 15 | Fastlane::Firim.all_classes.each do |current| 16 | require current 17 | end 18 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/lib/fastlane/plugin/firim/actions/firim_action.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module Actions 3 | class FirimAction < Action 4 | def self.run(config) 5 | require 'firim' 6 | config.load_configuration_file('Firimfile') 7 | 8 | if !config[:ipa] 9 | config[:ipa] = Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] if Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] 10 | end 11 | 12 | ::Firim::Runner.new(config).run 13 | end 14 | 15 | def self.description 16 | "Uses firim to upload ipa/apk to fir.im" 17 | end 18 | 19 | def self.authors 20 | ["whlsxl"] 21 | end 22 | 23 | def self.available_options 24 | require "firim" 25 | require "firim/options" 26 | FastlaneCore::CommanderGenerator.new.generate(::Firim::Options.available_options) 27 | end 28 | 29 | # support ios/android now 30 | def self.is_supported?(platform) 31 | [:ios, :android].include?(platform) 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/lib/fastlane/plugin/firim/helper/firim_helper.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module Helper 3 | class FirimHelper 4 | # class methods that you define here become available in your action 5 | # as `Helper::FirimHelper.your_method` 6 | # 7 | def self.show_message 8 | UI.message("Hello from the firim plugin helper!") 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/lib/fastlane/plugin/firim/version.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module Firim 3 | VERSION = "0.2.2" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/spec/firim_action_spec.rb: -------------------------------------------------------------------------------- 1 | describe Fastlane::Actions::FirimAction do 2 | describe '#run' do 3 | it 'prints a message' do 4 | expect(Fastlane::UI).to receive(:message).with("The firim plugin is working!") 5 | 6 | Fastlane::Actions::FirimAction.run(nil) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /fastlane-plugin-firim/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | 3 | # This module is only used to check the environment is currently a testing env 4 | module SpecHelper 5 | end 6 | 7 | require 'fastlane' # to import the Action super class 8 | require 'fastlane/plugin/firim' # import the actual plugin 9 | 10 | Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values) 11 | -------------------------------------------------------------------------------- /firim.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'firim/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "firim" 8 | spec.version = Firim::VERSION 9 | spec.authors = ["whlsxl"] 10 | spec.email = ["whlsxl+g@gmail.com"] 11 | 12 | spec.summary = %q{fir.im command tool} 13 | spec.description = "fir.im command tool,\n Upload ipa to fir.im" 14 | spec.homepage = "https://github.com/whlsxl/firim" 15 | spec.license = "MIT" 16 | 17 | spec.files = Dir["lib/**/*"] + %w( bin/firim README.md ) 18 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 19 | spec.require_paths = ["lib"] 20 | 21 | # fastlane dependencies 22 | spec.add_dependency 'fastlane', '>= 2.1.0', '< 3.0.0' 23 | # spec.add_dependency 'faraday', '>= 0.17', '< 2.0' 24 | # spec.add_dependency 'faraday_middleware', '>= 0.13.1', '< 2.0' 25 | 26 | spec.add_development_dependency "bundler", "~> 1.12" 27 | spec.add_development_dependency "rake", "~> 10.0" 28 | spec.add_development_dependency "minitest", "~> 5.0" 29 | end 30 | -------------------------------------------------------------------------------- /lib/assets/FirimfileDefault: -------------------------------------------------------------------------------- 1 | ###################### More Options ###################### 2 | # If you want to have even more control, check out the documentation 3 | # https://github.com/fastlane/fastlane/blob/master/deliver/Deliverfile.md 4 | 5 | firim_api_token "[[FIRIM_API_TOKEN]]" # The fir.im api token 6 | -------------------------------------------------------------------------------- /lib/firim.rb: -------------------------------------------------------------------------------- 1 | require 'firim/commands_generator' 2 | require 'firim/detect_values' 3 | require 'firim/options' 4 | require 'firim/runner' 5 | require 'firim/setup' 6 | require "firim/version" 7 | require "firim/account_manager" 8 | 9 | require 'fastlane_core' 10 | 11 | module Firim 12 | class << self 13 | end 14 | 15 | Helper = FastlaneCore::Helper # you gotta love Ruby: Helper.* should use the Helper class contained in FastlaneCore 16 | UI = FastlaneCore::UI 17 | 18 | # Constant that captures the root Pathname for the project. Should be used for building paths to assets or other 19 | # resources that code needs to locate locally 20 | ROOT = Pathname.new(File.expand_path('../..', __FILE__)) 21 | end 22 | -------------------------------------------------------------------------------- /lib/firim/account_manager.rb: -------------------------------------------------------------------------------- 1 | require 'security' 2 | require 'highline/import' # to hide the entered password 3 | 4 | module Firim 5 | class AccountManager 6 | DEFAULT_PREFIX = "firim" 7 | DEFAULT_USERNAME = "default" 8 | # @param prefix [String] Very optional, is used for the 9 | # prefix on keychain 10 | # @param note [String] An optional note that will be shown next 11 | # to the token and token prompt 12 | def initialize(user: nil, token: nil, prefix: nil, note: nil) 13 | @prefix = prefix || DEFAULT_PREFIX 14 | 15 | @user = user 16 | @token = token 17 | @note = note 18 | end 19 | 20 | # Is the prefix default prefix "firim" 21 | def default_prefix? 22 | @prefix == DEFAULT_PREFIX 23 | end 24 | 25 | def fetch_token_from_env 26 | ENV["FIRIM_TOKEN"] 27 | end 28 | 29 | def token(ask_if_missing: true) 30 | @token ||= fetch_token_from_env 31 | 32 | unless @token 33 | item = Security::InternetPassword.find(server: server_name) 34 | @token ||= item.password if item 35 | end 36 | ask_for_token while ask_if_missing && @token.to_s.length == 0 37 | return @token 38 | end 39 | 40 | def add_to_keychain 41 | Security::InternetPassword.add(server_name, @user, token) 42 | end 43 | 44 | def remove_from_keychain 45 | Security::InternetPassword.delete(server: server_name) 46 | @token = nil 47 | end 48 | 49 | def server_name 50 | "#{@prefix}.#{user_or_defualt}" 51 | end 52 | 53 | def user_or_defualt 54 | if @user.to_s.length == 0 55 | return DEFAULT_USERNAME 56 | end 57 | @user 58 | end 59 | 60 | def ask_for_token 61 | puts "-------------------------------------------------------------------------------------".green 62 | puts "Please provide your Firim Token".green 63 | puts "The Token you enter will be stored in your macOS Keychain".green 64 | if default_prefix? 65 | # We don't want to show this message, if we ask for the application specific token 66 | # which has a different prefix 67 | puts "You can also pass the token using the `FIRIM_TOKEN` environment variable".green 68 | end 69 | puts "Or fill in Firimfile `firim_api_token`".green 70 | puts "-------------------------------------------------------------------------------------".green 71 | 72 | if @user.to_s.length == 0 73 | raise "running in non-interactive shell" if $stdout.isatty == false 74 | prompt_text = "Username(not necessary)" 75 | prompt_text += " (#{@note})" if @note 76 | prompt_text += ": " 77 | @user = ask(prompt_text) 78 | end 79 | 80 | while @token.to_s.length == 0 81 | raise "Missing Token for #{user_or_defualt}, and running in non-interactive shell" if $stdout.isatty == false 82 | note = @note + " " if @note 83 | @token = ask("Token (#{note}for #{user_or_defualt}): ") { |q| q.echo = "*" } 84 | end 85 | 86 | return true if (/darwin/ =~ RUBY_PLATFORM).nil? # mac?, since we don't have access to the helper here 87 | 88 | # Now we store this information in the keychain 89 | if add_to_keychain 90 | return true 91 | else 92 | puts "Could not store token in keychain".red 93 | return false 94 | end 95 | 96 | end 97 | end 98 | end -------------------------------------------------------------------------------- /lib/firim/commands_generator.rb: -------------------------------------------------------------------------------- 1 | require 'commander' 2 | 3 | module Firim 4 | class CommandsGenerator 5 | include Commander::Methods 6 | 7 | # def self.start 8 | # FastlaneCore::UpdateChecker.start_looking_for_update('deliver') 9 | # self.new.run 10 | # ensure 11 | # FastlaneCore::UpdateChecker.show_update_status('deliver', Deliver::VERSION) 12 | # end 13 | 14 | def self.start 15 | self.new.run 16 | end 17 | 18 | def run 19 | program :version, Firim::VERSION 20 | program :description, 'fir.im command tool' 21 | program :help, 'Author', 'Hailong Wang ' 22 | program :help, 'GitHub', 'https://github.com/whlsxl/firim' 23 | program :help_formatter, :compact 24 | 25 | FastlaneCore::CommanderGenerator.new.generate(Firim::Options.available_options) 26 | global_option('--verbose') { $verbose = true } 27 | 28 | always_trace! 29 | 30 | command :run do |c| 31 | c.syntax = 'firim' 32 | c.description = 'Upload binary and infomations to Fir.im' 33 | c.action do |args, options| 34 | options = FastlaneCore::Configuration.create(Firim::Options.available_options, options.__hash__) 35 | loaded = options.load_configuration_file("Firimfile") 36 | loaded = true if options[:firim_api_token] 37 | unless loaded 38 | if UI.confirm("No firim configuration found in the current directory. Do you want to setup firim?") 39 | require 'deliver/setup' 40 | Firim::Setup.new.run(options) 41 | return 0 42 | end 43 | end 44 | Firim::Runner.new(options).run 45 | end 46 | end 47 | 48 | command :init do |c| 49 | c.syntax = 'firim init' 50 | c.description = 'Create the initial `Firimfile` configuration' 51 | c.action do |args, options| 52 | if File.exist?("Firimfile") or File.exist?("fastlane/Firimfile") 53 | UI.important("You already got a running firim setup in this directory") 54 | return 0 55 | end 56 | 57 | require 'firim/setup' 58 | options = FastlaneCore::Configuration.create(Firim::Options.available_options, options.__hash__) 59 | Firim::Setup.new.run(options) 60 | end 61 | end 62 | 63 | command :addtoken do |c| 64 | c.syntax = 'firim addtoken' 65 | c.description = 'Add a firim api token to keychain. username is not necessary, Just a sign for multiple api token.' 66 | 67 | c.option '--username username', String, 'Username to add(not necessary).' 68 | c.option '--token token', String, 'API token to add' 69 | 70 | c.action do |args, options| 71 | username = options.username || ask('Username(not necessary): ') 72 | token = options.token || ask('Password: ') { |q| q.echo = '*'} 73 | 74 | add(username, token) 75 | 76 | puts "Token #{username || '`default`'}: #{'*' * token.length} added to keychain." 77 | end 78 | end 79 | 80 | # Command to remove credential from Keychain 81 | command :removetoken do |c| 82 | c.syntax = 'firim removetoken' 83 | c.description = 'Removes a firim token from the keychain.' 84 | 85 | c.option '--username username', String, 'Username to remove(or default).' 86 | 87 | c.action do |args, options| 88 | username = options.username || ask('Username: ') 89 | 90 | remove(username) 91 | end 92 | end 93 | 94 | default_command :run 95 | 96 | run! 97 | end 98 | 99 | 100 | private 101 | 102 | # Add entry to Apple Keychain 103 | def add(username, token) 104 | Firim::AccountManager.new( 105 | user: username, 106 | token: token 107 | ).add_to_keychain 108 | end 109 | 110 | # Remove entry from Apple Keychain using AccountManager 111 | def remove(username) 112 | Firim::AccountManager.new( 113 | user: username 114 | ).remove_from_keychain 115 | end 116 | end 117 | end -------------------------------------------------------------------------------- /lib/firim/detect_values.rb: -------------------------------------------------------------------------------- 1 | module Firim 2 | class DetectValues 3 | def run!(options) 4 | find_firim_api_token(options) 5 | find_app_identifier(options) 6 | find_app_name(options) 7 | find_version(options) 8 | find_build_version(options) 9 | end 10 | 11 | def find_app_identifier(options) 12 | identifier = FastlaneCore::IpaFileAnalyser.fetch_app_identifier(options[:ipa]) 13 | if identifier.to_s.length != 0 14 | options[:app_identifier] = identifier 15 | else 16 | UI.user_error!("Could not find ipa with app identifier '#{options[:app_identifier]}' in your iTunes Connect account (#{options[:username]} - Team: #{Spaceship::Tunes.client.team_id})") 17 | end 18 | end 19 | 20 | def find_app_name(options) 21 | return if options[:app_name] 22 | plist = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(options[:ipa]) 23 | options[:app_name] ||= plist['CFBundleDisplayName'] 24 | options[:app_name] ||= plist['CFBundleName'] 25 | end 26 | 27 | def find_version(options) 28 | options[:app_version] ||= FastlaneCore::IpaFileAnalyser.fetch_app_version(options[:ipa]) 29 | end 30 | 31 | def find_build_version(options) 32 | plist = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(options[:ipa]) 33 | options[:app_build_version] = plist['CFBundleVersion'] 34 | end 35 | 36 | def find_firim_api_token(options) 37 | option_token = options[:firim_api_token] 38 | keychain_token = Firim::AccountManager.new(user: options[:firim_username]) 39 | token = keychain_token.token(ask_if_missing: option_token == nil) 40 | if token 41 | options[:firim_api_token] = token 42 | return 43 | end 44 | 45 | options[:firim_api_token] ||= UI.input("The API Token of fir.im: ") 46 | end 47 | end 48 | 49 | class DetectAndroidValues 50 | def run!(options) 51 | find_firim_api_token(options) 52 | find_app_identifier(options) 53 | find_app_name(options) 54 | find_version(options) 55 | find_build_version(options) 56 | end 57 | 58 | def read_key_from_gradle_file(gradle_file, key) 59 | return nil if gradle_file == nil 60 | value = nil 61 | begin 62 | file = File.new(gradle_file, "r") 63 | while (line = file.gets) 64 | next unless line.include? key 65 | components = line.strip.split(' ') 66 | value = components[components.length - 1].tr("\"", "") 67 | break 68 | end 69 | file.close 70 | rescue => err 71 | UI.error("An exception occured while reading gradle file: #{err}") 72 | err 73 | end 74 | return value 75 | end 76 | 77 | def find_app_identifier(options) 78 | return if options[:app_identifier] 79 | options[:app_identifier] ||= self.read_key_from_gradle_file(options[:gradle_file], "applicationId") 80 | end 81 | 82 | def find_app_name(options) 83 | return if options[:app_name] 84 | options[:app_name] ||= self.read_key_from_gradle_file(options[:gradle_file], "appName") 85 | end 86 | 87 | def find_version(options) 88 | return if options[:app_version] 89 | options[:app_version] ||= self.read_key_from_gradle_file(options[:gradle_file], "versionName") 90 | end 91 | 92 | def find_build_version(options) 93 | return if options[:app_build_version] 94 | options[:app_build_version] ||= self.read_key_from_gradle_file(options[:gradle_file], "versionCode") 95 | end 96 | 97 | def find_firim_api_token(options) 98 | option_token = options[:firim_api_token] 99 | keychain_token = Firim::AccountManager.new(user: options[:firim_username]) 100 | token = keychain_token.token(ask_if_missing: option_token == nil) 101 | if token 102 | options[:firim_api_token] = token 103 | return 104 | end 105 | 106 | options[:firim_api_token] ||= UI.input("The API Token of fir.im: ") 107 | end 108 | 109 | end 110 | 111 | end 112 | -------------------------------------------------------------------------------- /lib/firim/options.rb: -------------------------------------------------------------------------------- 1 | require 'fastlane_core' 2 | require 'credentials_manager' 3 | 4 | module Firim 5 | class Options 6 | def self.available_options 7 | [ 8 | # firim platform 9 | FastlaneCore::ConfigItem.new(key: :platform, 10 | optional: true, 11 | description: "The fir platform, support ios/android"), 12 | # fir.im api url 13 | FastlaneCore::ConfigItem.new(key: :firim_api_url, 14 | default_value: "https://api.bq04.com", 15 | description: "fir.im api URL"), 16 | # firim info 17 | FastlaneCore::ConfigItem.new(key: :firim_api_token, 18 | short_option: "-a", 19 | optional: true, 20 | description: "fir.im user api token"), 21 | FastlaneCore::ConfigItem.new(key: :firim_username, 22 | optional: true, 23 | description: "fir.im username, a sign for identify different token"), 24 | 25 | FastlaneCore::ConfigItem.new(key: :download_page_prefix, 26 | short_option: "-p", 27 | optional: true, 28 | default_value: "http://d.firim.top/", 29 | description: "fir.im user api token"), 30 | # Content path 31 | FastlaneCore::ConfigItem.new(key: :ipa, 32 | optional: true, 33 | short_option: "-i", 34 | env_name: "DELIVER_IPA_PATH", 35 | description: "Path to your ipa file", 36 | default_value: Dir["*.ipa"].first, 37 | verify_block: proc do |value| 38 | UI.user_error!("Could not find ipa file at path '#{value}'") unless File.exist?(value) 39 | UI.user_error!("'#{value}' doesn't seem to be an ipa file") unless value.end_with?(".ipa") 40 | end), 41 | FastlaneCore::ConfigItem.new(key: :apk, 42 | optional: true, 43 | env_name: "DELIVER_APK_PATH", 44 | description: "Path to your apk file", 45 | default_value: Dir["app/build/outputs/apk/prod/release/*.apk"].first, 46 | verify_block: proc do |value| 47 | UI.user_error!("Could not find apk file at path '#{value}'") unless File.exist?(value) 48 | UI.user_error!("'#{value}' doesn't seem to be an apk file") unless value.end_with?(".apk") 49 | end, 50 | conflicting_options: [:ipa], 51 | conflict_block: proc do |value| 52 | UI.user_error!("You can't use 'apk' and '#{value.key}' options in one run.") 53 | end), 54 | FastlaneCore::ConfigItem.new(key: :gradle_file, 55 | short_option: "-g", 56 | optional: true, 57 | description: "Path to your gradle file"), 58 | FastlaneCore::ConfigItem.new(key: :icon, 59 | description: "Path to the app icon, MUST BE jpg", 60 | optional: true, 61 | short_option: "-l", 62 | verify_block: proc do |value| 63 | UI.user_error!("Could not find png file at path '#{value}'") unless File.exist?(value) 64 | UI.user_error!("'#{value}' doesn't seem to be a png file") unless value.end_with?(".jpg") 65 | end), 66 | 67 | FastlaneCore::ConfigItem.new(key: :file, 68 | optional: true, 69 | description: "Don't use this for upload file"), 70 | # APP info 71 | FastlaneCore::ConfigItem.new(key: :app_identifier, 72 | description: "The app's identifier", 73 | optional: true), 74 | FastlaneCore::ConfigItem.new(key: :app_name, 75 | description: "The app's name", 76 | optional: true), 77 | FastlaneCore::ConfigItem.new(key: :app_desc, 78 | description: "The app's desc", 79 | optional: true), 80 | FastlaneCore::ConfigItem.new(key: :app_short, 81 | description: "The app's short URL", 82 | optional: true), 83 | FastlaneCore::ConfigItem.new(key: :app_is_opened, 84 | description: "APP's download link whether opened", 85 | is_string: false, 86 | optional: true), 87 | FastlaneCore::ConfigItem.new(key: :app_is_show_plaza, 88 | description: "Whether the app show in plaza", 89 | is_string: false, 90 | # conflicting_options: [:app_is_opened], 91 | optional: true), 92 | FastlaneCore::ConfigItem.new(key: :app_passwd, 93 | description: "The app's download page password", 94 | # conflicting_options: [:app_is_opened, :app_is_show_plaza], 95 | optional: true), 96 | FastlaneCore::ConfigItem.new(key: :app_store_link_visible, 97 | description: "Whether show store link in download page", 98 | is_string: false, 99 | optional: true), 100 | FastlaneCore::ConfigItem.new(key: :app_version, 101 | description: "The app's version", 102 | optional: true), 103 | FastlaneCore::ConfigItem.new(key: :app_build_version, 104 | description: "The app's build version", 105 | optional: true), 106 | FastlaneCore::ConfigItem.new(key: :app_release_type, 107 | description: "The app's release type (Adhoc, Inhouse)", 108 | optional: true), 109 | FastlaneCore::ConfigItem.new(key: :app_changelog, 110 | description: "The app's changelog", 111 | optional: true), 112 | # To file 113 | FastlaneCore::ConfigItem.new(key: :app_info_to_file_path, 114 | description: "Append all [app's name] : [URL] to this file", 115 | optional: true) 116 | ] 117 | end 118 | end 119 | end 120 | -------------------------------------------------------------------------------- /lib/firim/runner.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' # HTTP Client 2 | require 'faraday_middleware' 3 | # require 'logger' 4 | 5 | module Firim 6 | class Runner 7 | attr_accessor :options 8 | attr_reader :firim_client 9 | 10 | def firim_hostname 11 | api_url = self.options[:firim_api_url] 12 | return api_url 13 | end 14 | 15 | def guess_platform 16 | return self.options[:platform] if self.options[:platform] 17 | if self.options[:ipa] 18 | return "ios" 19 | elsif self.options[:apk] 20 | return "android" 21 | else 22 | return nil 23 | end 24 | end 25 | 26 | def initialize(options) 27 | self.options = options 28 | @app_info = {} 29 | 30 | conn_options = { 31 | request: { 32 | timeout: 300, 33 | open_timeout: 300 34 | } 35 | } 36 | 37 | if self.options[:apk] 38 | self.options[:file] = self.options[:apk] 39 | else 40 | self.options[:file] = self.options[:ipa] 41 | end 42 | self.options[:platform] = self.guess_platform 43 | UI.user_error!("Platform not given --platform ios/android") if self.options[:platform] == nil 44 | 45 | @firim_client = Faraday.new(self.firim_hostname, conn_options) do |c| 46 | c.request :url_encoded # form-encode POST params 47 | c.adapter :net_http 48 | c.response :json, :content_type => /\bjson$/ 49 | end 50 | 51 | if self.options[:platform] == 'ios' 52 | Firim::DetectValues.new.run!(self.options) 53 | else 54 | Firim::DetectAndroidValues.new.run!(self.options) 55 | end 56 | 57 | FastlaneCore::PrintTable.print_values(config: options, title: "firim #{Firim::VERSION} Summary") 58 | end 59 | 60 | def run 61 | # FastlaneCore::PrintTable.print_values(config: get_app_info, title: "Current online infomation") 62 | @app_info.merge!( upload_binary_and_icon ) 63 | @app_info.merge!( update_app_info(@app_info["id"])) 64 | write_app_info_to_file 65 | options = @app_info 66 | options[:download_page_url] = download_url 67 | ENV["FIRIM_APP_URL"] = download_url 68 | ENV["FIRIM_APP_NAME"] = options["name"] 69 | ENV["FIRIM_APP_SHORT"] = options["short"] 70 | ENV["FIRIM_MASTER_RELEASE_ID"] = options["master_release_id"] 71 | options.each { |key, value| ENV["FIRIM_#{key}"] = "#{value}" } 72 | FastlaneCore::PrintTable.print_values(config: options, title: "#{@app_info["name"]}'s' App Info") 73 | end 74 | 75 | def write_app_info_to_file 76 | file_path = self.options[:app_info_to_file_path] 77 | return if file_path == nil 78 | File.open(file_path, "at") do |f| 79 | d_url = download_url 80 | f.write("#{@app_info["name"]}: #{d_url}\n") 81 | UI.success "Write app info to #{file_path} successed!" 82 | end 83 | end 84 | 85 | def download_url 86 | prefix = self.options[:download_page_prefix] 87 | if prefix[1..-1] != "/" 88 | return "#{prefix}/#{@app_info["short"]}" 89 | end 90 | return "#{prefix}#{@app_info["short"]}" 91 | end 92 | 93 | def validation_response response_data 94 | error_code = response_data['code'].to_i 95 | return if error_code == 0 96 | if error_code == 100020 97 | UI.user_error!("Firim API Token(#{options[:firim_api_token]}) not correct") 98 | else 99 | UI.user_error!("Firim API ERROR error_code: #{error_code}") 100 | end 101 | end 102 | 103 | def get_app_info 104 | app_info_path = "apps/latest/" + options[:app_identifier] 105 | response = self.firim_client.get app_info_path, { :api_token => options[:firim_api_token], :type => options[:platform] } 106 | info = response.body == nil ? {} : response.body 107 | validation_response info 108 | info 109 | end 110 | 111 | def upload_binary_and_icon 112 | upload_publish_path = "apps/" 113 | response = self.firim_client.post do |req| 114 | req.url upload_publish_path 115 | req.body = { :type => options[:platform], :bundle_id => options[:app_identifier], :api_token => options[:firim_api_token] } 116 | end 117 | info = response.body 118 | validation_response info 119 | begin 120 | if info['cert']['binary']['key'] == nil 121 | UI.user_error!("Response body ERROR: #{response.body}") 122 | end 123 | rescue Exception => e 124 | UI.user_error!("Response body ERROR: #{response.body}") 125 | end 126 | begin 127 | upload_binary info['cert']['binary'] 128 | upload_icon info['cert']['icon'] 129 | rescue Exception => e 130 | # raise UI.user_error!("Firim Server error #{e}\n #{info}") 131 | raise e 132 | end 133 | info.select { |k, v| ["id", "type", "short"].include?(k) } 134 | end 135 | 136 | def get_upload_conn 137 | conn_options = { 138 | request: { 139 | timeout: 1000, 140 | open_timeout: 300 141 | } 142 | } 143 | Faraday.new(nil, conn_options) do |c| 144 | c.request :multipart 145 | c.request :url_encoded 146 | c.response :json, content_type: /\bjson$/ 147 | c.adapter :net_http 148 | end 149 | end 150 | 151 | def upload_binary binary_info 152 | UI.user_error!("app_name did not provide --app_name [name]") if self.options[:app_name] == nil 153 | UI.user_error!("app_version did not provide --app_version [version]") if self.options[:app_version] == nil 154 | UI.user_error!("app_build_version did not provide --app_build_version [build_version]") if self.options[:app_build_version] == nil 155 | if self.options[:file] == nil 156 | if self.options[:platform] == "ios" 157 | UI.user_error!("ipa file did not provide --ipa [ipa_path]") 158 | else 159 | UI.user_error!("apk file did not provide --ipa [apk_path]") 160 | end 161 | end 162 | 163 | params = { 164 | 'key' => binary_info['key'], 165 | 'token' => binary_info['token'], 166 | 'file' => Faraday::UploadIO.new(self.options[:file], 'application/octet-stream'), 167 | 'x:name' => self.options[:app_name], 168 | 'x:version' => self.options[:app_version], 169 | 'x:build' => self.options[:app_build_version] 170 | } 171 | params['x:release_type'] = self.options[:app_release_type] if self.options[:app_release_type] 172 | params['x:changelog'] = self.options[:app_changelog] if self.options[:app_changelog] 173 | binary_conn = get_upload_conn 174 | UI.message "Start upload #{self.options[:app_name]} binary..." 175 | response = binary_conn.post binary_info['upload_url'], params 176 | unless response.body['is_completed'] 177 | raise UI.user_error!("Upload binary to Qiniu error #{response.body}") 178 | end 179 | UI.success 'Upload binary successed!' 180 | end 181 | 182 | def upload_icon icon_info 183 | return unless self.options[:icon] 184 | binary_conn = get_upload_conn 185 | params = { 186 | 'key' => icon_info['key'], 187 | 'token' => icon_info['token'], 188 | 'file' => Faraday::UploadIO.new(self.options[:icon], 'image/jpeg'), 189 | } 190 | UI.message "Start upload #{self.options[:app_name]} icon..." 191 | response = binary_conn.post icon_info['upload_url'], params 192 | unless response.body['is_completed'] 193 | raise UI.user_error!("Upload icon to Qiniu error #{response.body}") 194 | end 195 | UI.success 'Upload icon successed!' 196 | end 197 | 198 | def update_app_info id 199 | params = { 200 | :api_token => self.options[:firim_api_token], 201 | :id => id 202 | } 203 | ["name", "desc", "short", "is_opened", "is_show_plaza", "passwd", "store_link_visible"].each do |k| 204 | key = :"app_#{k}" 205 | params[k] = self.options[key] if self.options[key] != nil 206 | end 207 | 208 | update_app_info_path = "apps/#{id}" 209 | response = self.firim_client.put do |req| 210 | req.url update_app_info_path 211 | req.body = params 212 | end 213 | info = response.body 214 | validation_response info 215 | UI.success "Update app info successed!" 216 | return info 217 | end 218 | 219 | end 220 | end 221 | -------------------------------------------------------------------------------- /lib/firim/setup.rb: -------------------------------------------------------------------------------- 1 | 2 | module Firim 3 | class Setup 4 | def run(options) 5 | containing = (File.directory?("fastlane") ? 'fastlane' : '.') 6 | file_path = File.join(containing, 'Firimfile') 7 | data = generate_firim_file(containing, options) 8 | setup_firim(file_path, data, containing, options) 9 | end 10 | 11 | def generate_firim_file(firim_path, options) 12 | # Generate the final Firimfile here 13 | firim = File.read("#{Firim::ROOT}/lib/assets/FirimfileDefault") 14 | firim.gsub!("[[FIRIM_API_TOKEN]]", options[:firim_api_token]) 15 | return firim 16 | end 17 | 18 | def setup_firim(file_path, data, firim_path, options) 19 | File.write(file_path, data) 20 | 21 | UI.success("Successfully created new Firimfile at path '#{file_path}'") 22 | end 23 | 24 | end 25 | end -------------------------------------------------------------------------------- /lib/firim/version.rb: -------------------------------------------------------------------------------- 1 | module Firim 2 | VERSION = "0.2.9" 3 | end 4 | -------------------------------------------------------------------------------- /test/firim_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class FirimTest < Minitest::Test 4 | def test_that_it_has_a_version_number 5 | refute_nil ::Firim::VERSION 6 | end 7 | 8 | def test_it_does_something_useful 9 | assert false 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'firim' 3 | 4 | require 'minitest/autorun' 5 | --------------------------------------------------------------------------------