Module: Tanita::Api::Client::HttpHelper
- Included in:
- Auth, BaseApiClient
- Defined in:
- lib/tanita/api/client/helpers.rb
Instance Method Summary collapse
- #generate_uri(path, params) ⇒ Object
- #parse_json(str) ⇒ Object
- #request(path, params) ⇒ Object
- #time_format(time) ⇒ Object
Instance Method Details
#generate_uri(path, params) ⇒ Object
20 21 22 23 |
# 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) ⇒ Object
35 36 37 38 39 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/tanita/api/client/helpers.rb', line 41 def time_format(time) time.strftime('%Y%m%d%H%M%S') end |