connector_kit 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb10df7a59883472f2597ad2d3fa5b67c5e236afaf31cd967334e56afe545990
4
+ data.tar.gz: 5f5a13651901a653afa50b59d26ecff458cda485d70dc3ef54eb721c3b0f2e37
5
+ SHA512:
6
+ metadata.gz: d2bb1ab2ddfb07d84257d132de77d90026757ff651fff907bd18a255db7666dda70c01ad2b298d428fd9ff4ed94f52d37342709a4bf95c88bf625b31a95ebbba
7
+ data.tar.gz: 481972d2871a8141fd3a800c51f091b2185e3140fb127cb1336a95f8c339265d26e4627d21b5600c73d43b3a99a6bfd8f4738d9f21a12f0c0bd62389c62888f5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in connector_kit.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Simon Jarbrant
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,39 @@
1
+ # ConnectorKit
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/connector_kit`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'connector_kit'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install connector_kit
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/connector_kit.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "connector_kit"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "connector_kit/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "connector_kit"
6
+ spec.version = ConnectorKit::VERSION
7
+ spec.authors = ["Simon Jarbrant"]
8
+ spec.email = ["simonjarbrant@gmail.com"]
9
+
10
+ spec.summary = "A gem for communicating with the App Store Connect API."
11
+ spec.description = "A gem for communicating with the App Store Connect API."
12
+ spec.homepage = "https://github.com/simba909/connector_kit"
13
+ spec.license = "MIT"
14
+
15
+ all_files = `git ls-files`.split("\n")
16
+ test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+
18
+ spec.files = all_files - test_files
19
+ spec.test_files = test_files
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.17"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+
27
+ spec.add_dependency "httparty", "~> 0.16.3"
28
+ spec.add_dependency "jwt", "~> 2.1", ">= 2.1.0"
29
+ end
@@ -0,0 +1,56 @@
1
+ require 'httparty'
2
+
3
+ require 'connector_kit/token_generator'
4
+ require 'connector_kit/exceptions'
5
+ require 'connector_kit/version'
6
+ require 'connector_kit/mappers/app_list_mapper'
7
+ require 'connector_kit/mappers/build_list_mapper'
8
+ require 'connector_kit/mappers/build_details_mapper'
9
+
10
+ module ConnectorKit
11
+ # Client class used for communicating with the App Store Connect API
12
+ class Client
13
+ include HTTParty
14
+ base_uri 'https://api.appstoreconnect.apple.com/v1'
15
+
16
+ def initialize(issuer_id, key_id, private_key_file_path)
17
+ token_generator = TokenGenerator.new(
18
+ issuer_id,
19
+ key_id,
20
+ private_key_file_path
21
+ )
22
+
23
+ self.class.headers(
24
+ 'Authorization' => "Bearer #{token_generator.generate_token}"
25
+ )
26
+ end
27
+
28
+ def apps
29
+ get '/apps', AppListMapper.new
30
+ end
31
+
32
+ def app_builds(app)
33
+ get "/apps/#{app.id}/builds", BuildListMapper.new
34
+ end
35
+
36
+ def build_beta_details(build)
37
+ get "/buildBetaDetails/#{build.id}", BuildDetailsMapper.new
38
+ end
39
+
40
+ private
41
+
42
+ def get(url, mapper)
43
+ response = self.class.get(url)
44
+
45
+ raise make_api_error(response) unless response.code == 200
46
+
47
+ mapper.map(response.parsed_response['data'])
48
+ end
49
+
50
+ def make_api_error(response)
51
+ # For the time being, the first error received is enough
52
+ error = response.parsed_response['errors'].first
53
+ APIError.new(error['title'], error['detail'], error['status'])
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ module ConnectorKit
2
+ class Error < StandardError; end
3
+
4
+ # Simple model class for representing errors in the App Store Connect API
5
+ class APIError < Error
6
+ attr_reader :detail, :status
7
+
8
+ def initialize(message, detail, status)
9
+ super(message)
10
+
11
+ @detail = detail
12
+ @status = status
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'connector_kit/models/app'
2
+
3
+ module ConnectorKit
4
+ # Mapper between a HTTParty response and a list of Apps
5
+ class AppListMapper
6
+ def map(data)
7
+ data.map { |app| App.new(app) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'connector_kit/models/build_details'
2
+
3
+ module ConnectorKit
4
+ # Mapper between a HTTParty response and a BuildDetails object
5
+ class BuildDetailsMapper
6
+ def map(data)
7
+ BuildDetails.new(data)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'connector_kit/models/build'
2
+
3
+ module ConnectorKit
4
+ # Mapper between a HTTParty response and a list of Builds
5
+ class BuildListMapper
6
+ def map(data)
7
+ data.map { |build| Build.new(build) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module ConnectorKit
2
+ # Simple model class for representing Apps in the App Store Connect API
3
+ class App
4
+ attr_reader :id, :bundle_id, :name, :sku
5
+
6
+ def initialize(options)
7
+ @id = options['id']
8
+
9
+ attrs = options['attributes']
10
+ @bundle_id = attrs['bundleId']
11
+ @name = attrs['name']
12
+ @sku = attrs['sku']
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module ConnectorKit
2
+ # Simple model class for representing Builds in the App Store Connect API
3
+ class Build
4
+ attr_reader :id,
5
+ :expired,
6
+ :processing_state,
7
+ :version,
8
+ :uploaded_date,
9
+ :expiration_date
10
+
11
+ def initialize(options)
12
+ @id = options['id']
13
+
14
+ attrs = options['attributes']
15
+ @expired = attrs['expired']
16
+ @processing_state = attrs['processingState']
17
+ @version = attrs['version']
18
+ @uploaded_date = Time.parse(attrs['uploadedDate'])
19
+ @expiration_date = Time.parse(attrs['expirationDate'])
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module ConnectorKit
2
+ # Simple model class for representing Build details in the App Store Connect API
3
+ class BuildDetails
4
+ attr_reader :id, :external_build_state, :internal_build_state
5
+
6
+ def initialize(options)
7
+ @id = options['id']
8
+
9
+ attrs = options['attributes']
10
+ @external_build_state = attrs['externalBuildState']
11
+ @internal_build_state = attrs['internalBuildState']
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ require 'openssl'
2
+ require 'jwt'
3
+
4
+ module ConnectorKit
5
+ # Helper class for generating JWT tokens
6
+ class TokenGenerator
7
+ def initialize(issuer_id, key_id, private_key_file_path)
8
+ @private_key_file_path = private_key_file_path
9
+ @custom_headers = {
10
+ kid: key_id,
11
+ typ: 'JWT'
12
+ }
13
+ @payload = {
14
+ iss: issuer_id,
15
+ aud: 'appstoreconnect-v1'
16
+ }
17
+ end
18
+
19
+ def generate_token
20
+ private_key = File.read(@private_key_file_path)
21
+ ecdsa_key = OpenSSL::PKey.read(private_key)
22
+
23
+ expiration = Time.now.to_i + 20 * 60
24
+ @payload[:exp] = expiration
25
+
26
+ puts "Generated token expires: #{Time.at(expiration)}"
27
+
28
+ JWT.encode(@payload, ecdsa_key, 'ES256', @custom_headers)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module ConnectorKit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe ConnectorKit do
2
+ it "has a version number" do
3
+ expect(ConnectorKit::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "connector_kit"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: connector_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Jarbrant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-14 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: jwt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.1.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.1'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.1.0
89
+ description: A gem for communicating with the App Store Connect API.
90
+ email:
91
+ - simonjarbrant@gmail.com
92
+ executables:
93
+ - console
94
+ - setup
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".travis.yml"
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - bin/console
106
+ - bin/setup
107
+ - connector_kit.gemspec
108
+ - lib/connector_kit.rb
109
+ - lib/connector_kit/exceptions.rb
110
+ - lib/connector_kit/mappers/app_list_mapper.rb
111
+ - lib/connector_kit/mappers/build_details_mapper.rb
112
+ - lib/connector_kit/mappers/build_list_mapper.rb
113
+ - lib/connector_kit/models/app.rb
114
+ - lib/connector_kit/models/build.rb
115
+ - lib/connector_kit/models/build_details.rb
116
+ - lib/connector_kit/token_generator.rb
117
+ - lib/connector_kit/version.rb
118
+ - spec/connector_kit_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/simba909/connector_kit
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.6
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A gem for communicating with the App Store Connect API.
144
+ test_files:
145
+ - spec/connector_kit_spec.rb
146
+ - spec/spec_helper.rb