Despite it being relatively simple, my brain can't comprehend new concepts all that easily so here I am.
I am using HTTParty to interact with the Microsoft Azure API. Here's an example of how their GET should look:
GET https://api.datamarket.azure.com/data.ashx/amla/text-analytics/v1/GetSentiment?Text=hello+world
Here's the headers they ask to be included:
Authorization: Basic <creds>
Accept: application/json
Where <creds> = ConvertToBase64(“AccountKey:” + yourActualAccountKey);
Here's my HTTParty class:
def self.sentiment(phrase)
require 'base64'
key = "MYKEYWASHERE"
accountKey = Base64.encode64("AccountKey:" + key)
response = get("https://api.datamarket.azure.com/data.ashx/amla/text-analytics/v1/GetSentiment?Text=hello+world", :headers => { "Authorization" => "Basic " + accountKey, "Accept" => "application/json"})
if response
return response
end
end
It responds with:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Bad Request - Invalid Header</h2> <hr><p>HTTP Error 400. The request has an invalid header name.</p> </BODY></HTML>
I also debugged it and it printed out the following:
opening connection to api.datamarket.azure.com:443...
opened
starting SSL for api.datamarket.azure.com:443...
SSL established
<- "GET /data.ashx/amla/text-analytics/v1/GetSentiment?Text=hello+world HTTP/1.1\r\nAuthorization: Basic QWNj(...)VREUmk1aWdudXRtL2VN\nak(...)R\r\nAccept: application/json\r\nConnection: close\r\nHost: api.datamarket.azure.com\r\n\r\n"
Anything obvious that I am doing wrong here?