-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
56 lines (48 loc) · 1.22 KB
/
server.rb
File metadata and controls
56 lines (48 loc) · 1.22 KB
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
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'httparty'
class App < Sinatra::Base
set :apikey, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
set :courier, 'jne'
set :format, 'json'
get '/' do
'Ongkir.info through sinatra application'
end
get '/city' do
content_type :json
params = request.env['rack.request.query_hash']
query = params['query']
type = params['type']
url = 'http://api.ongkir.info/city/list'
options = { :body => {
"query" => query,
"type" => type,
"courier" => settings.courier,
"API-Key" => settings.apikey,
"format" => settings.format
}
}
response = HTTParty.post(url, options)
response.body
end
get '/cost' do
content_type :json
params = request.env['rack.request.query_hash']
from = params['from']
to = params['to']
weight = params['weight']
url = 'http://api.ongkir.info/cost/find'
options = { :body => {
"from" => from,
"to" => to,
"weight" => weight,
"courier" => settings.courier,
"API-Key" => settings.apikey,
"format" => settings.format
}
}
response = HTTParty.post(url, options)
response.body
end
end