-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b8c592
commit 03348fa
Showing
7 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
require "fabricio/cli" | ||
|
||
Fabricio::CLI.start(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,21 @@ require 'fabricio/version' | |
Gem::Specification.new do |spec| | ||
spec.name = "fabricio" | ||
spec.version = Fabricio::VERSION | ||
spec.authors = ["Egor Tolstoy"] | ||
spec.email = ["[email protected]"] | ||
spec.authors = ["Egor Tolstoy", "Vadim Smal"] | ||
spec.emails = ["[email protected]", "[email protected]"] | ||
|
||
spec.summary = "A simple gem that fetches mobile application statistics from Fabric.io API." | ||
spec.license = "MIT" | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject do |f| | ||
f.match(%r{^(test|spec|features)/}) | ||
end | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
|
||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency 'faraday' | ||
spec.add_dependency "thor" | ||
|
||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require 'thor' | ||
require 'fabricio' | ||
require 'fileutils' | ||
require 'yaml' | ||
|
||
module Fabricio | ||
class CLI < Thor | ||
|
||
# Constants | ||
CREDENTIAL_DIRECTORY_PATH = "#{Dir.home}/.fabricio" | ||
CREDENTIAL_FILE_PATH = "#{CREDENTIAL_DIRECTORY_PATH}/.credential" | ||
FABRIC_GRAPHQL_API_URL = 'https://api-dash.fabric.io/graphql' | ||
|
||
desc "credential", "Setup credential" | ||
def credential | ||
say("Setup credential") | ||
credential = ask_credential | ||
|
||
tmp_client = Fabricio::Client.new do |config| | ||
config.username = credential.email | ||
config.password = credential.password | ||
end | ||
|
||
organization = tmp_client.organization.get | ||
unless organization.nil? | ||
say("Successful login to #{organization.name}") | ||
create_credential_file(email, password) | ||
else | ||
say("Login failed") | ||
end | ||
|
||
say("Complete!") | ||
end | ||
|
||
desc "organization", "Obtain organization" | ||
def organization | ||
say("#{client.organization.get.to_s}") | ||
end | ||
|
||
desc "apps", "Obtain all app" | ||
def apps | ||
say("#{client.app.all}") | ||
end | ||
|
||
desc "app", "Obtain single app" | ||
option :app_id => :required, :type => :string | ||
def app(app_id) | ||
say("#{client.app.get(app_id).to_s}") | ||
end | ||
|
||
desc "builds", "Obtain all builds" | ||
option :app_id => :required, :type => :string | ||
def builds(app_id) | ||
say("#{client.build.all(app_id).to_s}") | ||
end | ||
|
||
desc "build", "Obtain single build" | ||
option :app_id => :required, :type => :string | ||
option :version => :required, :type => :string | ||
option :build_number => :required, :type => :string | ||
def build(app_id, version, build_number) | ||
say("#{client.build.get(app_id, version, build_number).to_s}") | ||
end | ||
|
||
private | ||
def client | ||
email = "" | ||
password = "" | ||
if File.file?(CREDENTIAL_FILE_PATH) | ||
credential = YAML.load_file(CREDENTIAL_FILE_PATH) | ||
email = credential['email'] | ||
password = credential['password'] | ||
else | ||
ask_credential | ||
end | ||
|
||
client = Fabricio::Client.new do |config| | ||
config.username = email | ||
config.password = password | ||
end | ||
end | ||
|
||
def create_credential_file(credential) | ||
FileUtils.mkdir(CREDENTIAL_DIRECTORY_PATH) | ||
credential_hash = { | ||
"email" => credential.email, | ||
"password" => credential.password | ||
} | ||
File.open(CREDENTIAL_FILE_PATH,'w') do |f| | ||
f.write credential_hash.to_yaml | ||
end | ||
say("Your credential in #{CREDENTIAL_FILE_PATH}") | ||
end | ||
|
||
def ask_credential | ||
say("We have to know you're email from fabric account") | ||
email = ask("email: ") | ||
say("Now we want your password. Do not be afraid, it is stored locally") | ||
password = ask("password: ", :echo => false) | ||
say("") | ||
Fabricio::Model::Credential(email, password) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fabricio | ||
module Model | ||
# This model represents a credential | ||
class Credential | ||
attr_reader :email, :password | ||
|
||
# Returns a Credential model object | ||
# | ||
# @param email [String] | ||
# @param password [String] | ||
# @return [Fabricio::Model::Build] | ||
def initialize(email, password) | ||
@id = email | ||
@version = password | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ def initialize(attributes) | |
end | ||
end | ||
end | ||
end | ||
end |