module Tanita::Api::Client::HttpHelper

Public Instance Methods

generate_uri(path, params) click to toggle source
# File lib/tanita/api/client/helpers.rb, line 20
def generate_uri(path, params)
  uri = URI.parse("#{BASE_URL}#{path}?#{URI.encode_www_form(params)}")
  uri.to_s
end
parse_json(str) click to toggle source
# File lib/tanita/api/client/helpers.rb, line 35
def parse_json(str)
  JSON.parse(str, symbolize_names: true)
rescue JSON::ParserError => e
  raise Error.new("JSON::ParseError: '#{e}'\nstr:#{str}")
end
request(path, params) click to toggle source
# File lib/tanita/api/client/helpers.rb, line 25
def request(path, params)
  uri = URI.parse("#{BASE_URL}#{path}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  req = Net::HTTP::Post.new(uri.path)
  req.set_form_data(params)
  http.request(req)
end
time_format(time) click to toggle source
# File lib/tanita/api/client/helpers.rb, line 41
def time_format(time)
  time.strftime('%Y%m%d%H%M%S')
end