Sha256: 8a56c327117a3096b4eae671db6790035a3f3fa95e316c2df19ffba0ca49905b
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
require 'uuid' require 'httparty' module Msewage::Importer class API def initialize(config = Config.new) @config = config end def insert(record) res = HTTParty.put(new_source_url, body: new_source_body(record)) !res["code"].nil? print "." end private def new_source_url "#{api_endpoint}/sources/#{source_uid}?clientuid=#{client_uid}" end def new_source_body(record) { created_by: user_name, desc: record["desc"] || record["description"], latitude: record["latitude"], longitude: record["longitude"], name: record["name"], source_type: record["source_type"] } end def client_uid @client_uid ||= retrieve_client_uid end def retrieve_client_uid body = { password: password } path = "#{api_endpoint}/users/#{user_name}" res = HTTParty.post(path, body: body) res["clientuid"] end attr_reader :config def source_uid UUID.generate.gsub(/-/, '') #"0" * 16 end def user_name config.msewage.username end def password config.msewage.password end def api_endpoint config.api_endpoint end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
msewage-importer-0.0.2 | lib/msewage-importer/api.rb |
msewage-importer-0.0.1 | lib/msewage-importer/api.rb |