-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.rb
134 lines (111 loc) · 2.76 KB
/
proxy.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require 'sinatra'
require 'sinatra/cross_origin'
require 'sinatra/activerecord'
require './config/environments'
require './cors'
require './models/item'
require './models/message'
require 'net/http'
# start with bundle exec rackup -p 4567
def allow_json
cross_origin
content_type 'application/json', :charset => 'utf-8'
end
get "/" do
"hello world"
end
get "/amway_events/:year/:month" do
allow_json
uri = URI::HTTP.build(
:host => "www.amwaycenter.com",
:path => "/events/calendar/#{params[:year]}/#{params[:month]}"
)
response = Net::HTTP.get(uri)
response
# returns array of event objects {Title, StartDateTime, EndDateTime}
end
get "/json_padding_demo" do
content_type 'application/javascript', :charset => 'utf-8'
"#{params['callback']}({ \"data\": { \"month\": \"August\",
\"day\": 23,
\"year\": 1974 } })"
end
get "/darksky/*" do
allow_json
uri = URI("https://api.darksky.net/#{params['splat'][0]}")
response = Net::HTTP.get uri
response
end
get "/trivia" do
allow_json
uri = URI("http://trivia.propernerd.com/api/questions?#{request.query_string}")
puts uri.inspect
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri)
puts request.inspect
user = '2298623c5e504c94828de0519d5ae973e8289f36'
password = '504ffbd0aa78df6107f428078dfbc1f976ae026b'
request.basic_auth user, password
#response = Net::HTTP.start(uri.hostname, uri.port) do |http|
response = http.request(request)
#end
puts response.inspect
response.body
end
get "/disney/*" do
allow_json
uri = URI("https://touringplans.com/#{params['splat'][0]}")
response = Net::HTTP.get uri
response
end
get "/conshus-map" do
allow_json
uri = URI("https://maps.googleapis.com/maps/api/distancematrix/json?#{request.query_string}")
response = Net::HTTP.get uri
end
get "/eventful" do
allow_json
uri = URI("http://api.eventful.com/json/events/search?#{request.query_string}")
response = Net::HTTP.get uri
end
post "/items" do
allow_json
@item = Item.new(params[:item])
if @item.save
@item.to_json
else
{ failure: true }.to_json
end
end
get "/items" do
allow_json
items = Item.all
{ items: items }.to_json
end
get "/items/:id" do
allow_json
item = Item.find(params[:id])
item.to_json
end
delete "/items/:id" do
allow_json
item = Item.find(params[:id])
item.destroy
item.to_json
end
get "/messages" do
allow_json
messages = Message.all
{ messages: messages }.to_json
end
post "/messages" do
allow_json
message = Message.create(params[:message])
{ message: message }.to_json
end
delete "/messages/:id" do
allow_json
message = Message.find(params[:id])
message.destroy
{ message: message }.to_json
end