Class: AppSendr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/appsendr/client.rb

Overview

A Ruby class to call the AppSendr REST API.

Example:

require 'appsendr'
droppr = AppSendr::Client.new('[email protected]', 'mypass')
droppr.create('myapp')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, host = 'appsendr.com') ⇒ Client

Returns a new instance of Client.



37
38
39
40
41
42
# File 'lib/appsendr/client.rb', line 37

def initialize(api_key,host='appsendr.com')
  @api_key = api_key
  @host = host
  @resource = RestClient::Resource.new "http://#{@host}"
  
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



35
36
37
# File 'lib/appsendr/client.rb', line 35

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



35
36
37
# File 'lib/appsendr/client.rb', line 35

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



35
36
37
# File 'lib/appsendr/client.rb', line 35

def password
  @password
end

#userObject (readonly)

Returns the value of attribute user.



35
36
37
# File 'lib/appsendr/client.rb', line 35

def user
  @user
end

Class Method Details

.auth(user, pass, host) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/appsendr/client.rb', line 26

def self.auth(user,pass,host)
    @resource = RestClient::Resource.new "http://#{host}"
    resp = @resource['/api/user/authenticate'].post({:username=>user, :password=>pass})
    json_resp = JSON.parse(resp)
    return nil unless json_resp
    return json_resp["message"] if json_resp["status"].to_i == 200 
    
end

.gem_version_stringObject



22
23
24
# File 'lib/appsendr/client.rb', line 22

def self.gem_version_string
  "appsendr-gem/#{version}"
end

.versionObject



18
19
20
# File 'lib/appsendr/client.rb', line 18

def self.version
  AppSendr::VERSION
end

Instance Method Details

#abort_multipart(app_id, version_id, ipa, upload_id) ⇒ Object



204
205
206
207
208
209
210
211
212
213
# File 'lib/appsendr/client.rb', line 204

def abort_multipart(app_id, version_id, ipa, upload_id)
    params = { :version=> {
                  :ipa_path=>upload_path(app_id,version_id,File.basename(ipa)),
                  :upload_id=>upload_id, 
                  :id=>version_id 
                  }
              }
    post('/api/version/abort_multipart.json',params)
    
end

#add_collaborator(app_id, emaill) ⇒ Object

add_collaborator



114
115
116
# File 'lib/appsendr/client.rb', line 114

def add_collaborator(app_id,emaill)
    post('/api/collaborator/create.json',{:email=>email,:app_id=>app_id.to_s});
end

#add_group(app_id, name) ⇒ Object



90
91
92
# File 'lib/appsendr/client.rb', line 90

def add_group(app_id,name)
    post('/api/group/create.json',{:name=>name,:app_id=>app_id.to_s});
end

#add_group_tester(app_id, name, email) ⇒ Object



103
104
105
# File 'lib/appsendr/client.rb', line 103

def add_group_tester(app_id,name, email)
    post('/api/group/add_tester.json',{:name=>name,:app_id=>app_id.to_s, :email=>email});
end

#add_tester(app_id, email, name, udid = nil) ⇒ Object



78
79
80
# File 'lib/appsendr/client.rb', line 78

def add_tester(app_id,email,name,udid=nil)
    post('/api/tester/create.json',{:email=>email, :name=>name, :app_id=>app_id.to_s});
end

#authenticateObject



44
45
46
# File 'lib/appsendr/client.rb', line 44

def authenticate
    post('/api/user/authenticate.json');
end

#clear_testers(app_id) ⇒ Object



86
87
88
# File 'lib/appsendr/client.rb', line 86

def clear_testers(app_id)
    delete('/api/tester/clear.json',{:app_id=>app_id.to_s});
end

#collaborators(app_id) ⇒ Object



122
123
124
# File 'lib/appsendr/client.rb', line 122

def collaborators(app_id)
    get('/api/app/collaborators/'+app_id.to_s+'.json')
end

#create(name) ⇒ Object



63
64
65
# File 'lib/appsendr/client.rb', line 63

def create(name)
    post('/api/app/create.json', {:name=>name})
end

#current_version(app_id) ⇒ Object



55
56
57
# File 'lib/appsendr/client.rb', line 55

def current_version(app_id)
    get('/api/app/versions/'+app_id.to_s+'.json',{:limit=>1})
end

#devices(app_id, plist = true) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/appsendr/client.rb', line 67

def devices(app_id,plist=true)
    format = "json"
    format = "plist" if plist
    
    if app_id
        get("/api/tester/devices.#{format}", {:app_id=>app_id})
    else
        get("/api/tester/devices.#{format}")
    end
end

#finish_multipart(app_id, version_id, ipa, upload_id, parts, notify) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/appsendr/client.rb', line 188

def finish_multipart(app_id, version_id, ipa, upload_id, parts, notify)
      ipa_name = File.basename(ipa)
      ipa_size = File.size(ipa)

      params = {}
      params[:ipa_size] = ipa_size
      params[:ipa_path] = upload_path(app_id,version_id,ipa_name)
      params[:upload_id] = upload_id
      params[:parts] = parts
      params[:id] = version_id
      params[:notify] = notify
      post('/api/version/multipart_finished.json', {:version=>params})

              
end

#groups(app_id) ⇒ Object



98
99
100
# File 'lib/appsendr/client.rb', line 98

def groups(app_id)
    get('/api/app/groups/'+app_id.to_s+'.json')
end

#initialize_multipart(app_id, version_id, ipa) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/appsendr/client.rb', line 159

def initialize_multipart(app_id, version_id, ipa)
    ipa_name = File.basename(ipa)
    
    params = {}
 params[:ipa_path] = upload_path(app_id,version_id,ipa_name)
 params[:ipa_name] = ipa_name
    params[:id] = version_id
    
    post('/api/version/multipart_init.json', {:version=>params})
end


52
53
54
# File 'lib/appsendr/client.rb', line 52

def link(id)
    get('/api/app/show/'+id.to_s+'.json');
end

#listObject



48
49
50
# File 'lib/appsendr/client.rb', line 48

def list
    get('/api/user/apps.json')
end

#notify(app_id, group = nil) ⇒ Object



129
130
131
# File 'lib/appsendr/client.rb', line 129

def notify(app_id,group=nil)
    post('/api/app/notify/'+app_id.to_s+'.json',{:group=>group})
end

#remove_collaborator(app_id, email) ⇒ Object



118
119
120
# File 'lib/appsendr/client.rb', line 118

def remove_collaborator(app_id,email)
    post('/api/collaborator/destroy.json',{:email=>email,:app_id=>app_id.to_s});
end

#remove_group(app_id, name) ⇒ Object



94
95
96
# File 'lib/appsendr/client.rb', line 94

def remove_group(app_id, name)
    post('/api/group/destroy.json',{:name=>name,:app_id=>app_id.to_s});
end

#remove_group_tester(app_id, name, email) ⇒ Object



107
108
109
# File 'lib/appsendr/client.rb', line 107

def remove_group_tester(app_id, name, email)
    post('/api/group/remove_tester.json',{:name=>name,:app_id=>app_id.to_s, :email=>email});
end

#remove_tester(app_id, email) ⇒ Object



82
83
84
# File 'lib/appsendr/client.rb', line 82

def remove_tester(app_id,email)
    post('/api/tester/destroy.json',{:email=>email, :app_id=>app_id.to_s});
end

#testers(app_id) ⇒ Object



126
127
128
# File 'lib/appsendr/client.rb', line 126

def testers(app_id)
    get('/api/app/testers/'+app_id.to_s+'.json')
end

#upload(app_id, ipa, provisioning, is_public, notify, notes, bundle_id, icon, later = false) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/appsendr/client.rb', line 133

def upload(app_id, ipa,provisioning, is_public, notify, notes, bundle_id, icon, later=false)
params = {
      :provisioning_profile => File.new(provisioning, 'rb'),
      :notes=>notes,
      :bundle_identifier => bundle_id,
      :built_at=>Time.now,
      :notify=>notify,
:public=>is_public,
      :app_id => app_id.to_s
  #    :ipa=>
    }
if icon
	params[:icon] = File.new(icon,'rb')
end

if later
    params[:upload_later] = File.basename(ipa)
          
   else
       params[:ipa] = File.new(ipa, 'rb')
  		
      end

post('/api/version/create.json', {:version=>params})
end

#upload_part(app_id, version_id, ipa, upload_id, part_number, chunk) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/appsendr/client.rb', line 170

def upload_part(app_id, version_id, ipa, upload_id, part_number, chunk)
      ipa_name = File.basename(ipa)
      ipa_size = File.size(ipa)
      
      params = {}
      params[:ipa_chunk] = File.new(chunk,'rb')
      params[:ipa_size] = ipa_size
      params[:ipa_path] = upload_path(app_id,version_id,ipa_name)
      params[:upload_id] = upload_id
      params[:part_number] = part_number
      params[:id] = version_id

      retryable( :tries => 5 ) do
          resp = post('/api/version/multipart_upload_part.json', {:version=>params})
          return resp 
      end      
end

#versions(app_id) ⇒ Object



59
60
61
# File 'lib/appsendr/client.rb', line 59

def versions(app_id)
    get('/api/app/versions/'+app_id.to_s+'.json')
end