tiny_appstore_connect 0.1.3 → 0.1.6

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: 4c0a0ee36290dce8d6fec8d64801bda09fa15e27668d755e058739a1bdc04d79
4
- data.tar.gz: 2d5b81ef78cd0c3a004df7e625044f01761582b87f3ce5e244a168cc9b3c6283
3
+ metadata.gz: 2fcbbc00829799b1e062102e135c64cb0d1f7d64750bd99020798d9dae36030f
4
+ data.tar.gz: be6d5cb42388b9f9586793482d7daad76f883be20307a7b9e08d8d594038c277
5
5
  SHA512:
6
- metadata.gz: 614467c40dfdc1e23aebc2fd823a0becb210abc6aaebeaeafea348f98826431f408a2476adfc39ab319f561d779838527ab8c02607fec6c7ba5c30c4dcc774b2
7
- data.tar.gz: b8380dfa0bf0e96c580b55cd5651837cf5767f2b28362f2bc554c181d4d0e3860f5be71f5fea8968e9c0b092b733d62ec404538716e17c241df81d2936ade76c
6
+ metadata.gz: a2ba6200584ee7f885f4237a76488e8f1fae738a5d51870a0da4dfa8d36e559ad0d3fe7834f7ed7417bb8055e14eb29752a344a215e2a15fab6e7a0238756cd1
7
+ data.tar.gz: cc8c51e6c826dc6138667317a58f628fcc70f09e91857965bb892e01db162a6ad64e8cecb1b1b4eba49e2c0c41e0893b9b58d83ff7444ca5ad12560c4fa0d169
data/.rubocop.yml CHANGED
@@ -1,13 +1,34 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ SuggestExtensions: false
4
+ NewCops: disable
5
+ Exclude:
6
+ - 'bin/*'
7
+ - 'spec/**/*'
8
+ - '*.rb'
3
9
 
4
10
  Style/StringLiterals:
5
11
  Enabled: true
6
- EnforcedStyle: double_quotes
12
+ EnforcedStyle: single_quotes
7
13
 
8
14
  Style/StringLiteralsInInterpolation:
9
15
  Enabled: true
10
- EnforcedStyle: double_quotes
16
+ EnforcedStyle: single_quotes
11
17
 
12
18
  Layout/LineLength:
13
19
  Max: 120
20
+
21
+ Bundler/OrderedGems:
22
+ Enabled: false
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+
27
+ Lint/NonDeterministicRequireOrder:
28
+ Enabled: false
29
+
30
+ Lint/AssignmentInCondition:
31
+ Enabled: false
32
+
33
+ Layout/TrailingEmptyLines:
34
+ Enabled: false
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gem 'awesome_print', '~> 2.0.0.pre2'
9
9
  gem 'rake', '~> 13.0'
10
10
  gem 'rspec', '~> 3.0'
11
11
  gem 'rubocop', '~> 1.21'
12
+ gem 'keycutter'
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -11,7 +11,6 @@ RuboCop::RakeTask.new
11
11
 
12
12
  task default: %i[spec rubocop]
13
13
 
14
-
15
14
  namespace :github do
16
15
  task :release do
17
16
  Rake::Task['build'].invoke
@@ -22,18 +21,24 @@ namespace :github do
22
21
 
23
22
  task :push do
24
23
  helper = Bundler::GemHelper.new
25
- # puts helper.base
26
- # puts helper.gemspec
27
- puts "#{helper.send(:name)}-*.gem"
28
- puts helper.send(:name)
29
- puts helper.send(:built_gem_path)
30
- puts Gem::Util.glob_files_in_dir("#{helper.send(:name)}-*.gem", helper.base)
31
- # puts helper.send(:rubygem_push, helper.send(:built_gem_path))
32
- # helper.send(:rubygem_push, '.')
33
- # cmd = [*gem_command, "push", path]
34
- # cmd << "--key" << gem_key if gem_key
35
- # cmd << "--host" << allowed_push_host if allowed_push_host
36
-
37
- # Bundler.ui.debug(cmd)
24
+ gem_base = helper.base
25
+ gem_name = helper.send(:name)
26
+ gem_version = helper.send(:version)
27
+ gem_key = 'github'
28
+ allowed_push_host = 'https://rubygems.pkg.github.com/icyleaf'
29
+
30
+ gem_file = Gem::Util.glob_files_in_dir("#{gem_name}-*.gem", File.join(gem_base, 'pkg'))
31
+ .max_by { |f| File.mtime(f) }
32
+
33
+ cmd = ['gem', 'push', gem_file]
34
+ cmd << '--key' << gem_key
35
+ cmd << '--host' << allowed_push_host
36
+
37
+ Bundler.ui.debug(cmd)
38
+ Bundler::SharedHelpers.chdir(gem_base) do
39
+ abort unless Kernel.system(*cmd)
40
+ end
41
+
42
+ Bundler.ui.confirm "Pushed #{gem_name} #{gem_version} to #{gem_file}"
38
43
  end
39
44
  end
@@ -4,20 +4,24 @@
4
4
  # License by fastlane team (https://github.com/fastlane/fastlane)
5
5
 
6
6
  require 'faraday'
7
- if Gem::Dependency.new('', '< 2.0.0').match?('', Faraday::VERSION)
8
- require 'faraday_middleware'
9
- end
7
+ require 'faraday_middleware' if Gem::Dependency.new('', '< 2.0.0').match?('', Faraday::VERSION)
8
+ require 'tiny_appstore_connect/clients/app_store_version'
9
+ require 'tiny_appstore_connect/clients/app'
10
+ require 'tiny_appstore_connect/clients/build'
11
+ require 'tiny_appstore_connect/clients/device'
12
+ require 'tiny_appstore_connect/clients/certificate'
13
+ require 'tiny_appstore_connect/clients/user'
10
14
 
11
15
  module TinyAppstoreConnect
12
16
  class Client
13
- Dir[File.expand_path('clients/*.rb', __dir__)].each { |f| require f }
14
-
15
17
  ENDPOINT = 'https://api.appstoreconnect.apple.com/v1'
16
18
 
17
19
  include App
18
20
  include AppStoreVersion
19
21
  include Build
20
22
  include Device
23
+ include Certificate
24
+ include User
21
25
 
22
26
  attr_reader :connection
23
27
 
@@ -43,7 +47,6 @@ module TinyAppstoreConnect
43
47
  private
44
48
 
45
49
  def validates(response)
46
- puts response.body
47
50
  case response.status
48
51
  when 200, 201, 204
49
52
  # 200: get requests
@@ -56,8 +59,9 @@ module TinyAppstoreConnect
56
59
  end
57
60
 
58
61
  def handle_response(response)
59
- response = Response.new(response, connection)
62
+ response = Response.new(response, self)
60
63
 
64
+ # It always never to be go into here, throws a 429 error.
61
65
  if (remaining = response.rate[:remaining]) && remaining.to_i.zero?
62
66
  raise RateLimitExceededError, "Request limit reached #{response.rate[:limit]}
63
67
  in the previous 60 minutes with url: #{response.request_url}"
@@ -67,29 +71,39 @@ module TinyAppstoreConnect
67
71
  end
68
72
 
69
73
  def configure_connection(**kargs)
70
- @token = Token.new(**kargs)
71
74
  endpoint = kargs[:endpoint] || ENDPOINT
75
+ options = connection_options(**kargs)
72
76
 
73
- connection_opts= {
77
+ @connection = Faraday.new(endpoint, options) do |builder|
78
+ configure_builder_common(builder, **kargs)
79
+ configure_builder_debug(builder, **kargs)
80
+ end
81
+ end
82
+
83
+ def connection_options(**kargs)
84
+ {
74
85
  request: {
75
- timeout: (kargs[:timeout] || 300).to_i,
76
- open_timeout: (kargs[:timeout] || 300).to_i
86
+ timeout: (kargs[:timeout] || 300).to_i,
87
+ open_timeout: (kargs[:timeout] || 300).to_i
77
88
  }
78
89
  }
90
+ end
79
91
 
80
- @connection = Faraday.new(endpoint) do |builder|
81
- builder.headers[:user_agent] = "TinyAppstoreConnect v#{TinyAppstoreConnect::VERSION}"
82
- builder.headers[:accept] = 'application/json'
83
- builder.request :url_encoded
84
- builder.request :authorization, 'Bearer', -> { @token.token }
85
- builder.response :json, content_type: /\bjson$/
86
-
87
- if kargs[:debug] || ENV['ASC_DEBUG']
88
- builder.proxy = kargs[:proxy] || ENV['ASC_PROXY'] ||'https://127.0.0.1:8888'
89
- builder.ssl[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
90
- builder.response :logger, nil, { log_level: :debug }
91
- end
92
- end
92
+ def configure_builder_common(builder, **kargs)
93
+ @token = Token.new(**kargs)
94
+
95
+ builder.headers[:user_agent] = "TinyAppstoreConnect v#{TinyAppstoreConnect::VERSION}"
96
+ builder.request :url_encoded
97
+ builder.request :authorization, 'Bearer', -> { @token.token }
98
+ builder.response :json, content_type: /\bjson$/
99
+ end
100
+
101
+ def configure_builder_debug(builder, **kargs)
102
+ return unless kargs[:debug] || ENV['ASC_DEBUG']
103
+
104
+ builder.proxy = kargs[:proxy] || ENV['ASC_PROXY'] || 'https://127.0.0.1:8888'
105
+ builder.ssl[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
106
+ builder.response :logger, nil, { log_level: :debug }
93
107
  end
94
108
  end
95
109
  end
@@ -5,38 +5,38 @@
5
5
 
6
6
  class TinyAppstoreConnect::Client
7
7
  module App
8
- def apps(query = {})
9
- get('apps', query)
8
+ def apps(**query)
9
+ get('apps', **query)
10
10
  end
11
11
 
12
- def app(id, query = {})
13
- get("apps/#{id}", query).to_model
12
+ def app(id, **query)
13
+ get("apps/#{id}", **query).to_model
14
14
  end
15
15
 
16
- def app_versions(id, query = {})
17
- get("apps/#{id}/appStoreVersions", query)
16
+ def app_versions(id, **query)
17
+ get("apps/#{id}/appStoreVersions", **query)
18
18
  end
19
19
 
20
- def app_edit_version(id, includes: AppStoreVersion::ESSENTIAL_INCLUDES)
20
+ def app_edit_version(id, includes: TinyAppstoreConnect::Model::AppStoreVersion::ESSENTIAL_INCLUDES)
21
21
  filters = {
22
22
  appStoreState: [
23
- AppStoreState::PREPARE_FOR_SUBMISSION,
24
- AppStoreState::DEVELOPER_REJECTED,
25
- AppStoreState::REJECTED,
26
- AppStoreState::METADATA_REJECTED,
27
- AppStoreState::WAITING_FOR_REVIEW,
28
- AppStoreState::INVALID_BINARY,
29
- AppStoreState::IN_REVIEW,
30
- AppStoreState::PENDING_DEVELOPER_RELEASE
23
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::PREPARE_FOR_SUBMISSION,
24
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::DEVELOPER_REJECTED,
25
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::REJECTED,
26
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::METADATA_REJECTED,
27
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::WAITING_FOR_REVIEW,
28
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::INVALID_BINARY,
29
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::IN_REVIEW,
30
+ TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::PENDING_DEVELOPER_RELEASE
31
31
  ].join(',')
32
32
  }
33
33
 
34
34
  app_versions(id, include: includes, filter: filters).to_model
35
35
  end
36
36
 
37
- def app_live_version(id, includes: ESSENTIAL_INCLUDES)
37
+ def app_live_version(id, includes: TinyAppstoreConnect::Model::AppStoreVersion::ESSENTIAL_INCLUDES)
38
38
  filters = {
39
- appStoreState: AppStoreState::READY_FOR_SALE
39
+ appStoreState: TinyAppstoreConnect::Model::AppStoreVersion::AppStoreState::READY_FOR_SALE
40
40
  }
41
41
 
42
42
  app_versions(id, include: includes, filter: filters).to_model
@@ -9,8 +9,8 @@ class TinyAppstoreConnect::Client
9
9
  # get('appStoreVersions', query)
10
10
  # end
11
11
 
12
- def version(id, query = {})
13
- get("appStoreVersions/#{id}", query)
12
+ def version(id, **query)
13
+ get("appStoreVersions/#{id}", **query)
14
14
  end
15
15
 
16
16
  def select_version_build(id, build_id:)
@@ -9,20 +9,20 @@ class TinyAppstoreConnect::Client
9
9
  app_builds(id, limit: 1).to_model
10
10
  end
11
11
 
12
- def app_builds(id, **kargs)
13
- kargs = kargs.merge(filter: { app: id })
14
- builds(**kargs)
12
+ def app_builds(id, **query)
13
+ query = query.merge(filter: { app: id })
14
+ builds(**query)
15
15
  end
16
16
 
17
17
  def builds(limit: 200, sort: '-uploadedDate',
18
18
  includes: TinyAppstoreConnect::Model::Build::ESSENTIAL_INCLUDES,
19
- **kargs)
19
+ **query)
20
20
 
21
- kargs = kargs.merge(limit: limit)
21
+ query = query.merge(limit: limit)
22
22
  .merge(sort: sort)
23
23
  .merge(include: includes)
24
24
 
25
- get('builds', **kargs)
25
+ get('builds', **query)
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Inspried from fastlane/spaceship
4
+ # License by fastlane team (https://github.com/fastlane/fastlane)
5
+
6
+ class TinyAppstoreConnect::Client
7
+ module Certificate
8
+ def certificates(**query)
9
+ get('certificates', **query)
10
+ end
11
+
12
+ def certificate(id, **query)
13
+ get("certificates/#{id}", **query).to_model
14
+ end
15
+
16
+ def distribution_certificates(**query)
17
+ query[:filter] = {
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(',')
23
+ }
24
+
25
+ certificates(**query)
26
+ end
27
+ end
28
+ end
@@ -6,13 +6,32 @@
6
6
  class TinyAppstoreConnect::Client
7
7
  module Device
8
8
  def devices(filter: {}, includes: nil, limit: nil, sort: nil)
9
- kargs = {
9
+ query = {
10
10
  include: includes,
11
11
  limit: limit,
12
12
  sort: sort
13
13
  }.delete_if { |_, v| v.nil? }
14
14
 
15
- get('devices', **kargs)
15
+ get('devices', **query)
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)
16
35
  end
17
36
  end
18
37
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Inspried from fastlane/spaceship
4
+ # License by fastlane team (https://github.com/fastlane/fastlane)
5
+
6
+ class TinyAppstoreConnect::Client
7
+ module User
8
+ def users(**query)
9
+ get('users', **query)
10
+ end
11
+
12
+ def user(id, **query)
13
+ get("users/#{id}", **query).to_model
14
+ end
15
+ end
16
+ end
@@ -167,3 +167,5 @@ require_relative 'models/build'
167
167
  require_relative 'models/pre_release_version'
168
168
  require_relative 'models/app_store_version_submission'
169
169
  require_relative 'models/device'
170
+ require_relative 'models/certificate'
171
+ require_relative 'models/user'
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Inspried from fastlane/spaceship
4
+ # License by fastlane team (https://github.com/fastlane/fastlane)
5
+
6
+ module TinyAppstoreConnect::Model
7
+ class Certificate
8
+ include TinyAppstoreConnect::Model
9
+
10
+ attr_accessor :name
11
+ attr_accessor :certificate_type
12
+ attr_accessor :display_name
13
+ attr_accessor :serial_number
14
+ attr_accessor :platform
15
+ attr_accessor :expiratio_date
16
+ attr_accessor :certificate_content
17
+
18
+ module CertificateType
19
+ DISTRIBUTION = 'DISTRIBUTION'
20
+ DEVELOPMENT = 'DEVELOPMENT'
21
+
22
+ IOS_DEVELOPMENT = 'IOS_DEVELOPMENT'
23
+ IOS_DISTRIBUTION = 'IOS_DISTRIBUTION'
24
+ MAC_APP_DISTRIBUTION = 'MAC_APP_DISTRIBUTION'
25
+ MAC_INSTALLER_DISTRIBUTION = 'MAC_INSTALLER_DISTRIBUTION'
26
+ MAC_APP_DEVELOPMENT = 'MAC_APP_DEVELOPMENT'
27
+ DEVELOPER_ID_KEXT = 'DEVELOPER_ID_KEXT'
28
+ DEVELOPER_ID_APPLICATION = 'DEVELOPER_ID_APPLICATION'
29
+ PASS_TYPE_ID = 'PASS_TYPE_ID'
30
+ PASS_TYPE_ID_WITH_NFC = 'PASS_TYPE_ID_WITH_NFC'
31
+ end
32
+
33
+ def team_id
34
+ subject['OU']
35
+ end
36
+
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
52
+
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")
69
+
70
+ OpenSSL::X509::Certificate.new(data)
71
+ end.call
72
+ end
73
+
74
+ def self.type
75
+ 'certificates'
76
+ end
77
+ end
78
+ end
@@ -4,7 +4,7 @@
4
4
  # License by fastlane team (https://github.com/fastlane/fastlane)
5
5
 
6
6
  module TinyAppstoreConnect::Model
7
- class PreReleaseVersion
7
+ class UserRole
8
8
  include TinyAppstoreConnect::Model
9
9
 
10
10
  attr_accessor :version
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Inspried from fastlane/spaceship
4
+ # License by fastlane team (https://github.com/fastlane/fastlane)
5
+
6
+ module TinyAppstoreConnect::Model
7
+ class User
8
+ include TinyAppstoreConnect::Model
9
+
10
+ attr_accessor :username
11
+ attr_accessor :first_name
12
+ attr_accessor :last_name
13
+ attr_accessor :roles
14
+ attr_accessor :all_apps_visible
15
+ attr_accessor :provisioning_allowed
16
+
17
+ module UserRole
18
+ ADMIN = 'ADMIN'
19
+ FINANCE = 'FINANCE'
20
+ ACCOUNT_HOLDER = 'ACCOUNT_HOLDER'
21
+ SALES = 'SALES'
22
+ MARKETING = 'MARKETING'
23
+ APP_MANAGER = 'APP_MANAGER'
24
+ DEVELOPER = 'DEVELOPER'
25
+ ACCESS_TO_REPORTS = 'ACCESS_TO_REPORTS'
26
+ CUSTOMER_SUPPORT = 'CUSTOMER_SUPPORT'
27
+ IMAGE_MANAGER = 'IMAGE_MANAGER'
28
+ CREATE_APPS = 'CREATE_APPS'
29
+ CLOUD_MANAGED_DEVELOPER_ID = 'CLOUD_MANAGED_DEVELOPER_ID'
30
+ CLOUD_MANAGED_APP_DISTRIBUTION = 'CLOUD_MANAGED_APP_DISTRIBUTION'
31
+ end
32
+
33
+ def self.type
34
+ 'users'
35
+ end
36
+ end
37
+ end
@@ -7,17 +7,17 @@ require 'forwardable'
7
7
 
8
8
  module TinyAppstoreConnect
9
9
  class Response
10
- include Enumerable
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TinyAppstoreConnect
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.6'
5
5
  end
@@ -10,38 +10,52 @@ 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
- errors = response.body['errors']
16
- case response.status
17
- when 401
18
- # Unauthorized
19
- InvalidUserCredentialsError.from_errors(errors)
20
- when 403
21
- # The API key in use does not allow this request
22
- ForbiddenError.from_errors(errors)
23
- when 404
24
- # Not found resource
25
- NotFoundError.from_errors(errors)
26
- when 409
27
- # Invaild request entity
28
- InvalidEntityError.from_errors(errors)
29
- when 429
30
- # 429 Rate Limit Exceeded
31
- RateLimitExceededError.from_errors(errors)
32
- else
33
- ConnectAPIError.from_errors(errors)
34
- end
17
+ handel_error(response)
35
18
  end
36
19
 
37
- def from_errors(errors)
38
- 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:"]
39
26
  errors.each_with_index do |error, i|
40
- 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(' ')
41
32
  end
42
33
 
43
- new(message)
34
+ new(messages.join(' '), status_code, errors)
44
35
  end
36
+
37
+ private
38
+
39
+ def handel_error(response)
40
+ case response.status
41
+ # Unauthorized
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)
45
+ # Not found resource
46
+ when 404 then NotFoundError.from_errors(response)
47
+ # Invaild request entity
48
+ when 409 then InvalidEntityError.from_errors(response)
49
+ # 429 Rate Limit Exceeded
50
+ when 429 then RateLimitExceededError.from_errors(response)
51
+ else ConnectAPIError.from_errors(response)
52
+ end
53
+ end
54
+ end
55
+
56
+ def initialize(message, status_code, errors)
57
+ @status_code, @errors = status_code, errors
58
+ super(message)
45
59
  end
46
60
  end
47
61
 
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['github_repo'] = 'ssh://github.com/icyleaf/tiny_appstore_connect'
19
19
 
20
-
21
20
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
21
  `git ls-files -z`.split("\x0").reject do |f|
23
22
  (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
@@ -28,5 +27,6 @@ Gem::Specification.new do |spec|
28
27
  spec.require_paths = ['lib']
29
28
 
30
29
  spec.add_dependency 'faraday', '>= 1.10.0', '< 3.0'
31
- spec.add_dependency 'jwt', '>= 1.4', '<= 2.2.1'
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.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-26 00:00:00.000000000 Z
11
+ date: 2022-07-22 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,9 +47,29 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.4'
50
- - - "<="
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '3'
53
+ - !ruby/object:Gem::Dependency
54
+ name: openssl
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
51
58
  - !ruby/object:Gem::Version
52
59
  version: 2.2.1
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '4'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.2.1
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '4'
53
73
  description: Tiny AppStore Connect API
54
74
  email:
55
75
  - icyleaf.cn@gmail.com
@@ -69,14 +89,18 @@ files:
69
89
  - lib/tiny_appstore_connect/clients/app.rb
70
90
  - lib/tiny_appstore_connect/clients/app_store_version.rb
71
91
  - lib/tiny_appstore_connect/clients/build.rb
92
+ - lib/tiny_appstore_connect/clients/certificate.rb
72
93
  - lib/tiny_appstore_connect/clients/device.rb
94
+ - lib/tiny_appstore_connect/clients/user.rb
73
95
  - lib/tiny_appstore_connect/model.rb
74
96
  - lib/tiny_appstore_connect/models/app.rb
75
97
  - lib/tiny_appstore_connect/models/app_store_version.rb
76
98
  - lib/tiny_appstore_connect/models/app_store_version_submission.rb
77
99
  - lib/tiny_appstore_connect/models/build.rb
100
+ - lib/tiny_appstore_connect/models/certificate.rb
78
101
  - lib/tiny_appstore_connect/models/device.rb
79
102
  - lib/tiny_appstore_connect/models/pre_release_version.rb
103
+ - lib/tiny_appstore_connect/models/user.rb
80
104
  - lib/tiny_appstore_connect/response.rb
81
105
  - lib/tiny_appstore_connect/token.rb
82
106
  - lib/tiny_appstore_connect/version.rb