Skip to content

Commit

Permalink
Merge pull request #52 from strongself/feature/fix-session
Browse files Browse the repository at this point in the history
Default value for options
  • Loading branch information
CognitiveDisson authored Feb 26, 2018
2 parents c9e645a + eba7239 commit caf445b
Show file tree
Hide file tree
Showing 21 changed files with 403 additions and 269 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
install:
rm fabricio-*.*.*.gem 2> /dev/null || true
gem build fabricio.gemspec
gem install fabricio-*.*.*.gem

lint:
rubocop -l
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,32 @@ Or install it yourself as:
fabricio app get --app_id 'app_id'
# Obtain active now count
fabricio app active_now --org_id 'org_id' --app_id 'app_id'
fabricio app active_now --organization_id 'org_id' --app_id 'app_id'
# Obtain single issue
fabricio app single_issue --app_id 'app_id' 'issue_id'
fabricio app single_issue --app_id 'app_id' --issue_id 'issue_id'
# Obtain single issue session
fabricio app issue_session --app_id 'app_id' 'issue_id' 'session_id'
fabricio app issue_session --app_id 'app_id' --issue_id 'issue_id' --session_id 'session_id'
# Obtain latest issue session
fabricio app latest_session --app_id 'app_id'
```
##### Build
```
# Obtain all builds
fabricio build all --org_id 'org_id' --app_id 'app_id'
fabricio build all --organization_id 'org_id' --app_id 'app_id'
# Obtain single build
fabricio build get --org_id 'org_id' --app_id 'app_id' 'version' 'build_number'
fabricio build get --organization_id 'org_id' --app_id 'app_id' --version 'version' --build_number 'build_number'
```
##### Version
```
# Obtain all versions
fabricio version all --app_id 'app_id'
# Obtain top versions
fabricio version top --org_id 'org_id' --app_id 'app_id' --start 'timestamp' --end 'timestamp'
fabricio version top --organization_id 'org_id' --app_id 'app_id' --start_time 'timestamp' --end_time 'timestamp'
```
##### Organization
```
Expand Down Expand Up @@ -113,7 +113,10 @@ If your account have only one organization/app then it will be used by default a
```
fabricio build all
```

#### Parsing
You can use [`jq`](https://stedolan.github.io/jq/) for parsing json
> fabricio version all --app_id 'app_id' | jq 'sort_by(.major)[-1].synthesized_version'
"14.0 (131)"
### Code
1. Create a `Fabricio::Client` object and configure it on initialization.

Expand All @@ -130,18 +133,18 @@ fabricio build all

```ruby
client.app.all # Returns all applications on your account
client.app.get('app_id') # Returns information about specific application
client.app.crashfree('app_id', '1478736000', '1481328000' 'all') # Returns application crashfree for a given period of time
client.app.get(app_id: 'app_id') # Returns information about specific application
client.app.crashfree(app_id: 'app_id', start_time: '1478736000', end_time: '1481328000', build: 'all') # Returns application crashfree for a given period of time
client.organization.all # Returns information about your organizations
```

3. If you want to check the exact server output for a model, you can call `json` method on it:

`client.app.get('app_id').json`
`client.app.get(app_id: 'app_id').json`

You can call a method similar to any key in this hash:

`client.app.get('app_id').importance_level`
`client.app.get(app_id: 'app_id').importance_level`

## Commands

Expand All @@ -157,73 +160,73 @@ Obtains information about your organizations.

Obtains the list of all apps.

#### `client.app.get('app_id')`
#### `client.app.get(app_id: 'app_id')`

Obtains a specific app.

#### `client.app.active_now('organization_id', 'app_id')`
#### `client.app.active_now(organization_id: 'organization_id', app_id: 'app_id')`

Obtains the count of active users at the current moment.

#### `client.app.daily_new('organization_id', 'app_id', 'start_timestamp', 'end_timestamp')`
#### `client.app.daily_new(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp')`

Obtains the count of daily new users.

#### `client.app.daily_active('app_id', 'start_timestamp', 'end_timestamp', 'build')`
#### `client.app.daily_active(app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build')`

Obtains the count of daily active users.

#### `client.app.total_sessions('organization_id', 'app_id', 'start_timestamp', 'end_timestamp', 'build')`
#### `client.app.total_sessions(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build')`

Obtains the count of sessions.

#### `client.app.crashes('app_id', 'start_timestamp', 'end_timestamp', 'builds')`
#### `client.app.crashes(app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', builds: 'builds')`

Obtains the count of crashes for a number of builds.

#### `client.app.crashfree('app_id', 'start_timestamp', 'end_timestamp', 'build')`
#### `client.app.crashfree(app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build')`

Obtains application crashfree.

> Fabric.io website uses the same calculations. However, mobile app behaves differently and shows another value.
#### `client.app.top_issues('app_id', start_timestamp, end_timestamp, 'build', count)`
#### `client.app.top_issues(app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build', count: count)`

Obtain top issues.

#### `client.app.single_issue('app_id', 'issue_external_id', start_timestamp, end_timestamp)`
#### `client.app.single_issue(app_id: 'app_id', issue_id: 'issue_id', start_time: 'start_timestamp', end_time: 'end_timestamp')`

Obtain single issue.

#### `client.app.issue_session('app_id', 'issue_external_id', 'session_id')`
#### `client.app.issue_session(app_id: 'app_id', issue_id: 'issue_id', session_id: 'session_id')`

Obtain issue session.

#### `client.app.add_comment('app_id', 'issue_external_id', 'message')`
#### `client.app.add_comment(app_id: 'app_id', issue_id: 'issue_id', message: 'message')`

Add comment.

#### `client.app.oomfree('app_id', 'start_timestamp', 'end_timestamp', 'builds')`
#### `client.app.oomfree(app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', builds:'builds')`

Obtains application out-of-memory free for a number of builds.

### Build

#### `client.build.all('organization_id', 'app_id')`
#### `client.build.all(organization_id: 'organization_id', app_id: 'app_id')`

Obtains the list of all application builds.

#### `client.build.get('organization_id', 'app_id', 'version', 'build_number')`
#### `client.build.get(organization_id: 'organization_id', app_id: 'app_id', version: 'version', build_number: 'build_number')`

Obtains a specific build for a specific application.

### Version

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

Obtains an array of all versions for a given application.

#### `client.version.top('organization_id', 'app_id', 'start_timestamp', 'end_timestamp')`
#### `client.version.top(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp')`

Obtains an array of top versions for a given application.

Expand Down
4 changes: 2 additions & 2 deletions lib/fabricio/authorization/memory_param_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MemoryParamStorage < AbstractParamStorage
#
# @return [Fabricio::Authorization::ParamStorage]
def initialize
@params = nil
@params = {}
end

# Returns all stored variable
Expand All @@ -28,7 +28,7 @@ def store(hash)

# Resets current state and deletes all saved params
def reset
@params = nil
@params = {}
end

def organization_id
Expand Down
33 changes: 19 additions & 14 deletions lib/fabricio/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def all
option :app_id, :type => :string
option :short, :type => :boolean
def get
app = client.app.get(options[:app_id])
hash = prepared_options(options)
app = client.app.get(hash)
if options[:short]
say(app.pretty_print)
else
Expand All @@ -31,18 +32,20 @@ def get
end

desc "active_now", "Obtain active now count"
option :org_id, :type => :string
option :organization_id, :type => :string
option :app_id, :type => :string
def active_now
say(client.app.active_now(options[:org_id], options[:app_id]))
hash = prepared_options(options)
say(client.app.active_now(hash))
end

desc "issue", "Obtain issue by external_id"
desc "issue", "Obtain issue by issue_id"
option :app_id, :type => :string
option :external_id => :required, :type => :string
option :issue_id, :type => :string
option :short, :type => :boolean
def issue(external_id)
issue = client.app.single_issue(external_id, options[:app_id])
def issue
hash = prepared_options(options)
issue = client.app.single_issue(hash)
if options[:short]
say(issue.pretty_print)
else
Expand All @@ -52,11 +55,12 @@ def issue(external_id)

desc "session", "Obtain session"
option :app_id, :type => :string
option :external_id => :required, :type => :string
option :session_id => :required, :type => :string
option :issue_id, :type => :string
option :session_id, :type => :string
option :short, :type => :boolean
def session(external_id, session_id)
session = client.app.issue_session(external_id, session_id, options[:app_id])
def session
hash = prepared_options(options)
session = client.app.issue_session(hash)
if options[:short]
say(session.pretty_print)
else
Expand All @@ -66,10 +70,11 @@ def session(external_id, session_id)

desc "latest_session", "Obtain latest issue session"
option :app_id, :type => :string
option :external_id => :required, :type => :string
option :issue_id, :type => :string
option :short, :type => :boolean
def latest_session(external_id)
session = client.app.issue_session(options[:app_id], external_id)
def latest_session
hash = prepared_options(options)
session = client.app.issue_session(hash)
if options[:short]
say(session.pretty_print)
else
Expand Down
12 changes: 7 additions & 5 deletions lib/fabricio/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Build < Thor
option :app_id, :type => :string
option :short, :type => :boolean
def all
builds = client.build.all(options[:org_id], options[:app_id])
hash = prepared_options(options)
builds = client.build.all(hash)
if options[:short]
say(builds.map {|build| build.pretty_print}.join("\n\n"))
else
Expand All @@ -23,11 +24,12 @@ def all
desc "get", "Obtain single build"
option :org_id, :type => :string
option :app_id, :type => :string
option :version => :required, :type => :string
option :build_number => :required, :type => :string
option :version, :type => :string
option :build_number, :type => :string
option :short, :type => :boolean
def get(version, build_number)
build = client.build.get(options[:org_id], options[:app_id], version, build_number)
def get
hash = prepared_options(options)
build = client.build.get(hash)
if options[:short]
say(build.pretty_print)
else
Expand Down
5 changes: 5 additions & 0 deletions lib/fabricio/cli/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ def ask_credential
say("")
Fabricio::Model::Credential.new(email, password)
end

def prepared_options(options)
options = {} if options == nil
options.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
end
19 changes: 8 additions & 11 deletions lib/fabricio/cli/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@ class Version < Thor
desc "all", "Obtain all versions"
option :app_id, :type => :string
def all
say("#{client.version.all(options[:app_id]).to_json}")
hash = prepared_options(options)
say("#{client.version.all(hash).to_json}")
end

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

Expand Down
6 changes: 2 additions & 4 deletions lib/fabricio/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Issue < AbstractModel
:createdAt,
:type,
:state,
:latestSessionId,
:occurrenceCount,
:impactedDevices

Expand All @@ -29,9 +28,8 @@ def initialize(attributes)
@createdAt = attributes['createdAt']
@type = attributes['type']
@state = attributes['state']
@latestSessionId = attributes['latestSessionId']
@occurrenceCount = attributes['occurrenceCount']
@impactedDevices = attributes['impactedDevices']
@occurrenceCount = attributes['_occurrenceCount2I980d"']
@impactedDevices = attributes['_impactedDevices2oATOx']
@json = attributes
end
end
Expand Down
Loading

0 comments on commit caf445b

Please sign in to comment.