tiny_appstore_connect 0.1.4 → 0.1.5

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: 494a8a5e708cbb4977b5a615695320ef043acf68d412478bd8a9d611ca4ff849
4
- data.tar.gz: f3305e5be3e62211f6136f2c020d969f5f9961845e760e6aba1aba9d981a33f1
3
+ metadata.gz: 62e9ae341686817d57e8f0ea7833eef6be53a5a7c1e6416ffd4e81916375a61c
4
+ data.tar.gz: a9ad021b50df72944688a01c3c2670ace550a669de1efd9677df51af04459117
5
5
  SHA512:
6
- metadata.gz: f12fc5faf9af9374bf8466cae721dd18996ab6e0752a55a88562f41063d605600046d11745342e2ccddf0319c50dd75303821935d9f8b80710d43c8b420c163f
7
- data.tar.gz: 5003210e7e350583f15d2e021ad0248712abc7645092c91949259a93862be712574cc0ae4984ffda05be075fbe5c36245026303fecd993932d340ac69dd88274
6
+ metadata.gz: 8d9fcb1dad512e6650168ef085d0ff3b546d2f7c3e23d383349899606c935537aa49f9b7bcc4191fab213c4aadf11988b3e132b40568a39cb0148c99f38b63a8
7
+ data.tar.gz: c01a733a86ad47db48eaacf20c96cacb7019c60c4b6adf660385583719b26608f1a303eebd119cc131c33b6cca968f21b702802609808f7fdffb5985d254f04b
@@ -59,8 +59,9 @@ module TinyAppstoreConnect
59
59
  end
60
60
 
61
61
  def handle_response(response)
62
- response = Response.new(response, connection)
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: TinyAppstoreConnect::Model::Certificate::CertificateType::DISTRIBUTION,
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,9 @@ 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
17
21
  end
18
22
  end
@@ -31,22 +31,44 @@ module TinyAppstoreConnect::Model
31
31
  end
32
32
 
33
33
  def team_id
34
- certificate.subject
35
- .to_a
36
- .find {|n, _, _| n == 'OU'}[1]
37
- .force_encoding('UTF-8')
34
+ subject['OU']
38
35
  end
39
36
 
40
- def certificate
41
- require 'openssl'
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
- data = [
44
- '-----BEGIN CERTIFICATE-----',
45
- certificate_content,
46
- '-----END CERTIFICATE-----'
47
- ].join("\n")
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
- OpenSSL::X509::Certificate.new(data)
70
+ OpenSSL::X509::Certificate.new(data)
71
+ end.call
50
72
  end
51
73
 
52
74
  def self.type
@@ -10,14 +10,14 @@ module TinyAppstoreConnect
10
10
  # include Enumerable
11
11
  extend Forwardable
12
12
 
13
- attr_reader :response, :connection
13
+ attr_reader :response, :client
14
14
 
15
- def initialize(response, connection)
15
+ def initialize(response, client)
16
16
  @response = response
17
- @connection = connection
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,47 @@ module TinyAppstoreConnect
37
37
  end
38
38
  end
39
39
 
40
- def next_link
41
- return if response.nil?
40
+ def next_url
41
+ return if body.nil?
42
42
 
43
- links = response[:links] || {}
44
- links[:next]
43
+ links = body['links'] || {}
44
+ links['next']
45
45
  end
46
46
 
47
- # def all_pages
48
- # next_pages(count: 0)
49
- # end
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
- # def next_pages(count: 1)
52
- # count = count.to_i
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
65
-
66
- # break if counter >= count
67
- # end
52
+ yield(url)
53
+ end
68
54
 
69
- # responses
70
- # end
55
+ def next_pages(count: 1, &block)
56
+ count = 0 if !count.nil? && count < 0
57
+ responses = [self]
58
+ counter = 0
71
59
 
72
- # def next_url
73
- # return if response.nil?
60
+ resp = self
61
+ loop do
62
+ resp = resp.next_page(&block)
63
+ break if resp.nil?
74
64
 
75
- # links = response[:links] || {}
76
- # links[:next]
77
- # end
65
+ responses << resp
66
+ counter += 1
78
67
 
79
- # def next_page
80
- # return unless url = next_url
68
+ break if !count.nil? && counter >= count
69
+ end
81
70
 
82
- # Response.new(connection.get(url), connection)
83
- # end
71
+ responses
72
+ end
84
73
 
85
- def to_model
86
- to_models.first
74
+ def all_pages(flatten: false, &block)
75
+ responses = next_pages(count: nil, &block)
76
+ flatten ? responses.flat_map(&:to_models) : responses
87
77
  end
88
78
 
89
79
  def to_models
90
- return [] if response.nil?
80
+ return [] if body.nil?
91
81
 
92
82
  model_or_models = Parser.parse(response, rate)
93
83
  [model_or_models].flatten
@@ -95,7 +85,7 @@ module TinyAppstoreConnect
95
85
 
96
86
  def each(&block)
97
87
  to_models.each do |model|
98
- block.call(model)
88
+ yield(model)
99
89
  end
100
90
  end
101
91
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TinyAppstoreConnect
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -10,38 +10,49 @@ 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.status, response.body['errors'])
17
+ handel_error(response)
16
18
  end
17
19
 
18
- def from_errors(errors)
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']
19
25
  message = ["Check errors(#{errors.size}) from response:"]
20
26
  errors.each_with_index do |error, i|
21
27
  message << "#{i + 1} - [#{error['status']}] #{error['title']}: #{error['detail']} in #{error['source']}"
22
28
  end
23
29
 
24
- new(message)
30
+ new(message, status_code, errors)
25
31
  end
26
32
 
27
33
  private
28
34
 
29
- def handel_error(status_code, errors)
30
- case status_code
35
+ def handel_error(response)
36
+ case response.status
31
37
  # Unauthorized
32
- when 401 then InvalidUserCredentialsError.from_errors(errors)
33
- # The API key in use does not allow this request
34
- when 403 then ForbiddenError.from_errors(errors)
38
+ when 401 then InvalidUserCredentialsError.from_errors(response)
39
+ # The API key in use does not allow this request (API role problems)
40
+ when 403 then ForbiddenError.from_errors(response)
35
41
  # Not found resource
36
- when 404 then NotFoundError.from_errors(errors)
42
+ when 404 then NotFoundError.from_errors(response)
37
43
  # Invaild request entity
38
- when 409 then InvalidEntityError.from_errors(errors)
44
+ when 409 then InvalidEntityError.from_errors(response)
39
45
  # 429 Rate Limit Exceeded
40
- when 429 then RateLimitExceededError.from_errors(errors)
41
- else ConnectAPIError.from_errors(errors)
46
+ when 429 then RateLimitExceededError.from_errors(response)
47
+ else ConnectAPIError.from_errors(response)
42
48
  end
43
49
  end
44
50
  end
51
+
52
+ def initialize(message, status_code, errors)
53
+ @status_code, @errors = status_code, errors
54
+ super(message)
55
+ end
45
56
  end
46
57
 
47
58
  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', '<= 2.2.1'
31
- spec.add_dependency 'openssl', '>= 3.0.0', '< 4'
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
4
+ version: 0.1.5
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-19 00:00:00.000000000 Z
11
+ date: 2022-07-21 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: 2.2.1
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: 2.2.1
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: 3.0.0
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: 3.0.0
69
+ version: 2.2.1
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '4'