forked from RishabhTayal/itc-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappstore.rb
60 lines (57 loc) · 1.94 KB
/
appstore.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
53
54
55
56
57
58
59
60
require 'sinatra'
require 'spaceship'
require 'json'
# Get list of ratings for a specified app with bundle_id
get '/ratings' do
content_type :json
username = request.env['HTTP_USERNAME']
password = request.env['HTTP_PASSWORD']
bundle_id = params[:bundle_id]
store_front = params[:store_front]
store_front = '' if store_front.nil?
Spaceship::Tunes.login(username, password)
ratings = Spaceship::Tunes::Application.find(bundle_id).ratings
ratings.reviews(store_front).collect do |review|
{
id: review.id,
title: review.title,
rating: review.rating,
review: review.review,
store_front: review.store_front,
total_views: review.total_views,
raw_developer_response: review.raw_developer_response,
last_modified: review.last_modified,
developer_response: {
id: review.developer_response.id,
response: review.developer_response.response,
last_modified: review.developer_response.last_modified,
hidden: review.developer_response.hidden,
state: review.developer_response.state
}
}
end.to_json
end
# Add a new response to a rating
post '/response' do
content_type :json
username = request.env['HTTP_USERNAME']
password = request.env['HTTP_PASSWORD']
rating_id = params[:rating_id]
bundle_id = params[:bundle_id]
response = params[:response_text]
Spaceship::Tunes.login(username, password)
app = Spaceship::Tunes::Application.find(bundle_id)
body app.ratings.sendResponse(rating_id, response).to_json
end
# Delete developer response from a review
delete '/response' do
content_type :json
username = request.env['HTTP_USERNAME']
password = request.env['HTTP_PASSWORD']
rating_id = params[:rating_id]
bundle_id = params[:bundle_id]
response_id = params[:response_id]
Spaceship::Tunes.login(username, password)
app = Spaceship::Tunes::Application.find(bundle_id)
body app.ratings.deleteResponse(rating_id, response_id).to_json
end