fabricio 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +12 -0
- data/.idea/runConfigurations/IRB_console__fabricio.xml +23 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +149 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/api_reference.md +611 -0
- data/docs/swagger-api.json +553 -0
- data/fabricio.gemspec +29 -0
- data/lib/fabricio.rb +2 -0
- data/lib/fabricio/authorization/abstract_session_storage.rb +26 -0
- data/lib/fabricio/authorization/authorization_client.rb +122 -0
- data/lib/fabricio/authorization/memory_session_storage.rb +35 -0
- data/lib/fabricio/authorization/session.rb +21 -0
- data/lib/fabricio/client/client.rb +92 -0
- data/lib/fabricio/models/abstract_model.rb +17 -0
- data/lib/fabricio/models/app.rb +24 -0
- data/lib/fabricio/models/build.rb +23 -0
- data/lib/fabricio/models/organization.rb +22 -0
- data/lib/fabricio/models/point.rb +17 -0
- data/lib/fabricio/networking/app_request_model_factory.rb +229 -0
- data/lib/fabricio/networking/build_request_model_factory.rb +103 -0
- data/lib/fabricio/networking/network_client.rb +101 -0
- data/lib/fabricio/networking/organization_request_model_factory.rb +27 -0
- data/lib/fabricio/networking/request_model.rb +39 -0
- data/lib/fabricio/services/app_service.rb +146 -0
- data/lib/fabricio/services/build_service.rb +59 -0
- data/lib/fabricio/services/organization_service.rb +33 -0
- data/lib/fabricio/version.rb +3 -0
- metadata +163 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fabricio
|
2
|
+
module Networking
|
3
|
+
# A data structure that provides all values necessary for making an API request
|
4
|
+
class RequestModel
|
5
|
+
|
6
|
+
attr_accessor :type, :base_url, :api_path, :headers, :body, :params
|
7
|
+
|
8
|
+
# Initializes a new RequestModel object. You can use a block to fill all the options:
|
9
|
+
# model = Fabricio::Networking::RequestModel.new do |config|
|
10
|
+
# config.type = :GET
|
11
|
+
# config.base_url = FABRIC_API_URL
|
12
|
+
# config.api_path = '/apps'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# @param options [Hash] Hash containing customizable options
|
16
|
+
# @option options [String] :type Request type - :GET or :POST
|
17
|
+
# @option options [String] :base_url The base_url. E.g. 'https://fabric.io'
|
18
|
+
# @option options [String] :api_path An API endpoint path. E.g. '/apps'
|
19
|
+
# @option options [Hash] :headers All request headers
|
20
|
+
# @option options [Hash] :body Request body
|
21
|
+
# @option options [Hash] :params Request url parameters
|
22
|
+
# @return [Fabricio::Networking::RequestModel]
|
23
|
+
def initialize(options =
|
24
|
+
{
|
25
|
+
:type => :GET,
|
26
|
+
:base_url => '',
|
27
|
+
:api_path => '',
|
28
|
+
:headers => {},
|
29
|
+
:body => nil,
|
30
|
+
:params => {}
|
31
|
+
})
|
32
|
+
options.each do |key, value|
|
33
|
+
instance_variable_set("@#{key}", value)
|
34
|
+
end
|
35
|
+
yield(self) if block_given?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'fabricio/networking/app_request_model_factory'
|
2
|
+
require 'fabricio/networking/network_client'
|
3
|
+
require 'fabricio/models/app'
|
4
|
+
require 'fabricio/models/point'
|
5
|
+
|
6
|
+
module Fabricio
|
7
|
+
module Service
|
8
|
+
# Service responsible for fetching different App information
|
9
|
+
class AppService
|
10
|
+
|
11
|
+
# Initializes a new AppService object.
|
12
|
+
#
|
13
|
+
# @param session [Fabricio::Authorization::Session]
|
14
|
+
# @param network_client [Fabricio::Networking::NetworkClient]
|
15
|
+
# @return [Fabricio::Service::AppService]
|
16
|
+
def initialize(session, network_client)
|
17
|
+
@session = session
|
18
|
+
|
19
|
+
@request_model_factory = Fabricio::Networking::AppRequestModelFactory.new
|
20
|
+
@network_client = network_client
|
21
|
+
end
|
22
|
+
|
23
|
+
# Obtains the list of all apps
|
24
|
+
#
|
25
|
+
# @return [Array<Fabricio::Model::App>]
|
26
|
+
def all
|
27
|
+
request_model = @request_model_factory.all_apps_request_model
|
28
|
+
response = @network_client.perform_request(request_model)
|
29
|
+
JSON.parse(response.body).map do |app_hash|
|
30
|
+
Fabricio::Model::App.new(app_hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Obtains a specific app
|
35
|
+
#
|
36
|
+
# @param id [String] Application identifier
|
37
|
+
# @return [Fabricio::Model::App]
|
38
|
+
def get(id)
|
39
|
+
request_model = @request_model_factory.get_app_request_model(id)
|
40
|
+
response = @network_client.perform_request(request_model)
|
41
|
+
Fabricio::Model::App.new(JSON.parse(response.body))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Obtains the count of active users at the current moment
|
45
|
+
#
|
46
|
+
# @param id [String] Application identifier
|
47
|
+
# @return [Integer]
|
48
|
+
def active_now(id)
|
49
|
+
request_model = @request_model_factory.active_now_request_model(@session, id)
|
50
|
+
response = @network_client.perform_request(request_model)
|
51
|
+
JSON.parse(response.body)['cardinality']
|
52
|
+
end
|
53
|
+
|
54
|
+
# Obtains the count of daily new users
|
55
|
+
#
|
56
|
+
# @param id [String] Application identifier
|
57
|
+
# @param start_time [String] Timestamp of the start date
|
58
|
+
# @param end_time [String] Timestamp of the end date
|
59
|
+
# @return [Array<Fabricio::Model::Point>]
|
60
|
+
def daily_new(id, start_time, end_time)
|
61
|
+
request_model = @request_model_factory.daily_new_request_model(@session, id, start_time, end_time)
|
62
|
+
response = @network_client.perform_request(request_model)
|
63
|
+
JSON.parse(response.body)['series'].map do |array|
|
64
|
+
Fabricio::Model::Point.new(array)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Obtains the count of daily active users
|
69
|
+
#
|
70
|
+
# @param id [String] Application identifier
|
71
|
+
# @param start_time [String] Timestamp of the start date
|
72
|
+
# @param end_time [String] Timestamp of the end date
|
73
|
+
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
|
74
|
+
# @return [Array<Fabricio::Model::Point>]
|
75
|
+
def daily_active(id, start_time, end_time, build)
|
76
|
+
request_model = @request_model_factory.daily_active_request_model(@session, id, start_time, end_time, build)
|
77
|
+
response = @network_client.perform_request(request_model)
|
78
|
+
JSON.parse(response.body)['series'].map do |array|
|
79
|
+
Fabricio::Model::Point.new(array)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Obtains the count of sessions
|
84
|
+
#
|
85
|
+
# @param id [String] Application identifier
|
86
|
+
# @param start_time [String] Timestamp of the start date
|
87
|
+
# @param end_time [String] Timestamp of the end date
|
88
|
+
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
|
89
|
+
# @return [Integer]
|
90
|
+
def total_sessions(id, start_time, end_time, build)
|
91
|
+
request_model = @request_model_factory.total_sessions_request_model(@session, id, start_time, end_time, build)
|
92
|
+
response = @network_client.perform_request(request_model)
|
93
|
+
JSON.parse(response.body)['sessions']
|
94
|
+
end
|
95
|
+
|
96
|
+
# Obtains the number of crashes
|
97
|
+
#
|
98
|
+
# @param id [String] Application identifier
|
99
|
+
# @param start_time [String] Timestamp of the start date
|
100
|
+
# @param end_time [String] Timestamp of the end date
|
101
|
+
# @param builds [Array<String>] The versions of the app. E.g. ['4.0.1 (38)', '4.0.2 (45)']
|
102
|
+
# @return [Integer]
|
103
|
+
def crashes(id, start_time, end_time, builds)
|
104
|
+
request_model = @request_model_factory.crash_count_request_model(id, start_time, end_time, builds)
|
105
|
+
response = @network_client.perform_request(request_model)
|
106
|
+
JSON.parse(response.body)['data']['project']['crashlytics']['scalars']['crashes']
|
107
|
+
end
|
108
|
+
|
109
|
+
# Obtains application crashfree. It's calculated using a simple formula:
|
110
|
+
# crashfree = 1 - total_crashes / total_sessions.
|
111
|
+
# AFAIK Fabric.io website uses the same calculations. However, mobile app behaves differently and shows another value.
|
112
|
+
#
|
113
|
+
# @param id [String] Application identifier
|
114
|
+
# @param start_time [String] Timestamp of the start date
|
115
|
+
# @param end_time [String] Timestamp of the end date
|
116
|
+
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
|
117
|
+
# @return [Float]
|
118
|
+
def crashfree(id, start_time, end_time, build)
|
119
|
+
sessions = total_sessions(id, start_time, end_time, build)
|
120
|
+
crashes = crashes(id, start_time, end_time, [build])
|
121
|
+
1 - crashes.to_f / sessions
|
122
|
+
end
|
123
|
+
|
124
|
+
# Obtains application OOM-free (Out of Memory).
|
125
|
+
#
|
126
|
+
# @param id [String] Application identifier
|
127
|
+
# @param start_time [String] Timestamp of the start date
|
128
|
+
# @param end_time [String] Timestamp of the end date
|
129
|
+
# @param builds [Array<String>] The versions of the app. E.g. ['4.0.1 (38)', '4.0.2 (45)']
|
130
|
+
# @return [Float]
|
131
|
+
def oomfree(id, start_time, end_time, builds)
|
132
|
+
start_date = Time.at(start_time.to_i).to_datetime
|
133
|
+
end_date = Time.at(end_time.to_i).to_datetime
|
134
|
+
days = (end_date - start_date).to_i + 1
|
135
|
+
|
136
|
+
request_model = @request_model_factory.oom_count_request_model(id, days, builds)
|
137
|
+
response = @network_client.perform_request(request_model)
|
138
|
+
|
139
|
+
result = JSON.parse(response.body)
|
140
|
+
sessions = result['data']['project']['crashlytics']['oomSessionCounts']['timeSeries'][0]['allTimeCount']
|
141
|
+
ooms = result['data']['project']['crashlytics']['oomCounts']['timeSeries'][0]['allTimeCount']
|
142
|
+
1 - ooms.to_f / sessions
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'fabricio/networking/build_request_model_factory'
|
2
|
+
require 'fabricio/networking/network_client'
|
3
|
+
require 'fabricio/models/build'
|
4
|
+
|
5
|
+
module Fabricio
|
6
|
+
module Service
|
7
|
+
# Service responsible for fetching different Build information
|
8
|
+
class BuildService
|
9
|
+
|
10
|
+
# Initializes a new BuildService object.
|
11
|
+
#
|
12
|
+
# @param session [Fabricio::Authorization::Session]
|
13
|
+
# @param network_client [Fabricio::Networking::NetworkClient]
|
14
|
+
# @return [Fabricio::Service::BuildService]
|
15
|
+
def initialize(session, network_client)
|
16
|
+
@session = session
|
17
|
+
|
18
|
+
@request_model_factory = Fabricio::Networking::BuildRequestModelFactory.new
|
19
|
+
@network_client = network_client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Obtains the list of all application builds
|
23
|
+
#
|
24
|
+
# @param app_id [String] Application identifier
|
25
|
+
# @return [Array<Fabricio::Model::Build>]
|
26
|
+
def all(app_id)
|
27
|
+
request_model = @request_model_factory.all_builds_request_model(@session, app_id)
|
28
|
+
response = @network_client.perform_request(request_model)
|
29
|
+
JSON.parse(response.body)['instances'].map do |hash|
|
30
|
+
Fabricio::Model::Build.new(hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Obtains a specific build for a specific application
|
35
|
+
#
|
36
|
+
# @param app_id [String] Application identifier
|
37
|
+
# @param version [String] Build version. E.g. '4.0.1'.
|
38
|
+
# @param build_number [String] Build number. E.g. '39'.
|
39
|
+
# @return [Fabricio::Model::Build]
|
40
|
+
def get(app_id, version, build_number)
|
41
|
+
request_model = @request_model_factory.get_build_request_model(@session, app_id, version, build_number)
|
42
|
+
response = @network_client.perform_request(request_model)
|
43
|
+
Fabricio::Model::Build.new(JSON.parse(response.body)['instances'].first)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Obtains an array of top versions for a given app
|
47
|
+
#
|
48
|
+
# @param app_id [String] Application identifier
|
49
|
+
# @param start_time [String] Timestamp of the start date
|
50
|
+
# @param end_time [String] Timestamp of the end date
|
51
|
+
# @return [Array<String>]
|
52
|
+
def top_versions(app_id, start_time, end_time)
|
53
|
+
request_model = @request_model_factory.top_versions_request_model(@session, app_id, start_time, end_time)
|
54
|
+
response = @network_client.perform_request(request_model)
|
55
|
+
JSON.parse(response.body)['builds']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'fabricio/networking/organization_request_model_factory'
|
2
|
+
require 'fabricio/networking/network_client'
|
3
|
+
require 'fabricio/models/organization'
|
4
|
+
|
5
|
+
module Fabricio
|
6
|
+
module Service
|
7
|
+
# Service responsible for fetching different Organization information
|
8
|
+
class OrganizationService
|
9
|
+
|
10
|
+
# Initializes a new OrganizationService object.
|
11
|
+
#
|
12
|
+
# @param session [Fabricio::Authorization::Session]
|
13
|
+
# @param network_client [Fabricio::Networking::NetworkClient]
|
14
|
+
# @return [Fabricio::Service::OrganizationService]
|
15
|
+
def initialize(session, network_client)
|
16
|
+
@session = session
|
17
|
+
|
18
|
+
@request_model_factory = Fabricio::Networking::OrganizationRequestModelFactory.new
|
19
|
+
@network_client = network_client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Obtains current organization information
|
23
|
+
#
|
24
|
+
# @return [Fabricio::Model::Organization]
|
25
|
+
def get
|
26
|
+
request_model = @request_model_factory.get_organization_request_model
|
27
|
+
response = @network_client.perform_request(request_model)
|
28
|
+
puts(response)
|
29
|
+
Fabricio::Model::Organization.new(JSON.parse(response.body)[0])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fabricio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Egor Tolstoy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.0
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- e.tolstoy@rambler-co.ru
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".codeclimate.yml"
|
105
|
+
- ".idea/runConfigurations/IRB_console__fabricio.xml"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- docs/api_reference.md
|
117
|
+
- docs/swagger-api.json
|
118
|
+
- fabricio.gemspec
|
119
|
+
- lib/fabricio.rb
|
120
|
+
- lib/fabricio/authorization/abstract_session_storage.rb
|
121
|
+
- lib/fabricio/authorization/authorization_client.rb
|
122
|
+
- lib/fabricio/authorization/memory_session_storage.rb
|
123
|
+
- lib/fabricio/authorization/session.rb
|
124
|
+
- lib/fabricio/client/client.rb
|
125
|
+
- lib/fabricio/models/abstract_model.rb
|
126
|
+
- lib/fabricio/models/app.rb
|
127
|
+
- lib/fabricio/models/build.rb
|
128
|
+
- lib/fabricio/models/organization.rb
|
129
|
+
- lib/fabricio/models/point.rb
|
130
|
+
- lib/fabricio/networking/app_request_model_factory.rb
|
131
|
+
- lib/fabricio/networking/build_request_model_factory.rb
|
132
|
+
- lib/fabricio/networking/network_client.rb
|
133
|
+
- lib/fabricio/networking/organization_request_model_factory.rb
|
134
|
+
- lib/fabricio/networking/request_model.rb
|
135
|
+
- lib/fabricio/services/app_service.rb
|
136
|
+
- lib/fabricio/services/build_service.rb
|
137
|
+
- lib/fabricio/services/organization_service.rb
|
138
|
+
- lib/fabricio/version.rb
|
139
|
+
homepage:
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.4.6
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: A simple gem that fetches mobile application statistics from Fabric.io API.
|
163
|
+
test_files: []
|