Class: ITCAnalytics::UseCases::GetAppInstalls
- Inherits:
-
Object
- Object
- ITCAnalytics::UseCases::GetAppInstalls
- Defined in:
- lib/itc_analytics/use_cases/get_app_installs.rb
Instance Attribute Summary collapse
-
#applications ⇒ Object
Returns the value of attribute applications.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#itunes_gateway ⇒ Object
Returns the value of attribute itunes_gateway.
-
#session_repository ⇒ Object
Returns the value of attribute session_repository.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(applications:, session_repository:, start_date:, end_date:, itunes_gateway:) ⇒ GetAppInstalls
constructor
A new instance of GetAppInstalls.
Constructor Details
#initialize(applications:, session_repository:, start_date:, end_date:, itunes_gateway:) ⇒ GetAppInstalls
Returns a new instance of GetAppInstalls.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 10 def initialize(applications:, session_repository:, start_date:, end_date:, itunes_gateway:) @applications, @session_repository, @start_date, @end_date, @itunes_gateway = [ applications, session_repository, start_date, end_date, itunes_gateway ] end |
Instance Attribute Details
#applications ⇒ Object
Returns the value of attribute applications.
8 9 10 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 8 def applications @applications end |
#end_date ⇒ Object
Returns the value of attribute end_date.
8 9 10 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 8 def end_date @end_date end |
#itunes_gateway ⇒ Object
Returns the value of attribute itunes_gateway.
8 9 10 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 8 def itunes_gateway @itunes_gateway end |
#session_repository ⇒ Object
Returns the value of attribute session_repository.
8 9 10 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 8 def session_repository @session_repository end |
#start_date ⇒ Object
Returns the value of attribute start_date.
8 9 10 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 8 def start_date @start_date end |
Instance Method Details
#execute ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/itc_analytics/use_cases/get_app_installs.rb', line 24 def execute session = @session_repository.get if (session == nil || session.valid? == false) raise Exceptions::InvalidSession, "Session was nil!" end = Domain::ValueObjects::AnalyticsOptions.new( primary_measure: Domain::ValueObjects::AnalyticsOptions.measures[:installs], start_date: @start_date, end_date: @end_date) = Domain::ValueObjects::MetricsOptions.new(secondary_measure: nil, frequency: Domain::ValueObjects::MetricsOptions.frequencies[:days], group: { :metric => Domain::ValueObjects::AnalyticsOptions.measures[:installs], :dimension => Domain::ValueObjects::MetricsOptions.dimension_filter_keys[:device], :rank => "", :limit => 10 }, dimension_filters: []) query = Domain::Entities::MetricsQuery.new(session: session, applications: @applications, analytics_options: , metrics_options: ) results = @itunes_gateway.execute_metrics_query(query: query) results_obj = JSON.parse(results) if !results_obj.key?("results") raise Exceptions::NoResults, "There were no results in the json #{results}" end return results_obj["results"].map { |result| { :adamId => result["adamId"], :meetsThreshold => result["meetsThreshold"], :platform => result["group"]["key"], :data => result["data"] } } rescue Interfaces::Gateways::Exceptions::ItunesUnauthorized => e puts e. @session_repository.save(nil) raise Exceptions::InvalidSession end |