connector_kit 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb10df7a59883472f2597ad2d3fa5b67c5e236afaf31cd967334e56afe545990
4
- data.tar.gz: 5f5a13651901a653afa50b59d26ecff458cda485d70dc3ef54eb721c3b0f2e37
3
+ metadata.gz: '08bee81ea565559ab0b8e5156e8149c00d42c75a16006ac8286b8d9e9caf91aa'
4
+ data.tar.gz: 4f5ca61f4feac8042d710debefed0db9ed857c389d5ee1b22bb81d67966fdd5c
5
5
  SHA512:
6
- metadata.gz: d2bb1ab2ddfb07d84257d132de77d90026757ff651fff907bd18a255db7666dda70c01ad2b298d428fd9ff4ed94f52d37342709a4bf95c88bf625b31a95ebbba
7
- data.tar.gz: 481972d2871a8141fd3a800c51f091b2185e3140fb127cb1336a95f8c339265d26e4627d21b5600c73d43b3a99a6bfd8f4738d9f21a12f0c0bd62389c62888f5
6
+ metadata.gz: f0ed6058f0cea7ad567120bb4a5c75463134cc8e3b19790a931f06ac7fc9209d59d02686ad72a5e4dcc0f4a70370a04b687bb07e3ac7c59ae8c4815afe1c6434
7
+ data.tar.gz: fb0c640fc46f104d502f856efc9ab4d736b06f6610dba75eb6f6ef63e6e5b2889382e1030a21f63450c4df4cdf6cb7f0081c8cf69066009fb2f04ed87dadb2f6
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # ConnectorKit
1
+ # ConnectorKit 🔌
2
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.
3
+ [![Gem Version](https://badge.fury.io/rb/connector_kit.svg)](https://badge.fury.io/rb/connector_kit)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A simple Ruby gem for communicating with the [App Store Connect API](https://developer.apple.com/app-store-connect/api).
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,15 +14,52 @@ gem 'connector_kit'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ ```bash
18
+ $ bundle
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install connector_kit
23
+ ```bash
24
+ $ gem install connector_kit
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ Before you can use this gem you need to set up a new key in the App Store Connect "Users and Access" section. More detailed info here: [App Store Connect API documentation](https://developer.apple.com/documentation/appstoreconnectapi)
30
+
31
+ First, require the gem and set up a client. The `Client` class has three constructor arguments:
32
+
33
+ - `issuer_id`: The Issuer ID of your organisation (you can find this in App Store Connect)
34
+ - `key_id`: The Key ID of the App Store Connect API key you want to use
35
+ - `private_key_file_path`: The path to the `*.p8` file that you downloaded as part of creating an App Store Connect API key
36
+
37
+ ```ruby
38
+ require 'connector_kit'
39
+
40
+ client = ConnectorKit::Client.new(
41
+ '8e2f3845-63ec-4865-8be7-f7cbb3c099db',
42
+ 'E28E8EE0B4CE',
43
+ 'AuthKey_E28E8EE0B4CE.p8'
44
+ )
45
+ ```
46
+
47
+ After initialising the client, it will generate a JWT token as described in the documentation for the App Store Connect API. It's valid for 20 minutes. Now you can use it to fetch information from the API:
48
+
49
+ ```ruby
50
+ # Fetches all apps in the organisation
51
+ apps = client.apps
52
+ ```
53
+
54
+ ```ruby
55
+ # Fetches all builds for an app
56
+ builds = client.app_builds(app)
57
+ ```
58
+
59
+ ```ruby
60
+ # Fetches build details for a build
61
+ build_details = client.build_beta_details(build)
62
+ ```
26
63
 
27
64
  ## Development
28
65
 
@@ -32,7 +69,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
69
 
33
70
  ## Contributing
34
71
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/connector_kit.
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/simba909/connector_kit.
36
73
 
37
74
  ## License
38
75
 
@@ -0,0 +1,30 @@
1
+ require 'httparty'
2
+
3
+ require 'connector_kit/exceptions'
4
+
5
+ module ConnectorKit
6
+ # Simple HTTP client wrapper for HTTParty
7
+ class HTTPClient
8
+ include HTTParty
9
+
10
+ def initialize(target_uri)
11
+ self.class.base_uri(target_uri)
12
+ end
13
+
14
+ def get(url, response_mapper)
15
+ response = self.class.get(url)
16
+
17
+ raise make_api_error(response) unless response.code == 200
18
+
19
+ response_mapper.map(response.parsed_response['data'])
20
+ end
21
+
22
+ private
23
+
24
+ def make_api_error(response)
25
+ # For the time being, the first error received is enough
26
+ error = response.parsed_response['errors'].first
27
+ APIError.new(error['title'], error['detail'], error['status'])
28
+ end
29
+ end
30
+ end
@@ -15,8 +15,8 @@ module ConnectorKit
15
15
  @expired = attrs['expired']
16
16
  @processing_state = attrs['processingState']
17
17
  @version = attrs['version']
18
- @uploaded_date = Time.parse(attrs['uploadedDate'])
19
- @expiration_date = Time.parse(attrs['expirationDate'])
18
+ @uploaded_date = Time.parse(attrs['uploadedDate']).getlocal
19
+ @expiration_date = Time.parse(attrs['expirationDate']).getlocal
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module ConnectorKit
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/connector_kit.rb CHANGED
@@ -1,18 +1,13 @@
1
- require 'httparty'
2
-
1
+ require 'connector_kit/httpclient.rb'
3
2
  require 'connector_kit/token_generator'
4
- require 'connector_kit/exceptions'
5
3
  require 'connector_kit/version'
6
4
  require 'connector_kit/mappers/app_list_mapper'
7
5
  require 'connector_kit/mappers/build_list_mapper'
8
6
  require 'connector_kit/mappers/build_details_mapper'
9
7
 
10
8
  module ConnectorKit
11
- # Client class used for communicating with the App Store Connect API
9
+ # Class used for communicating with the App Store Connect API
12
10
  class Client
13
- include HTTParty
14
- base_uri 'https://api.appstoreconnect.apple.com/v1'
15
-
16
11
  def initialize(issuer_id, key_id, private_key_file_path)
17
12
  token_generator = TokenGenerator.new(
18
13
  issuer_id,
@@ -20,37 +15,22 @@ module ConnectorKit
20
15
  private_key_file_path
21
16
  )
22
17
 
23
- self.class.headers(
18
+ @httpclient = HTTPClient.new('https://api.appstoreconnect.apple.com/v1')
19
+ @httpclient.class.headers(
24
20
  'Authorization' => "Bearer #{token_generator.generate_token}"
25
21
  )
26
22
  end
27
23
 
28
24
  def apps
29
- get '/apps', AppListMapper.new
25
+ @httpclient.get '/apps', AppListMapper.new
30
26
  end
31
27
 
32
28
  def app_builds(app)
33
- get "/apps/#{app.id}/builds", BuildListMapper.new
29
+ @httpclient.get "/apps/#{app.id}/builds", BuildListMapper.new
34
30
  end
35
31
 
36
32
  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'])
33
+ @httpclient.get "/buildBetaDetails/#{build.id}", BuildDetailsMapper.new
54
34
  end
55
35
  end
56
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connector_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Jarbrant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,6 +107,7 @@ files:
107
107
  - connector_kit.gemspec
108
108
  - lib/connector_kit.rb
109
109
  - lib/connector_kit/exceptions.rb
110
+ - lib/connector_kit/httpclient.rb
110
111
  - lib/connector_kit/mappers/app_list_mapper.rb
111
112
  - lib/connector_kit/mappers/build_details_mapper.rb
112
113
  - lib/connector_kit/mappers/build_list_mapper.rb