lib/sched/client.rb in sched-0.1.8 vs lib/sched/client.rb in sched-0.1.9
- old
+ new
@@ -30,33 +30,38 @@
end
end
private
+ def byte_order_mark
+ "\xEF\xBB\xBF".force_encoding("UTF-8")
+ end
+
def curl_client(path)
c = Curl::Easy.new("#{api_url}/#{path}")
c.headers["User-Agent"] = "sched-gem"
c
end
+ def encoded(str)
+ str.force_encoding("UTF-8").gsub(byte_order_mark, "")
+ end
+
def full_url(path)
"#{api_url}/#{path}"
end
def get_request(path, data)
get_attributes = data.map { |key, value| "#{key}=#{value}" }.join("&")
c = curl_client("#{path}?#{get_attributes}")
c.perform
- c.body_str
+ encoded(c.body_str)
end
def parse_attributes(attributes)
attributes.map do |a|
- a.force_encoding("UTF-8")
- .strip.gsub(/[\u0080-\u00ff]/, "")
- .gsub(/^event_/, "session_")
- .to_sym
+ a.gsub(/^event_/, "session_").to_sym
end
end
def parse_sessions(results)
attributes = parse_attributes(results.shift)
@@ -73,9 +78,9 @@
post_fields = data.map do |key, value|
Curl::PostField.content(key.to_s, value)
end
c = curl_client(path)
c.http_post(post_fields)
- c.body_str
+ encoded(c.body_str)
end
end
end