lib/irkit/device.rb in irkit-0.0.9 vs lib/irkit/device.rb in irkit-0.1.0
- old
+ new
@@ -14,11 +14,11 @@
def to_s
%Q{#<#{self.class} @address="#{@address}" @bonjour_name="#{@bonjour_name}">}
end
def get_messages
- res = HTTParty.get("#{url}/messages")
+ res = HTTParty.get("#{url}/messages", headers: headers)
case res.code
when 200
return nil if res.body.length < 1
return IRKit::Response.new JSON.parse res.body
else
@@ -26,17 +26,18 @@
end
end
def post_messages(data)
opts = {
- :body => data.to_json
+ :body => data.to_json,
+ :headers => headers
}
HTTParty.post "#{url}/messages", opts
end
def get_token
- res = HTTParty.post "#{url}/keys", {}
+ res = HTTParty.post "#{url}/keys", {headers: headers}
case res.code
when 200
return JSON.parse(res.body)["clienttoken"]
else
raise IRKit::Error, res.body
@@ -57,7 +58,12 @@
else
raise IRKit::Error, res.body
end
end
+ private
+
+ def headers
+ {"X-Requested-With" => "ruby-irkit"}
+ end
end
end