Class: Spaceship::Client
- Inherits:
-
Object
- Object
- Spaceship::Client
- Defined in:
- lib/spaceship/ui.rb,
lib/spaceship/portal/ui/select_team.rb,
lib/spaceship/client.rb
Direct Known Subclasses
Defined Under Namespace
Classes: InvalidUserCredentialsError, NoUserCredentialsError, UnexpectedResponse, UserInterface
Constant Summary collapse
- PROTOCOL_VERSION =
"QH65B2"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#logger ⇒ Object
The logger in which all requests are logged /tmp/spaceship.log by default.
Automatic Paging collapse
-
#page_size ⇒ Object
The page size we want to request, defaults to 500.
-
#paging ⇒ Object
Handles the paging for you…
Login and Team Selection collapse
-
#login(user = nil, password = nil) ⇒ Spaceship::Client
Authenticates with Apple’s web services.
-
#session? ⇒ Bool
Do we have a valid session?.
Class Method Summary collapse
- .hostname ⇒ Object
-
.login(user = nil, password = nil) ⇒ Spaceship::Client
Authenticates with Apple’s web services.
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#UI ⇒ Object
Public getter for all UI related code.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/spaceship/client.rb', line 61 def initialize @client = Faraday.new(self.class.hostname) do |c| c.response :json, content_type: /\bjson$/ c.response :xml, content_type: /\bxml$/ c.response :plist, content_type: /\bplist$/ c.adapter Faraday.default_adapter if ENV['DEBUG'] # for debugging only # This enables tracking of networking requests using Charles Web Proxy c.response :logger c.proxy "https://127.0.0.1:8888" end end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
19 20 21 |
# File 'lib/spaceship/client.rb', line 19 def client @client end |
#cookie ⇒ Object
Returns the value of attribute cookie.
20 21 22 |
# File 'lib/spaceship/client.rb', line 20 def @cookie end |
#logger ⇒ Object
The logger in which all requests are logged /tmp/spaceship.log by default
24 25 26 |
# File 'lib/spaceship/client.rb', line 24 def logger @logger end |
Class Method Details
.hostname ⇒ Object
57 58 59 |
# File 'lib/spaceship/client.rb', line 57 def self.hostname raise "You must implemented self.hostname" end |
.login(user = nil, password = nil) ⇒ Spaceship::Client
Authenticates with Apple’s web services. This method has to be called once to generate a valid session. The session will automatically be used from then on.
This method will automatically use the username from the Appfile (if available) and fetch the password from the Keychain (if available)
48 49 50 51 52 53 54 55 |
# File 'lib/spaceship/client.rb', line 48 def self.login(user = nil, password = nil) instance = self.new if instance.login(user, password) instance else raise InvalidUserCredentialsError.new end end |
Instance Method Details
#login(user = nil, password = nil) ⇒ Spaceship::Client
Authenticates with Apple’s web services. This method has to be called once to generate a valid session. The session will automatically be used from then on.
This method will automatically use the username from the Appfile (if available) and fetch the password from the Keychain (if available)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/spaceship/client.rb', line 140 def login(user = nil, password = nil) if user.to_s.empty? or password.to_s.empty? require 'credentials_manager' data = CredentialsManager::PasswordManager.shared_manager(user, false) user ||= data.username password ||= data.password end if user.to_s.strip.empty? or password.strip.to_s.empty? raise NoUserCredentialsError.new("No login data provided") end send_login_request(user, password) # different in subclasses end |
#page_size ⇒ Object
The page size we want to request, defaults to 500
102 103 104 |
# File 'lib/spaceship/client.rb', line 102 def page_size @page_size ||= 500 end |
#paging ⇒ Object
Handles the paging for you… for free Just pass a block and use the parameter as page number
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/spaceship/client.rb', line 108 def paging page = 0 results = [] loop do page += 1 current = yield(page) results = results + current break if ((current || []).count < page_size) # no more results end return results end |
#session? ⇒ Bool
Returns Do we have a valid session?.
156 157 158 |
# File 'lib/spaceship/client.rb', line 156 def session? !!@cookie end |
#UI ⇒ Object
Public getter for all UI related code
11 12 13 |
# File 'lib/spaceship/ui.rb', line 11 def UI UserInterface.new(self) end |