Skip to content

Commit

Permalink
Merge pull request #33 from christianhager/weekly_active
Browse files Browse the repository at this point in the history
add support for weekly active users
  • Loading branch information
etolstoy authored Oct 7, 2017
2 parents 1206352 + eebb7c4 commit 0b8c592
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
fabricio (1.2.0)
fabricio (1.3.0)
faraday

GEM
Expand All @@ -15,7 +15,7 @@ GEM
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
faraday (0.12.1)
faraday (0.13.1)
multipart-post (>= 1.2, < 3)
hashdiff (0.3.4)
json (2.1.0)
Expand Down Expand Up @@ -58,4 +58,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.12.5
1.14.5
21 changes: 21 additions & 0 deletions lib/fabricio/networking/app_request_model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ def daily_active_request_model(session, app_id, start_time, end_time, build)
model
end

# Returns a request model for obtaining the count of weekly active users
#
# @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
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @return [Fabricio::Networking::RequestModel]
def weekly_active_request_model(session, app_id, start_time, end_time, build)
path = growth_analytics_endpoint(session, app_id, 'weekly_active')
params = time_range_params(start_time, end_time)
params['build'] = build
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

# Returns a request model for obtaining the count of monhtly active users
#
# @param session [Fabricio::Authorization::Session]
Expand Down
15 changes: 15 additions & 0 deletions lib/fabricio/services/app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ def daily_active(id, start_time, end_time, build)
end
end

# Obtains the count of weekly active users
#
# @param id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @return [Array<Fabricio::Model::Point>]
def weekly_active(id, start_time, end_time, build)
request_model = @request_model_factory.weekly_active_request_model(@session, id, start_time, end_time, build)
response = @network_client.perform_request(request_model)
JSON.parse(response.body)['series'].map do |array|
Fabricio::Model::Point.new(array)
end
end

# Obtains the count of monhtly active users
#
# @param id [String] Application identifier
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/fabricio/service/app_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
expect(result).not_to be_nil
end

it 'should fetch weekly_active' do
response_file = File.new(Dir.getwd + '/spec/lib/fabricio/service/app_service_daily_active_stub_response.txt')
stub_request(:get, /weekly_active/).to_return(:body => response_file, :status => 200)

result = @service.weekly_active('1', '1', '1', '1')
expect(result).not_to be_nil
end

it 'should fetch monthly_active' do
response_file = File.new(Dir.getwd + '/spec/lib/fabricio/service/app_service_daily_active_stub_response.txt')
stub_request(:get, /monthly_active/).to_return(:body => response_file, :status => 200)
Expand Down

0 comments on commit 0b8c592

Please sign in to comment.