Class: Spaceship::ConnectAPI::Client

Inherits:
Spaceship::Client show all
Defined in:
spaceship/lib/spaceship/connect_api/client.rb

Constant Summary

Constants inherited from Spaceship::Client

Spaceship::Client::AUTH_TYPES, Spaceship::Client::AccessForbiddenError, Spaceship::Client::AppleTimeoutError, Spaceship::Client::BadGatewayError, Spaceship::Client::BasicPreferredInfoError, Spaceship::Client::GatewayTimeoutError, Spaceship::Client::InsufficientPermissions, Spaceship::Client::InternalServerError, Spaceship::Client::InvalidUserCredentialsError, Spaceship::Client::NoUserCredentialsError, Spaceship::Client::PROTOCOL_VERSION, Spaceship::Client::ProgramLicenseAgreementUpdated, Spaceship::Client::USER_AGENT, Spaceship::Client::UnauthorizedAccessError, Spaceship::Client::UnexpectedResponse

Instance Attribute Summary collapse

Attributes inherited from Spaceship::Client

#client, #csrf_tokens, #logger, #provider, #user, #user_email

Client Init collapse

Methods inherited from Spaceship::Client

#UI, #ask_for_2fa_code, #choose_phone_number, client_with_authorization_from, #cookie, #detect_most_common_errors_and_raise_exceptions, #fastlane_user_dir, #fetch_olympus_session, #fetch_program_license_agreement_messages, #handle_two_factor, #handle_two_step, #handle_two_step_for_device, #handle_two_step_or_factor, #itc_service_key, #load_session_from_env, #load_session_from_file, login, #login, #page_size, #paging, #parse_response, #persistent_cookie_path, #phone_id_from_masked_number, #phone_id_from_number, #raise_insufficient_permission_error!, #request, #request_two_factor_code_from_phone, #request_two_factor_code_from_phone_choose, #send_shared_login_request, #sms_automatically_sent, #sms_fallback, spaceship_session_env, #store_cookie, #store_session, #team_id, #team_id=, #team_information, #team_name, #teams, #update_request_headers, #user_details_data, #with_retry

Constructor Details

#initialize(cookie: nil, current_team_id: nil, token: nil) ⇒ Client

Instantiates a client with cookie session or a JWT token.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 14

def initialize(cookie: nil, current_team_id: nil, token: nil)
  if token.nil?
    super(cookie: cookie, current_team_id: current_team_id, timeout: 1200)
  else
    options = {
      request: {
        timeout:       (ENV["SPACESHIP_TIMEOUT"] || 300).to_i,
        open_timeout:  (ENV["SPACESHIP_TIMEOUT"] || 300).to_i
      }
    }
    @token = token
    @current_team_id = current_team_id

    hostname = "https://api.appstoreconnect.apple.com/v1/"

    @client = Faraday.new(hostname, options) do |c|
      c.response(:json, content_type: /\bjson$/)
      c.response(:xml, content_type: /\bxml$/)
      c.response(:plist, content_type: /\bplist$/)
      c.use(FaradayMiddleware::RelsMiddleware)
      c.adapter(Faraday.default_adapter)
      c.headers["Authorization"] = "Bearer #{token.text}"

      if ENV['SPACESHIP_DEBUG']
        # for debugging only
        # This enables tracking of networking requests using Charles Web Proxy
        c.proxy = "https://127.0.0.1:8888"
        c.ssl[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
      elsif ENV["SPACESHIP_PROXY"]
        c.proxy = ENV["SPACESHIP_PROXY"]
        c.ssl[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if ENV["SPACESHIP_PROXY_SSL_VERIFY_NONE"]
      end

      if ENV["DEBUG"]
        puts("To run spaceship through a local proxy, use SPACESHIP_DEBUG")
      end
    end
  end
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token


7
8
9
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 7

def token
  @token
end

Class Method Details

.hostnameObject


54
55
56
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 54

def self.hostname
  return nil
end

Instance Method Details

#build_params(filter: nil, includes: nil, limit: nil, sort: nil, cursor: nil) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 66

def build_params(filter: nil, includes: nil, limit: nil, sort: nil, cursor: nil)
  params = {}

  filter = filter.delete_if { |k, v| v.nil? } if filter

  params[:filter] = filter if filter && !filter.empty?
  params[:include] = includes if includes
  params[:limit] = limit if limit
  params[:sort] = sort if sort
  params[:cursor] = cursor if cursor

  return params
end

#delete(url_or_path, params = nil, body = nil) ⇒ Object


114
115
116
117
118
119
120
121
122
123
124
125
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 114

def delete(url_or_path, params = nil, body = nil)
  response = with_asc_retry do
    request(:delete) do |req|
      req.url(url_or_path)
      req.options.params_encoder = Faraday::NestedParamsEncoder if params
      req.params = params if params
      req.body = body.to_json if body
      req.headers['Content-Type'] = 'application/json' if body
    end
  end
  handle_response(response)
end

#get(url_or_path, params = nil) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 80

def get(url_or_path, params = nil)
  response = with_asc_retry do
    request(:get) do |req|
      req.url(url_or_path)
      req.options.params_encoder = Faraday::NestedParamsEncoder
      req.params = params if params
      req.headers['Content-Type'] = 'application/json'
    end
  end
  handle_response(response)
end

#patch(url_or_path, body) ⇒ Object


103
104
105
106
107
108
109
110
111
112
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 103

def patch(url_or_path, body)
  response = with_asc_retry do
    request(:patch) do |req|
      req.url(url_or_path)
      req.body = body.to_json
      req.headers['Content-Type'] = 'application/json'
    end
  end
  handle_response(response)
end

#post(url_or_path, body) ⇒ Object


92
93
94
95
96
97
98
99
100
101
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 92

def post(url_or_path, body)
  response = with_asc_retry do
    request(:post) do |req|
      req.url(url_or_path)
      req.body = body.to_json
      req.headers['Content-Type'] = 'application/json'
    end
  end
  handle_response(response)
end

#web_session?Boolean

Helpers

Returns:

  • (Boolean)

62
63
64
# File 'spaceship/lib/spaceship/connect_api/client.rb', line 62

def web_session?
  return @token.nil?
end