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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 494a8a5e708cbb4977b5a615695320ef043acf68d412478bd8a9d611ca4ff849
4
- data.tar.gz: f3305e5be3e62211f6136f2c020d969f5f9961845e760e6aba1aba9d981a33f1
3
+ metadata.gz: 159be4a02efbe33a9b6a40521f7aaa6e0989c13ed511da96a89632488e6cbaca
4
+ data.tar.gz: 21b2aeb13a33ca663d79d5424b757672720b1bc72ffd9f3e8409df642f6f3449
5
5
  SHA512:
6
- metadata.gz: f12fc5faf9af9374bf8466cae721dd18996ab6e0752a55a88562f41063d605600046d11745342e2ccddf0319c50dd75303821935d9f8b80710d43c8b420c163f
7
- data.tar.gz: 5003210e7e350583f15d2e021ad0248712abc7645092c91949259a93862be712574cc0ae4984ffda05be075fbe5c36245026303fecd993932d340ac69dd88274
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, 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,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
- 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
@@ -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, :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,51 @@ 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
52
+ yield(url)
53
+ end
65
54
 
66
- # break if counter >= count
67
- # end
55
+ def next_pages(count: 1, &block)
56
+ count = 0 if !count.nil? && count < 0
57
+ responses = [self]
58
+ counter = 0
68
59
 
69
- # responses
70
- # end
60
+ resp = self
61
+ loop do
62
+ resp = resp.next_page(&block)
63
+ break if resp.nil?
71
64
 
72
- # def next_url
73
- # return if response.nil?
65
+ responses << resp
66
+ counter += 1
74
67
 
75
- # links = response[:links] || {}
76
- # links[:next]
77
- # end
68
+ break if !count.nil? && counter >= count
69
+ end
78
70
 
79
- # def next_page
80
- # return unless url = next_url
71
+ responses
72
+ end
81
73
 
82
- # Response.new(connection.get(url), connection)
83
- # end
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 response.nil?
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
- block.call(model)
92
+ yield(model)
99
93
  end
100
94
  end
101
95
  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.7'
5
5
  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.status, response.body['errors'])
17
+ handel_error(response)
16
18
  end
17
19
 
18
- def from_errors(errors)
19
- message = ["Check errors(#{errors.size}) from response:"]
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 << "#{i + 1} - [#{error['status']}] #{error['title']}: #{error['detail']} in #{error['source']}"
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(message)
34
+ new(messages.join(' '), status_code, errors)
25
35
  end
26
36
 
27
37
  private
28
38
 
29
- def handel_error(status_code, errors)
30
- case status_code
39
+ def handel_error(response)
40
+ case response.status
31
41
  # 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)
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(errors)
46
+ when 404 then NotFoundError.from_errors(response)
37
47
  # Invaild request entity
38
- when 409 then InvalidEntityError.from_errors(errors)
48
+ when 409 then InvalidEntityError.from_errors(response)
39
49
  # 429 Rate Limit Exceeded
40
- when 429 then RateLimitExceededError.from_errors(errors)
41
- else ConnectAPIError.from_errors(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', '<= 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.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-19 00:00:00.000000000 Z
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: 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'