-4

I am learning Ruby and need to wrap a third-party api with Ruby

API:    https://www.mysite.com/api
Parameters:
user_id     //a unique  token   to  identify user
user_info       //a JSON    array   of  items   with    user info

Results:
result_message  //success   or  failure message
group_id        //group number that user belongs to

I need to implement a method(A) which calls the api and needs the required parameters for the api and also array of users as input.

I am not sure how to implement the method. Any thoughts? Thanks.

Mark
  • 5,994
  • 5
  • 42
  • 55
Alex
  • 159
  • 14

1 Answers1

2

A good start can be: http://augustl.com/blog/2010/ruby_net_http_cheat_sheet/

require "net/https"
require "uri"

uri = URI.parse("http://yoururl.com/?id=#{user_id}&user_info=#{user_info}")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)
puts response.code
puts response.body

response.body contains all the information you want to get.

Hope it helps.

Mark
  • 5,994
  • 5
  • 42
  • 55