tiny_appstore_connect 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiny_appstore_connect/client.rb +2 -1
- data/lib/tiny_appstore_connect/clients/certificate.rb +5 -1
- data/lib/tiny_appstore_connect/clients/device.rb +19 -0
- data/lib/tiny_appstore_connect/models/certificate.rb +34 -12
- data/lib/tiny_appstore_connect/models/device.rb +19 -0
- data/lib/tiny_appstore_connect/response.rb +34 -40
- data/lib/tiny_appstore_connect/version.rb +1 -1
- data/lib/tiny_appstore_connect.rb +29 -14
- data/tiny_appstore_connect.gemspec +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 159be4a02efbe33a9b6a40521f7aaa6e0989c13ed511da96a89632488e6cbaca
|
4
|
+
data.tar.gz: 21b2aeb13a33ca663d79d5424b757672720b1bc72ffd9f3e8409df642f6f3449
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7dd5876ff04fa6bf047931092581a87dd7cd2081a6d690697566d3da68070002320cd83cadb2ef25006cb5be5f30be8a980ea630e7368831d8e0d9123bc1bf7
|
7
|
+
data.tar.gz: 655f5d2b5597030b48b0604921fdde524a98e11b414cd2ab9a1c3d0f69b369c7131fb651f0a6839773dd91f25ce7df1b6773ed650f3e6a14b3aca79435502660
|
@@ -59,8 +59,9 @@ module TinyAppstoreConnect
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def handle_response(response)
|
62
|
-
response = Response.new(response,
|
62
|
+
response = Response.new(response, self)
|
63
63
|
|
64
|
+
# It always never to be go into here, throws a 429 error.
|
64
65
|
if (remaining = response.rate[:remaining]) && remaining.to_i.zero?
|
65
66
|
raise RateLimitExceededError, "Request limit reached #{response.rate[:limit]}
|
66
67
|
in the previous 60 minutes with url: #{response.request_url}"
|
@@ -15,7 +15,11 @@ class TinyAppstoreConnect::Client
|
|
15
15
|
|
16
16
|
def distribution_certificates(**query)
|
17
17
|
query[:filter] = {
|
18
|
-
certificateType:
|
18
|
+
certificateType: [
|
19
|
+
TinyAppstoreConnect::Model::Certificate::CertificateType::DISTRIBUTION,
|
20
|
+
TinyAppstoreConnect::Model::Certificate::CertificateType::IOS_DISTRIBUTION,
|
21
|
+
TinyAppstoreConnect::Model::Certificate::CertificateType::MAC_APP_DISTRIBUTION
|
22
|
+
].join(',')
|
19
23
|
}
|
20
24
|
|
21
25
|
certificates(**query)
|
@@ -14,5 +14,24 @@ class TinyAppstoreConnect::Client
|
|
14
14
|
|
15
15
|
get('devices', **query)
|
16
16
|
end
|
17
|
+
|
18
|
+
def device(udid, **query)
|
19
|
+
get("devices/#{udid}", **query).to_model
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_device(udid, name, platform: 'IOS')
|
23
|
+
body = {
|
24
|
+
data: {
|
25
|
+
type: 'devices',
|
26
|
+
attributes: {
|
27
|
+
udid: udid,
|
28
|
+
name: name,
|
29
|
+
platform: platform
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
post('devices', body: body)
|
35
|
+
end
|
17
36
|
end
|
18
37
|
end
|
@@ -31,22 +31,44 @@ module TinyAppstoreConnect::Model
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def team_id
|
34
|
-
|
35
|
-
.to_a
|
36
|
-
.find {|n, _, _| n == 'OU'}[1]
|
37
|
-
.force_encoding('UTF-8')
|
34
|
+
subject['OU']
|
38
35
|
end
|
39
36
|
|
40
|
-
def
|
41
|
-
|
37
|
+
def name
|
38
|
+
subject['O']
|
39
|
+
end
|
40
|
+
|
41
|
+
def full_name
|
42
|
+
subject['CN']
|
43
|
+
end
|
44
|
+
# def type
|
45
|
+
# value = subject['CN']
|
46
|
+
# if value.include?('Distribution')
|
47
|
+
# return 'Distribution'
|
48
|
+
# else
|
49
|
+
# return ''
|
50
|
+
# end
|
51
|
+
# end
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
def subject
|
54
|
+
@subject ||= certificate.subject
|
55
|
+
.to_a
|
56
|
+
.each_with_object({}) do |(key, value, _), obj|
|
57
|
+
obj[key] = value.force_encoding('UTF-8')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def certificate
|
62
|
+
@certificate ||= -> () do
|
63
|
+
require 'openssl'
|
64
|
+
data = [
|
65
|
+
'-----BEGIN CERTIFICATE-----',
|
66
|
+
certificate_content,
|
67
|
+
'-----END CERTIFICATE-----'
|
68
|
+
].join("\n")
|
48
69
|
|
49
|
-
|
70
|
+
OpenSSL::X509::Certificate.new(data)
|
71
|
+
end.call
|
50
72
|
end
|
51
73
|
|
52
74
|
def self.type
|
@@ -15,6 +15,25 @@ module TinyAppstoreConnect::Model
|
|
15
15
|
attr_accessor :udid
|
16
16
|
attr_accessor :added_date
|
17
17
|
|
18
|
+
def device
|
19
|
+
return model unless model.nil?
|
20
|
+
|
21
|
+
case device_class
|
22
|
+
when DeviceClass::APPLE_WATCH
|
23
|
+
'Apple Watch'
|
24
|
+
when DeviceClass::IPAD
|
25
|
+
'iPad'
|
26
|
+
when DeviceClass::IPHONE
|
27
|
+
'iPhone'
|
28
|
+
when DeviceClass::IPOD
|
29
|
+
'iPod Touch'
|
30
|
+
when DeviceClass::APPLE_TV
|
31
|
+
'Apple TV'
|
32
|
+
when DeviceClass::MAC
|
33
|
+
'macOS'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
18
37
|
# include
|
19
38
|
# attr_accessor :app
|
20
39
|
# attr_accessor :app_store_version_submission
|
@@ -10,14 +10,14 @@ module TinyAppstoreConnect
|
|
10
10
|
# include Enumerable
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
-
attr_reader :response, :
|
13
|
+
attr_reader :response, :client
|
14
14
|
|
15
|
-
def initialize(response,
|
15
|
+
def initialize(response, client)
|
16
16
|
@response = response
|
17
|
-
@
|
17
|
+
@client = client
|
18
18
|
end
|
19
19
|
|
20
|
-
def_delegators :@response, :status, :headers
|
20
|
+
def_delegators :@response, :status, :headers, :body
|
21
21
|
|
22
22
|
def request_url
|
23
23
|
@response.env.url
|
@@ -37,57 +37,51 @@ module TinyAppstoreConnect
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
return if
|
40
|
+
def next_url
|
41
|
+
return if body.nil?
|
42
42
|
|
43
|
-
links =
|
44
|
-
links[
|
43
|
+
links = body['links'] || {}
|
44
|
+
links['next']
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def next_page(&block)
|
48
|
+
url = next_url
|
49
|
+
return if url.nil?
|
50
|
+
return client.get(url) unless block_given?
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
# count = 0 if count <= 0
|
54
|
-
|
55
|
-
# responses = [self]
|
56
|
-
# counter = 0
|
57
|
-
|
58
|
-
# resp = self
|
59
|
-
# loop do
|
60
|
-
# resp = resp.next_page
|
61
|
-
# break if resp.nil?
|
62
|
-
|
63
|
-
# responses << resp
|
64
|
-
# counter += 1
|
52
|
+
yield(url)
|
53
|
+
end
|
65
54
|
|
66
|
-
|
67
|
-
|
55
|
+
def next_pages(count: 1, &block)
|
56
|
+
count = 0 if !count.nil? && count < 0
|
57
|
+
responses = [self]
|
58
|
+
counter = 0
|
68
59
|
|
69
|
-
|
70
|
-
|
60
|
+
resp = self
|
61
|
+
loop do
|
62
|
+
resp = resp.next_page(&block)
|
63
|
+
break if resp.nil?
|
71
64
|
|
72
|
-
|
73
|
-
|
65
|
+
responses << resp
|
66
|
+
counter += 1
|
74
67
|
|
75
|
-
|
76
|
-
|
77
|
-
# end
|
68
|
+
break if !count.nil? && counter >= count
|
69
|
+
end
|
78
70
|
|
79
|
-
|
80
|
-
|
71
|
+
responses
|
72
|
+
end
|
81
73
|
|
82
|
-
|
83
|
-
|
74
|
+
def all_pages(flatten: false, &block)
|
75
|
+
responses = next_pages(count: nil, &block)
|
76
|
+
flatten ? responses.flat_map(&:to_models) : responses
|
77
|
+
end
|
84
78
|
|
85
79
|
def to_model
|
86
80
|
to_models.first
|
87
81
|
end
|
88
82
|
|
89
83
|
def to_models
|
90
|
-
return [] if
|
84
|
+
return [] if body.nil?
|
91
85
|
|
92
86
|
model_or_models = Parser.parse(response, rate)
|
93
87
|
[model_or_models].flatten
|
@@ -95,7 +89,7 @@ module TinyAppstoreConnect
|
|
95
89
|
|
96
90
|
def each(&block)
|
97
91
|
to_models.each do |model|
|
98
|
-
|
92
|
+
yield(model)
|
99
93
|
end
|
100
94
|
end
|
101
95
|
end
|
@@ -10,38 +10,53 @@ module TinyAppstoreConnect
|
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
12
|
class ConnectAPIError < Error
|
13
|
+
attr_reader :status_code, :errors
|
14
|
+
|
13
15
|
class << self
|
14
16
|
def parse(response)
|
15
|
-
handel_error(response
|
17
|
+
handel_error(response)
|
16
18
|
end
|
17
19
|
|
18
|
-
def from_errors(
|
19
|
-
|
20
|
+
def from_errors(response)
|
21
|
+
status_code = response.status
|
22
|
+
# 403 will returns content-type with value '*/*' FUCK!
|
23
|
+
body = response.body.is_a?(String) ? JSON.load(response.body) : response.body
|
24
|
+
errors = body['errors']
|
25
|
+
messages = ["Check errors(#{errors.size}) from response:"]
|
20
26
|
errors.each_with_index do |error, i|
|
21
|
-
message
|
27
|
+
message = []
|
28
|
+
message << "#{i + 1}." << "[#{error['status']}:#{error['code']}]" << "#{error['title']}" << "#{error['detail']}"
|
29
|
+
message << "in #{error['source']}" unless error['source'].to_s.empty?
|
30
|
+
|
31
|
+
messages << message.join(' ')
|
22
32
|
end
|
23
33
|
|
24
|
-
new(
|
34
|
+
new(messages.join(' '), status_code, errors)
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
28
38
|
|
29
|
-
def handel_error(
|
30
|
-
case
|
39
|
+
def handel_error(response)
|
40
|
+
case response.status
|
31
41
|
# Unauthorized
|
32
|
-
when 401 then InvalidUserCredentialsError.from_errors(
|
33
|
-
# The API key in use does not allow this request
|
34
|
-
when 403 then ForbiddenError.from_errors(
|
42
|
+
when 401 then InvalidUserCredentialsError.from_errors(response)
|
43
|
+
# The API key in use does not allow this request (API role problems)
|
44
|
+
when 403 then ForbiddenError.from_errors(response)
|
35
45
|
# Not found resource
|
36
|
-
when 404 then NotFoundError.from_errors(
|
46
|
+
when 404 then NotFoundError.from_errors(response)
|
37
47
|
# Invaild request entity
|
38
|
-
when 409 then InvalidEntityError.from_errors(
|
48
|
+
when 409 then InvalidEntityError.from_errors(response)
|
39
49
|
# 429 Rate Limit Exceeded
|
40
|
-
when 429 then RateLimitExceededError.from_errors(
|
41
|
-
else ConnectAPIError.from_errors(
|
50
|
+
when 429 then RateLimitExceededError.from_errors(response)
|
51
|
+
else ConnectAPIError.from_errors(response)
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
55
|
+
|
56
|
+
def initialize(message, status_code, errors)
|
57
|
+
@status_code, @errors = status_code, errors
|
58
|
+
super(message)
|
59
|
+
end
|
45
60
|
end
|
46
61
|
|
47
62
|
class RateLimitExceededError < ConnectAPIError; end
|
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
29
|
spec.add_dependency 'faraday', '>= 1.10.0', '< 3.0'
|
30
|
-
spec.add_dependency 'jwt', '>= 1.4', '
|
31
|
-
spec.add_dependency 'openssl', '>=
|
30
|
+
spec.add_dependency 'jwt', '>= 1.4', '< 3'
|
31
|
+
spec.add_dependency 'openssl', '>= 2.2.1', '< 4'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_appstore_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icyleaf
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -37,9 +37,9 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '1.4'
|
40
|
-
- - "
|
40
|
+
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: '3'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,16 +47,16 @@ dependencies:
|
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '1.4'
|
50
|
-
- - "
|
50
|
+
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: '3'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: openssl
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 2.2.1
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '4'
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 2.2.1
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '4'
|