0

I'm having trouble getting parameters passed in an HTTP Put call, using ruby. Take a look at the "put_data" variable. When I leave it as a hash, ruby says:

undefined method `bytesize' for #<Hash:0x007fbf41a109e8>

if I convert to a string, I get:

can't convert Net::HTTPUnauthorized into String

I've also tried doing just - '?token=wBsB16NSrfVDpZPoEpM'

   def process_activation
      uri = URI("http://localhost:3000/api/v1/activation/" + self.member_card_num)
      Net::HTTP.start(uri.host, uri.port) do |http|
        headers = {'Content-Type' => 'text/plain; charset=utf-8'}
        put_data = {:token => "wBsB16NSrfVDpZPoEpM"}
        response = http.send_request('PUT', uri.request_uri, put_data,  headers)
        result = JSON.parse(response)
      end
      if result['card']['state']['state'] == "active"
        return true
      else
        return false
      end 
    end

I've searched all around, including rubydocs, but can't find an example of how to encode parameters. Any help would be appreciated.

tpow
  • 7,600
  • 11
  • 59
  • 84

1 Answers1

0

Don't waste your time with NET::HTTP. I used 'rest-client' and had this thing done in minutes...

       def process_activation
          response = RestClient.put 'http://localhost:3000/api/v1/card_activation/'+ self.member_card_num, :token => "wBsB1pjJNNfiK6NSrfVDpZPoEpM"
          result = JSON.parse(response)
          return result['card']['state']['state'] == "active"
        end
tpow
  • 7,600
  • 11
  • 59
  • 84