-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynup_api.rb
More file actions
46 lines (37 loc) · 1.46 KB
/
synup_api.rb
File metadata and controls
46 lines (37 loc) · 1.46 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
require 'json'
require 'rest-client'
require 'telegram_bot'
TELEGRAM_TOKEN = '135203734:AAEO7AIYWR7z9sjaxyG-93hZLxb_IMWjZX4'
url = "http://localhost:3000/"
env = url + "api/v1/businesses/"
data = {"user[email]" => "customer1@synup.com","user[password]" => "customer123"}
res = RestClient.post url + 'users/sign_in.json', data
parseresponse = JSON.parse(res)
token = parseresponse["auth_token"]
# newres = RestClient.get newlocation,:params => {:auth_token => token,:user_email => "admin@synup.com"}
locations_json = RestClient.get url + 'api/v1/businesses.json', params: {auth_token: token, user_email: 'customer1@synup.com'}
locations = JSON.parse(locations_json)
location_count = locations['result'].size.inspect
synup_bot = TelegramBot.new(token: TELEGRAM_TOKEN)
puts synup_bot.inspect
synup_bot.get_updates(fail_silently: true) do |message|
puts "@#{message.from.username}: #{message.text}"
command = message.get_command_for(synup_bot)
message.reply do |reply|
case command
when /locationcount/
reply.text = "customer1@synup.com, you have #{location_count} locations on Synup."
when /listings/
when /reviews/
puts "command entered = #{command}"
else
reply.text = "#{message.from.first_name}, have no idea what #{command.inspect} means."
end
puts "sending #{reply.text.inspect} to @#{message.from.username}"
reply.send_with(synup_bot)
end
end
def get_reviews_by_site(loc_id, site)
end
def get_listing_details(loc_id)
end