Skip to content

Commit

Permalink
Fix session obtain
Browse files Browse the repository at this point in the history
  • Loading branch information
CognitiveDisson committed Feb 12, 2018
1 parent 37a2081 commit fb6c6e0
Show file tree
Hide file tree
Showing 24 changed files with 497 additions and 299 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ Or install it yourself as:
### CLI
#### Commands
```
fabricio app # Obtain single app
fabricio apps # Obtain all app
fabricio build # Obtain single build
fabricio builds # Obtain all builds
fabricio credential # Setup credential
fabricio help [COMMAND] # Describe available commands or one specific command
fabricio organization # Obtain organization
fabricio app get # Obtain single app
fabricio app all # Obtain all app
fabricio app active_now # Obtain active now count
fabricio app single_issue # Obtain single issue
fabricio app issue_session # Obtain single issue session
fabricio app latest_session # Obtain latest issue session
fabricio build get # Obtain single build
fabricio build all # Obtain all builds
fabricio version all # Obtain all versions
fabricio version top # Obtain top versions
fabricio organization get # Obtain organization
fabricio credential # Setup credential
fabricio help [COMMAND] # Describe available commands or one specific command
```
#### Example
```bash
Expand All @@ -63,9 +69,9 @@ email: [email protected]
Now we want your password. Do not be afraid, it is stored locally
password:
Successful login to TestOrganization
> fabricio organization
> fabricio organization get
{"id"=>"424423ac76fa54934e00a09b", "alias"=>"test", "name"=>"Test", "api_key"=>"19ac3e6195b1900ada120c1e0c1230a818626d55", "enrollments"=>{"answers_enhanced_feature_set_enabled_for_new_apps"=>"false", "answers_ip_address_tracking_enabled_for_new_apps"=>"true", "beta_distribution"=>"true"}, "accounts_count"=>100, "mopub_id"=>"11142", "sdk_organization"=>true, "apps_counts"=>{"ios"=>9}, "build_secret"=>"fdda1e597843e25731848bb46eec2cc893ea86847e22d5f44567ecd48ff4e32"}
> fabricio apps
> fabricio app all
...
```

Expand Down Expand Up @@ -172,7 +178,13 @@ Obtains the list of all application builds.

Obtains a specific build for a specific application.

#### `client.build.top_versions('app_id', 'start_timestamp', 'end_timestamp')`
### Version

#### `client.version.all('app_id', 'start_timestamp', 'end_timestamp')`

Obtains an array of all versions for a given application.

#### `client.version.top('app_id', 'start_timestamp', 'end_timestamp')`

Obtains an array of top versions for a given application.

Expand Down
34 changes: 34 additions & 0 deletions lib/fabricio/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,39 @@ def active_now(app_id)
end
end

desc "single_issue", "Obtain issue by external_id"
option :app_id => :required, :type => :string
option :external_id => :required, :type => :string
def issue(app_id, external_id)
if options[:short]
say("#{client.app.single_issue(app_id, external_id).pretty_print}")
else
say("#{client.app.single_issue(app_id, external_id).to_s}")
end
end

desc "issue_session", "Obtain session"
option :app_id => :required, :type => :string
option :external_id => :required, :type => :string
option :session_id => :required, :type => :string
def session(app_id, external_id, session_id)
if options[:short]
say("#{client.app.issue_session(app_id, external_id, session_id).pretty_print}")
else
say("#{client.app.issue_session(app_id, external_id, session_id).to_s}")
end
end

desc "latest_session", "Obtain latest issue session"
option :app_id => :required, :type => :string
option :external_id => :required, :type => :string
def latest_session(app_id, external_id)
if options[:short]
say("#{client.app.issue_session(app_id, external_id).pretty_print}")
else
say("#{client.app.issue_session(app_id, external_id).to_s}")
end
end

end
end
4 changes: 4 additions & 0 deletions lib/fabricio/cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'organization'
require_relative 'app'
require_relative 'build'
require_relative 'version'
require_relative 'cli_helper'

module Fabricio
Expand All @@ -19,6 +20,9 @@ class CLI < Thor
desc "build", "..."
subcommand "build", Build

desc "version", "..."
subcommand "version", Version

desc "credential", "Setup credential"
def credential
say("Setup credential")
Expand Down
41 changes: 41 additions & 0 deletions lib/fabricio/cli/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'thor'
require 'fabricio'
require 'fileutils'
require 'yaml'
require_relative 'cli_helper'

module Fabricio
class Version < Thor

desc "all", "Obtain all versions"
option :app_id => :required, :type => :string
option :short, :type => :boolean
def all(app_id)
if options[:short]
say("#{client.version.all(app_id)}")
else
say("#{client.version.all(app_id).to_s}")
end
end

desc "top", "Obtain single build"
option :app_id => :required, :type => :string
option :start_time, :type => :string
option :end_time, :type => :string
option :short, :type => :boolean
def top(app_id)
result = nil
if options[:start_time] && options[:end_time]
result = client.version.top(app_id, options[:start_time], options[:end_time])
else
result = client.version.top(app_id)
end
if options[:short]
say("#{client.version.top(app_id).pretty_print}")
else
say("#{client.version.top(app_id).to_s}")
end
end

end
end
2 changes: 2 additions & 0 deletions lib/fabricio/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'fabricio/services/organization_service'
require 'fabricio/services/app_service'
require 'fabricio/services/build_service'
require 'fabricio/services/version_service'
require 'fabricio/authorization/authorization_client'
require 'fabricio/authorization/session'
require 'fabricio/authorization/memory_session_storage'
Expand Down Expand Up @@ -58,6 +59,7 @@ def initialize(options =
@organization_service ||= Fabricio::Service::OrganizationService.new(session, network_client)
@app_service ||= Fabricio::Service::AppService.new(session, network_client)
@build_service ||= Fabricio::Service::BuildService.new(session, network_client)
@version_service ||= Fabricio::Service::VersionService.new(session, network_client)
end

# We use `method_missing` approach instead of explicit methods.
Expand Down
10 changes: 4 additions & 6 deletions lib/fabricio/models/issue_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Model
class IssueSession < AbstractModel
attr_reader :id,
:created_at,
:header_link
:next_session_id
:prev_session_id

Expand All @@ -15,11 +14,10 @@ class IssueSession < AbstractModel
# @param attributes [Hash]
# @return [Fabricio::Model::Build]
def initialize(attributes)
@id = attributes['session_id']
@created_at = attributes['created_at']
@header_link = attributes['header_link']
@next_session_id = attributes['next_session_id']
@prev_session_id = attributes['prev_session_id']
@id = attributes['externalId']
@created_at = attributes['createdAt']
@next_session_id = attributes['prevSessionId']
@prev_session_id = attributes['nextSessionId']
@json = attributes
end
end
Expand Down
67 changes: 15 additions & 52 deletions lib/fabricio/networking/app_request_model_factory.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
require 'json'
require 'fabricio/networking/request_model_factory'
require 'fabricio/networking/request_model'
require 'json'

module Fabricio
module Networking
# This factory creates request models for fetching data for App model object
class AppRequestModelFactory

# Server constants
FABRIC_API_URL = 'https://fabric.io'
FABRIC_GRAPHQL_API_URL = 'https://api-dash.fabric.io/graphql'
FABRIC_API_PATH = '/api/v2'
FABRIC_API_3_PATH = '/api/v3'
FABRIC_APPS_ENDPOINT = '/apps'
FABRIC_ORGANIZATIONS_ENDPOINT = '/organizations'
FABRIC_PROJECTS_ENDPOINT = '/projects'
class AppRequestModelFactory < RequestModelFactory

# Returns a request model for obtaining the list of all apps
#
Expand Down Expand Up @@ -261,7 +253,7 @@ def single_issue_request_model(app_id, issue_external_id, start_time, end_time)
model
end

# Returns a request model for obtaining the count of ooms
# Returns a request model for obtaining issue session
#
# @param app_id [String]
# @param issue_external_id [String] Issue external identifier
Expand All @@ -271,17 +263,23 @@ def issue_session_request_model(app_id, issue_external_id, session_id)
headers = {
'Content-Type' => 'application/json'
}
path = issue_session_endpoint(app_id, issue_external_id, session_id)
body = {
'query' => "query SingleSession($externalId_0:String!) {project(externalId:$externalId_0) {crashlytics {_session2RIRzK:session(externalId:\"#{session_id}\",issueId:\"#{issue_external_id}\") {externalId,createdAt,buildVersionId,prevSessionId,nextSessionId,sdk {display},os {platform,build,display,name,modified},orientation {device,ui},customLogs {time,message},customKeys {key,value},memory {free,used},storage {free,used},device {architecture,manufacturer,model,name,proximityOn,betaDeviceToken},user {externalId,name,email},stacktraces {exceptions {caption {title,subtitle},interesting,fatal,state,threadName,queueName,crash {name,code,address},exception {message,type,nested},frames {file,offset,line,address,symbol,rawSymbol,owner,library,blamed,native}},errors {caption {title,subtitle},interesting,fatal,state,threadName,queueName,crash {name,code,address},exception {message,type,nested},frames {file,offset,line,address,symbol,rawSymbol,owner,library,blamed,native}},threads {caption {title,subtitle},interesting,fatal,state,threadName,queueName,crash {name,code,address},exception {message,type,nested},frames {file,offset,line,address,symbol,rawSymbol,owner,library,blamed,native}}}}},id}}",
'variables' => {
'externalId_0' => app_id
}
}.to_json
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.type = :POST
config.base_url = FABRIC_GRAPHQL_API_URL
config.api_path = '?relayDebugName=SingleSession'
config.headers = headers
config.body = body
end
model
end

# Returns a request model for obtaining the count of ooms
# Returns a request model for add comment to issue
#
# @param app_id [String]
# @param issue_external_id [String] Issue external identifier
Expand Down Expand Up @@ -345,16 +343,6 @@ def add_comment_endpoint(app_id, issue_id)
"#{FABRIC_API_3_PATH}#{FABRIC_PROJECTS_ENDPOINT}/#{app_id}/issues/#{issue_id}/notes"
end

# Returns an API path to some issue session
#
# @param app_id [String]
# @param issue_id [String]
# @param session_id [String]
# @return [String]
def issue_session_endpoint(app_id, issue_id, session_id)
"#{FABRIC_API_3_PATH}#{FABRIC_PROJECTS_ENDPOINT}/#{app_id}/issues/#{issue_id}/sessions/#{session_id}"
end

# Returns an API path to some growth analytic endpoint
#
# @param session [Fabricio::Authorization::Session]
Expand All @@ -365,31 +353,6 @@ def growth_analytics_endpoint(session, app_id, name)
"#{FABRIC_API_PATH}#{org_app_endpoint(session, app_id)}/growth_analytics/#{name}.json"
end

# Returns an API path to organization endpoint
#
# @param session [Fabricio::Authorization::Session]
# @param app_id [String]
# @return [String]
def org_app_endpoint(session, app_id)
"#{org_endpoint(session)}/#{app_endpoint(app_id)}"
end

# Returns an API path to app endpoint
#
# @param app_id [String]
# @return [String]
def app_endpoint(app_id)
"#{FABRIC_APPS_ENDPOINT}/#{app_id}"
end

# Returns an API path to app endpoint
#
# @param session [Fabricio::Authorization::Session]
# @return [String]
def org_endpoint(session)
"#{FABRIC_ORGANIZATIONS_ENDPOINT}/#{session.organization_id}"
end

# Returns an API path to app endpoint
#
# @param start_time [String]
Expand Down
59 changes: 2 additions & 57 deletions lib/fabricio/networking/build_request_model_factory.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
require 'fabricio/networking/request_model_factory'
require 'fabricio/networking/request_model'

module Fabricio
module Networking
# This factory creates request models for fetching data for Build model object
class BuildRequestModelFactory

# Server constants
FABRIC_API_URL = 'https://fabric.io'
FABRIC_API_PATH = '/api/v2'
FABRIC_APPS_ENDPOINT = '/apps'
FABRIC_ORGANIZATIONS_ENDPOINT = '/organizations'
class BuildRequestModelFactory < RequestModelFactory

# Returns a request model for obtaining the list of all builds for a specific app
#
Expand Down Expand Up @@ -48,56 +43,6 @@ def get_build_request_model(session, app_id, version, build_number)
model
end

# Returns a request model for obtaining an array of top versions for a given app
#
# @param session [Fabricio::Authorization::Session]
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @return [Fabricio::Networking::RequestModel]
def top_versions_request_model(session, app_id, start_time, end_time)
path = "#{FABRIC_API_PATH}#{org_app_endpoint(session, app_id)}/growth_analytics/top_builds"
params = {
'app_id' => app_id,
'start' => start_time,
'end' => end_time
}
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.params = params
end
model
end

private

# Returns an API path to app endpoint
#
# @param app_id [String]
# @return [String]
def app_endpoint(app_id)
"#{FABRIC_APPS_ENDPOINT}/#{app_id}"
end

# Returns an API path to app endpoint
#
# @param session [Fabricio::Authorization::Session]
# @return [String]
def org_endpoint(session)
"#{FABRIC_ORGANIZATIONS_ENDPOINT}/#{session.organization_id}"
end

# Returns an API path to organization endpoint
#
# @param session [Fabricio::Authorization::Session]
# @param app_id [String]
# @return [String]
def org_app_endpoint(session, app_id)
"#{org_endpoint(session)}#{app_endpoint(app_id)}"
end

end
end
end
8 changes: 2 additions & 6 deletions lib/fabricio/networking/organization_request_model_factory.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
require 'fabricio/networking/request_model_factory'
require 'fabricio/networking/request_model'

module Fabricio
module Networking
# This factory creates request models for fetching data for Organization model object
class OrganizationRequestModelFactory

# Server constants
FABRIC_API_URL = 'https://fabric.io'
FABRIC_API_PATH = '/api/v2'
FABRIC_ORGANIZATIONS_ENDPOINT = '/organizations'
class OrganizationRequestModelFactory < RequestModelFactory

# Returns a request model for obtaining the organization data
#
Expand Down
Loading

0 comments on commit fb6c6e0

Please sign in to comment.