itc_analytics 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/itc_analytics.gemspec +31 -0
- data/lib/itc_analytics.rb +43 -0
- data/lib/itc_analytics/domain/entities/analytics_query.rb +15 -0
- data/lib/itc_analytics/domain/entities/application.rb +41 -0
- data/lib/itc_analytics/domain/entities/metrics_query.rb +34 -0
- data/lib/itc_analytics/domain/entities/query.rb +12 -0
- data/lib/itc_analytics/domain/entities/session.rb +20 -0
- data/lib/itc_analytics/domain/entities/sources_query.rb +29 -0
- data/lib/itc_analytics/domain/value_objects/analytics_options.rb +36 -0
- data/lib/itc_analytics/domain/value_objects/group_options.rb +20 -0
- data/lib/itc_analytics/domain/value_objects/metrics_options.rb +52 -0
- data/lib/itc_analytics/domain/value_objects/sources_options.rb +15 -0
- data/lib/itc_analytics/interfaces/controllers/http.rb +62 -0
- data/lib/itc_analytics/interfaces/gateways/exceptions.rb +14 -0
- data/lib/itc_analytics/interfaces/gateways/itunesconnect.rb +76 -0
- data/lib/itc_analytics/interfaces/repositories/session/inmemory.rb +19 -0
- data/lib/itc_analytics/use_cases/create_new_session.rb +33 -0
- data/lib/itc_analytics/use_cases/exceptions.rb +10 -0
- data/lib/itc_analytics/use_cases/get_app_installs.rb +75 -0
- data/lib/itc_analytics/use_cases/get_available_applications.rb +51 -0
- data/lib/itc_analytics/use_cases/login.rb +41 -0
- data/lib/itc_analytics/version.rb +3 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fe3d84382764396ca8770176f396f0161bc29bcd71827b4e0e615aaee9e4f139
|
4
|
+
data.tar.gz: 9d1d469a023903d3d67e2a547fbb0c193b1b912a61cb01283a3c28a8000c3a6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db4ae9122fa6f16546afca78c1ef099049212a89d1ea0669bf7bfe9c53d63856c7f1cfcf55effa58ee9968a98b5b031286da4dc450311e84910b8b5703f784af
|
7
|
+
data.tar.gz: cb394e906794ec438f08932ab3e23f08af2c65182fb75f4c1068ea7dc34a77774814818e51cd339cc3dc529c7593837e375842f7c48202c81658500aad20f009
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at snelson21@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Steele Nelson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ITCAnalytics
|
2
|
+
|
3
|
+
A gem to access analytics from iTunesConnect.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'itc_analytics'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install itc_analytics
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Login:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
ITCAnalytics.login('username', 'password')
|
27
|
+
```
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elyticscode/itc_analytics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ios/analytics"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'itc_analytics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "itc_analytics"
|
8
|
+
spec.version = ITCAnalytics::VERSION
|
9
|
+
spec.authors = ["Steele Nelson"]
|
10
|
+
spec.email = ["steele@elytics.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Get analytics from iTunesConnect}
|
13
|
+
spec.description = <<-EOF
|
14
|
+
ITCAnalytics uses the undocumented iTunesConnect API's to retreive
|
15
|
+
analytics for iOS and tvOS apps.
|
16
|
+
EOF
|
17
|
+
spec.homepage = "https://www.elytics.com"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "simplecov", "~> 0.14"
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "itc_analytics/version"
|
2
|
+
require "itc_analytics/interfaces/gateways/itunesconnect"
|
3
|
+
require "itc_analytics/interfaces/repositories/session/inmemory"
|
4
|
+
require "itc_analytics/use_cases/create_new_session"
|
5
|
+
require "itc_analytics/use_cases/login"
|
6
|
+
|
7
|
+
module ITCAnalytics
|
8
|
+
#the main class
|
9
|
+
class << self
|
10
|
+
|
11
|
+
attr_accessor :session_repository
|
12
|
+
attr_accessor :http_controller
|
13
|
+
attr_accessor :itunesconnect_gateway
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
|
19
|
+
def session_repository
|
20
|
+
@session_repository ||= Interfaces::Repositories::Session::InMemory.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_controller
|
24
|
+
@http_controller ||= Interfaces::Controllers::Http.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def itunesconnect_gateway
|
28
|
+
@itunesconnect_gateway ||= Interfaces::Gateways::ItunesConnect.new(http_controller: http_controller,
|
29
|
+
apple_widget_key: "22d448248055bab0dc197c6271d738c3")
|
30
|
+
end
|
31
|
+
|
32
|
+
def login(user, pass)
|
33
|
+
success = UseCases::Login.new(
|
34
|
+
username: user,
|
35
|
+
password: pass,
|
36
|
+
session_repository: session_repository,
|
37
|
+
itunesconnect_gateway: itunesconnect_gateway)
|
38
|
+
.execute
|
39
|
+
return success
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "itc_analytics/domain/entities/query"
|
2
|
+
module ITCAnalytics
|
3
|
+
module Domain
|
4
|
+
module Entities
|
5
|
+
class AnalyticsQuery < Query
|
6
|
+
attr_accessor :application
|
7
|
+
def initialize(session:, applications:, analytics_options:)
|
8
|
+
super(session: session)
|
9
|
+
@applications = applications
|
10
|
+
@analytics_options = analytics_options
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module Entities
|
4
|
+
class Application
|
5
|
+
attr_accessor :id,
|
6
|
+
:itunes_app_id,
|
7
|
+
:itunes_app_name,
|
8
|
+
:is_bundle,
|
9
|
+
:icon_url,
|
10
|
+
:asset_token,
|
11
|
+
:platforms,
|
12
|
+
:is_enabled,
|
13
|
+
:app_opt_in_rate
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(itunes_app_id:,
|
17
|
+
itunes_app_name:,
|
18
|
+
is_bundle:,
|
19
|
+
icon_url:,
|
20
|
+
asset_token:,
|
21
|
+
platforms:,
|
22
|
+
is_enabled:,
|
23
|
+
app_opt_in_rate:
|
24
|
+
)
|
25
|
+
@itunes_app_id = itunes_app_id
|
26
|
+
@itunes_app_name = itunes_app_name
|
27
|
+
@is_bundle = is_bundle
|
28
|
+
@icon_url = icon_url
|
29
|
+
@asset_token = asset_token
|
30
|
+
@platforms = platforms
|
31
|
+
@is_enabled = is_enabled
|
32
|
+
@app_opt_in_rate = app_opt_in_rate
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid?
|
36
|
+
String(itunes_app_id).length > 0 && String(itunes_app_name).length > 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "itc_analytics/domain/entities/analytics_query"
|
2
|
+
module ITCAnalytics
|
3
|
+
module Domain
|
4
|
+
module Entities
|
5
|
+
class MetricsQuery < AnalyticsQuery
|
6
|
+
|
7
|
+
attr_reader :metrics_options
|
8
|
+
|
9
|
+
def initialize(session:, applications:, analytics_options:, metrics_options:)
|
10
|
+
super(session: session, applications: applications, analytics_options: analytics_options)
|
11
|
+
@metrics_options = metrics_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def assemble_body
|
15
|
+
measures = [@analytics_options.primary_measure]
|
16
|
+
measures << @metrics_options.secondary_measure unless @metrics_options.secondary_measure == nil
|
17
|
+
|
18
|
+
adamIds = @applications.map { |application| application.itunes_app_id }
|
19
|
+
|
20
|
+
startTime = @analytics_options.start_date.strftime("%Y-%m-%dT%H:%M:000Z")
|
21
|
+
endTime = @analytics_options.end_date.strftime("%Y-%m-%dT%H:%M:000Z")
|
22
|
+
return {
|
23
|
+
:startTime => startTime,
|
24
|
+
:endTime => endTime,
|
25
|
+
:adamId => adamIds,
|
26
|
+
:measures => measures,
|
27
|
+
:group => @metrics_options.group,
|
28
|
+
:frequency => @metrics_options.frequency
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module Entities
|
4
|
+
class Session
|
5
|
+
attr_accessor :id
|
6
|
+
attr_reader :account_cookie
|
7
|
+
attr_reader :itctx_cookie
|
8
|
+
|
9
|
+
def initialize(account_cookie: '', itctx_cookie: '')
|
10
|
+
@account_cookie = account_cookie
|
11
|
+
@itctx_cookie = itctx_cookie
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
String(account_cookie).length > 0 && String(itctx_cookie).length > 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module Entities
|
4
|
+
class SourcesQuery < AnalyticsQuery
|
5
|
+
|
6
|
+
attr_reader :sources_options
|
7
|
+
|
8
|
+
def self.dimensions
|
9
|
+
d = Hash.new
|
10
|
+
d[:appVersion] = "appVersion"
|
11
|
+
d[:campaigns] = "campaignId"
|
12
|
+
d[:device] = "platform"
|
13
|
+
d[:platformVersion] = "platformVersion"
|
14
|
+
d[:region] = "region"
|
15
|
+
d[:territory] = "storefront"
|
16
|
+
d[:websites] = "domainReferrer"
|
17
|
+
d[:apps] = "appReferer"
|
18
|
+
d[:sourceType] = "source"
|
19
|
+
return d
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(session:, applications:, analytics_options:, sources_options:)
|
23
|
+
super(session: session, applications: applications, analytics_options: analytics_options)
|
24
|
+
@sources_options = sources_options
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module ValueObjects
|
4
|
+
class AnalyticsOptions
|
5
|
+
|
6
|
+
attr_reader :primary_measure
|
7
|
+
attr_reader :start_date
|
8
|
+
attr_reader :end_date
|
9
|
+
|
10
|
+
def initialize(primary_measure:, start_date:, end_date:)
|
11
|
+
@primary_measure = primary_measure
|
12
|
+
@start_date = start_date
|
13
|
+
@end_date = end_date
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.measures
|
17
|
+
measures = Hash.new
|
18
|
+
measures[:installs] = "installs"
|
19
|
+
measures[:sessions] = "sessions"
|
20
|
+
measures[:pageViews] = "pageViewCount"
|
21
|
+
measures[:activeDevices] = "activeDevices"
|
22
|
+
measures[:rollingActiveDevices] = "rollingActiveDevices"
|
23
|
+
measures[:crashes] = "crashes"
|
24
|
+
measures[:payingUsers] = "payingUsers"
|
25
|
+
measures[:units] = "units"
|
26
|
+
measures[:sales] = "sales"
|
27
|
+
measures[:iap] = "iap"
|
28
|
+
measures[:impressionsTotal] = "impressionsTotal"
|
29
|
+
measures[:impressionsUnique] = "impressionsUnique"
|
30
|
+
measures[:pageViewUnique] = "pageViewUnique"
|
31
|
+
return measures
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module ValueObjects
|
4
|
+
class GroupOptions
|
5
|
+
|
6
|
+
attr_reader :metric
|
7
|
+
attr_reader :dimension
|
8
|
+
attr_reader :rank
|
9
|
+
attr_reader :limit
|
10
|
+
|
11
|
+
def initialize(metric:, dimension:, rank:, limit:)
|
12
|
+
@metric = metric
|
13
|
+
@dimension = dimension
|
14
|
+
@rank = rank
|
15
|
+
@limit = limit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ITCAnalytics
|
2
|
+
module Domain
|
3
|
+
module ValueObjects
|
4
|
+
class MetricsOptions
|
5
|
+
|
6
|
+
attr_reader :secondary_measure
|
7
|
+
attr_reader :frequency
|
8
|
+
attr_reader :group
|
9
|
+
attr_reader :dimension_filters
|
10
|
+
|
11
|
+
def initialize(secondary_measure:, frequency:, group:, dimension_filters:)
|
12
|
+
@secondary_measure = secondary_measure
|
13
|
+
@frequency = frequency
|
14
|
+
@group = group
|
15
|
+
@dimension_filters = dimension_filters
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.dimension_filter_keys
|
19
|
+
dfk = Hash.new
|
20
|
+
dfk[:appPurchaseWeek] = "apppurchaseWeek"
|
21
|
+
dfk[:appPurchaseDay] = "apppurchaseDay"
|
22
|
+
dfk[:appPurchaseMonth] = "apppurchaseMonth"
|
23
|
+
dfk[:appVersion] = "appVersion"
|
24
|
+
dfk[:campaigns] = "campaignId"
|
25
|
+
dfk[:device] = "platform"
|
26
|
+
dfk[:platformVersion] = "platformVersion"
|
27
|
+
dfk[:territory] = "storefront"
|
28
|
+
dfk[:region] = "region"
|
29
|
+
dfk[:websites] = "domainReferrer"
|
30
|
+
return dfk
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.platforms
|
34
|
+
pl = Hash.new
|
35
|
+
pl[:iPhone] = "iPhone"
|
36
|
+
pl[:iPad] = "iPad"
|
37
|
+
pl[:iPod] = "iPod"
|
38
|
+
pl[:appleTV] = "AppleTV"
|
39
|
+
return pl
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.frequencies
|
43
|
+
f = Hash.new
|
44
|
+
f[:days] = "DAY"
|
45
|
+
f[:weeks] = "WEEK"
|
46
|
+
f[:months] = "MONTH"
|
47
|
+
return f
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module ITCAnalytics
|
6
|
+
module Interfaces
|
7
|
+
module Controllers
|
8
|
+
class Http
|
9
|
+
def get(url:, headers:)
|
10
|
+
uri = URI(url)
|
11
|
+
|
12
|
+
request = Net::HTTP::Get.new(uri)
|
13
|
+
headers.each do |key, value|
|
14
|
+
request[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
return fire_request(uri: uri, request: request)
|
18
|
+
|
19
|
+
end
|
20
|
+
def post(url:, headers:, post_body:)
|
21
|
+
uri = URI(url)
|
22
|
+
|
23
|
+
request = Net::HTTP::Post.new(uri)
|
24
|
+
request.body = post_body
|
25
|
+
headers.each do |key, value|
|
26
|
+
request[key] = value
|
27
|
+
end
|
28
|
+
|
29
|
+
return fire_request(uri: uri, request: request)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def fire_request(uri:, request:)
|
34
|
+
|
35
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
+
http.use_ssl = true
|
37
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
38
|
+
|
39
|
+
#remove
|
40
|
+
http.set_debug_output($stdout)
|
41
|
+
|
42
|
+
res = http.request(request)
|
43
|
+
|
44
|
+
return Http.hash_response(res)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.hash_response(res)
|
48
|
+
begin
|
49
|
+
body = res.body
|
50
|
+
rescue Exception => e
|
51
|
+
body = ""
|
52
|
+
end
|
53
|
+
return Hash["error" => !res.is_a?(Net::HTTPSuccess),
|
54
|
+
"body" => body,
|
55
|
+
"code" => res.code,
|
56
|
+
"message" => res.message,
|
57
|
+
"headers" => res.to_hash]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "itc_analytics/interfaces/gateways/exceptions"
|
2
|
+
require 'json'
|
3
|
+
module ITCAnalytics
|
4
|
+
module Interfaces
|
5
|
+
module Gateways
|
6
|
+
class ItunesConnect
|
7
|
+
|
8
|
+
def initialize(http_controller:, apple_widget_key:)
|
9
|
+
@http_controller = http_controller
|
10
|
+
@apple_widget_key = apple_widget_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_account_info_cookie(username:, password:)
|
14
|
+
result = @http_controller.post(url: "https://idmsa.apple.com/appleauth/auth/signin",
|
15
|
+
headers: Hash["Content-Type" => "application/json", "X-Apple-Widget-Key" => @apple_widget_key],
|
16
|
+
post_body: "{\"accountName\": \"" << username << "\",\"password\": \"" << password << "\",\"rememberMe\": false}")
|
17
|
+
|
18
|
+
if result['error'] == false && result['headers']['set-cookie'].find { |e| /myacinfo=.+?;/ =~ e }
|
19
|
+
return result['headers']['set-cookie'].find { |e| /(myacinfo=.+?;)/ =~ e }.scan(/(myacinfo=.+?;)/).last.first
|
20
|
+
end
|
21
|
+
raise Exceptions::ItunesRequestFailure, "failed to get myacinfo apple may have changed login routine"
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_itctx_cookie(account_info_cookie:)
|
25
|
+
result = @http_controller.get(url: "https://olympus.itunes.apple.com/v1/session",
|
26
|
+
headers: Hash["Cookie" => account_info_cookie])
|
27
|
+
|
28
|
+
if result['error'] == false && result['headers']['set-cookie'].find { |e| /itctx=.+?;/ =~ e }
|
29
|
+
return result['headers']['set-cookie'].find { |e| /(itctx=.+?;)/ =~ e }.scan(/(itctx=.+?Only)/).last.first
|
30
|
+
end
|
31
|
+
raise Exceptions::ItunesRequestFailure, "failed to get itctx cookie apple may have changed login routine"
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_headers(get_cookies)
|
35
|
+
Hash["Content-Type" => "application/json;charset=UTF-8",
|
36
|
+
"Accept" => "application/json, text/plain, */*",
|
37
|
+
"Origin" => "https://analytics.itunes.apple.com",
|
38
|
+
"X-Requested-By" => "analytics.itunes.apple.com",
|
39
|
+
"Referer" => "https://analytics.itunes.apple.com/",
|
40
|
+
"Cookie" => get_cookies]
|
41
|
+
end
|
42
|
+
|
43
|
+
def result_body(result)
|
44
|
+
if result["error"]
|
45
|
+
if result["code"] == 401
|
46
|
+
raise Exceptions::ItunesUnauthorized, "Unauthorized call to iTunesConnect #{result['message']}"
|
47
|
+
end
|
48
|
+
raise Exceptions::ItunesRequestFailure, "iTunesConnect not responding to #{result['message']}"
|
49
|
+
end
|
50
|
+
return result["body"]
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_api_url(url:, session_cookies:)
|
54
|
+
result = @http_controller.get(url: url, headers: get_headers(session_cookies))
|
55
|
+
return result_body(result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_applications_json(session_cookies:)
|
59
|
+
url = 'https://analytics.itunes.apple.com/analytics/api/v1/app-info/app'
|
60
|
+
return get_api_url(url: url, session_cookies: session_cookies)
|
61
|
+
end
|
62
|
+
|
63
|
+
def execute_metrics_query(query:)
|
64
|
+
url = "https://analytics.itunes.apple.com/analytics/api/v1/data/time-series"
|
65
|
+
post_body = query.assemble_body.to_json
|
66
|
+
|
67
|
+
result = @http_controller.post(url: url,
|
68
|
+
headers: get_headers([query.session.account_cookie, query.session.itctx_cookie]),
|
69
|
+
post_body: post_body)
|
70
|
+
|
71
|
+
return result_body(result)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require "itc_analytics/domain/entities/session"
|
3
|
+
|
4
|
+
module ITCAnalytics
|
5
|
+
module UseCases
|
6
|
+
class CreateNewSession
|
7
|
+
attr_accessor :username,
|
8
|
+
:password,
|
9
|
+
:itunesconnect_gateway
|
10
|
+
def initialize(username:, password:, itunesconnect_gateway:)
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@itunesconnect_gateway = itunesconnect_gateway
|
14
|
+
end
|
15
|
+
def execute
|
16
|
+
account_cookie = @itunesconnect_gateway.create_account_info_cookie(
|
17
|
+
username: @username,
|
18
|
+
password: @password
|
19
|
+
)
|
20
|
+
if account_cookie == nil
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
itctx_cookie = @itunesconnect_gateway.get_itctx_cookie(account_info_cookie: account_cookie)
|
25
|
+
if itctx_cookie == nil
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
return Domain::Entities::Session.new(account_cookie: account_cookie, itctx_cookie: itctx_cookie)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "itc_analytics/domain/entities/metrics_query"
|
2
|
+
require "itc_analytics/domain/value_objects/analytics_options"
|
3
|
+
require "itc_analytics/domain/value_objects/metrics_options"
|
4
|
+
require "itc_analytics/use_cases/exceptions"
|
5
|
+
module ITCAnalytics
|
6
|
+
module UseCases
|
7
|
+
class GetAppInstalls
|
8
|
+
attr_accessor :applications, :session_repository, :start_date, :end_date, :itunes_gateway
|
9
|
+
|
10
|
+
def initialize(applications:, session_repository:, start_date:, end_date:, itunes_gateway:)
|
11
|
+
@applications,
|
12
|
+
@session_repository,
|
13
|
+
@start_date,
|
14
|
+
@end_date,
|
15
|
+
@itunes_gateway = [
|
16
|
+
applications,
|
17
|
+
session_repository,
|
18
|
+
start_date,
|
19
|
+
end_date,
|
20
|
+
itunes_gateway
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
session = @session_repository.get
|
26
|
+
if (session == nil || session.valid? == false)
|
27
|
+
raise Exceptions::InvalidSession, "Session was nil!"
|
28
|
+
end
|
29
|
+
|
30
|
+
analytics_options = Domain::ValueObjects::AnalyticsOptions.new(
|
31
|
+
primary_measure: Domain::ValueObjects::AnalyticsOptions.measures[:installs],
|
32
|
+
start_date: @start_date,
|
33
|
+
end_date: @end_date)
|
34
|
+
|
35
|
+
metrics_options = Domain::ValueObjects::MetricsOptions.new(secondary_measure: nil,
|
36
|
+
frequency: Domain::ValueObjects::MetricsOptions.frequencies[:days],
|
37
|
+
group: {
|
38
|
+
:metric => Domain::ValueObjects::AnalyticsOptions.measures[:installs],
|
39
|
+
:dimension => Domain::ValueObjects::MetricsOptions.dimension_filter_keys[:device],
|
40
|
+
:rank => "",
|
41
|
+
:limit => 10
|
42
|
+
},
|
43
|
+
dimension_filters: [])
|
44
|
+
|
45
|
+
query = Domain::Entities::MetricsQuery.new(session: session,
|
46
|
+
applications: @applications,
|
47
|
+
analytics_options: analytics_options,
|
48
|
+
metrics_options: metrics_options)
|
49
|
+
|
50
|
+
results = @itunes_gateway.execute_metrics_query(query: query)
|
51
|
+
|
52
|
+
results_obj = JSON.parse(results)
|
53
|
+
if !results_obj.key?("results")
|
54
|
+
raise Exceptions::NoResults, "There were no results in the json #{results}"
|
55
|
+
end
|
56
|
+
|
57
|
+
return results_obj["results"].map { |result| {
|
58
|
+
:adamId => result["adamId"],
|
59
|
+
:meetsThreshold => result["meetsThreshold"],
|
60
|
+
:platform => result["group"]["key"],
|
61
|
+
:data => result["data"]
|
62
|
+
} }
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
rescue Interfaces::Gateways::Exceptions::ItunesUnauthorized => e
|
68
|
+
puts e.message
|
69
|
+
@session_repository.save(nil)
|
70
|
+
raise Exceptions::InvalidSession
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "itc_analytics/domain/entities/application"
|
2
|
+
require "itc_analytics/use_cases/exceptions"
|
3
|
+
require "itc_analytics/interfaces/gateways/exceptions"
|
4
|
+
module ITCAnalytics
|
5
|
+
module UseCases
|
6
|
+
class GetAvailableApplications
|
7
|
+
|
8
|
+
attr_accessor :session_repository, :itunesconnect_gateway
|
9
|
+
|
10
|
+
def initialize(session_repository:, itunesconnect_gateway:)
|
11
|
+
@session_repository = session_repository
|
12
|
+
@itunesconnect_gateway = itunesconnect_gateway
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
|
17
|
+
session = @session_repository.get
|
18
|
+
if session == nil || !session.valid?
|
19
|
+
raise Exceptions::InvalidSession
|
20
|
+
end
|
21
|
+
|
22
|
+
results = @itunesconnect_gateway.get_applications_json(
|
23
|
+
session_cookies: [session.account_cookie, session.itctx_cookie]
|
24
|
+
)
|
25
|
+
|
26
|
+
obj = JSON.parse(results)
|
27
|
+
if !obj.key?("results")
|
28
|
+
raise Exceptions::NoResults
|
29
|
+
end
|
30
|
+
|
31
|
+
applications = obj["results"].map { |e|
|
32
|
+
Domain::Entities::Application.new(
|
33
|
+
itunes_app_id: e["adamId"],
|
34
|
+
itunes_app_name: e["name"],
|
35
|
+
is_bundle: e["is_bundle"],
|
36
|
+
icon_url: e["icon_url"],
|
37
|
+
asset_token: e["asset_token"],
|
38
|
+
platforms: e["platforms"],
|
39
|
+
is_enabled: e["is_enabled"],
|
40
|
+
app_opt_in_rate: e["app_opt_in_rate"]
|
41
|
+
)
|
42
|
+
}
|
43
|
+
return applications
|
44
|
+
|
45
|
+
rescue Interfaces::Gateways::Exceptions::ItunesUnauthorized => e
|
46
|
+
@session_repository.save(nil)
|
47
|
+
raise Exceptions::InvalidSession, "The session was invalid"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require "itc_analytics/use_cases/create_new_session"
|
3
|
+
|
4
|
+
module ITCAnalytics
|
5
|
+
module UseCases
|
6
|
+
class Login
|
7
|
+
attr_accessor :username,
|
8
|
+
:password,
|
9
|
+
:session_repository,
|
10
|
+
:itunesconnect_gateway,
|
11
|
+
:create_new_session_use_case
|
12
|
+
|
13
|
+
def initialize(username:, password:, session_repository:, itunesconnect_gateway:)
|
14
|
+
@username = username
|
15
|
+
@password = password
|
16
|
+
@session_repository = session_repository
|
17
|
+
@itunesconnect_gateway = itunesconnect_gateway
|
18
|
+
@create_new_session_use_case = UseCases::CreateNewSession.new(
|
19
|
+
username: @username,
|
20
|
+
password: @password,
|
21
|
+
itunesconnect_gateway: @itunesconnect_gateway)
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
existing = @session_repository.get
|
26
|
+
unless existing.nil? || ! existing.valid?
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
existing = @create_new_session_use_case.execute
|
31
|
+
|
32
|
+
if existing.nil? || ! existing.valid?
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
|
36
|
+
@session_repository.save(existing)
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itc_analytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steele Nelson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.14'
|
69
|
+
description: " ITCAnalytics uses the undocumented iTunesConnect API's to retreive
|
70
|
+
\n analytics for iOS and tvOS apps.\n"
|
71
|
+
email:
|
72
|
+
- steele@elytics.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- itc_analytics.gemspec
|
88
|
+
- lib/itc_analytics.rb
|
89
|
+
- lib/itc_analytics/domain/entities/analytics_query.rb
|
90
|
+
- lib/itc_analytics/domain/entities/application.rb
|
91
|
+
- lib/itc_analytics/domain/entities/metrics_query.rb
|
92
|
+
- lib/itc_analytics/domain/entities/query.rb
|
93
|
+
- lib/itc_analytics/domain/entities/session.rb
|
94
|
+
- lib/itc_analytics/domain/entities/sources_query.rb
|
95
|
+
- lib/itc_analytics/domain/value_objects/analytics_options.rb
|
96
|
+
- lib/itc_analytics/domain/value_objects/group_options.rb
|
97
|
+
- lib/itc_analytics/domain/value_objects/metrics_options.rb
|
98
|
+
- lib/itc_analytics/domain/value_objects/sources_options.rb
|
99
|
+
- lib/itc_analytics/interfaces/controllers/http.rb
|
100
|
+
- lib/itc_analytics/interfaces/gateways/exceptions.rb
|
101
|
+
- lib/itc_analytics/interfaces/gateways/itunesconnect.rb
|
102
|
+
- lib/itc_analytics/interfaces/repositories/session/inmemory.rb
|
103
|
+
- lib/itc_analytics/use_cases/create_new_session.rb
|
104
|
+
- lib/itc_analytics/use_cases/exceptions.rb
|
105
|
+
- lib/itc_analytics/use_cases/get_app_installs.rb
|
106
|
+
- lib/itc_analytics/use_cases/get_available_applications.rb
|
107
|
+
- lib/itc_analytics/use_cases/login.rb
|
108
|
+
- lib/itc_analytics/version.rb
|
109
|
+
homepage: https://www.elytics.com
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.7.3
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Get analytics from iTunesConnect
|
133
|
+
test_files: []
|