<commit_before>require "jetsetmeapi/version"
require 'httparty'
require 'json'

module Jetsetmeapi

  AUTHPATH="https://api.jetsetme.com/authentication/request_token"
  CONFIRMPATH="https://api.jetsetme.com/authentication/confirm_token"
  DEVID=ENV["DEVID"]
  APPID=ENV["APPID"]
  HEADERS = {"X-DEVID" => DEVID, "X-APPID" => APPID, "Content-type" => "application/json"}

  def self.get_auth_token(msisdn)
    if load_parameters
      response = HTTParty.post(AUTHPATH, :headers => HEADERS, :body => {:msisdn => msisdn}.to_json)
      token = JSON.parse(response)["token"]
      error = JSON.parse(response)["error"] unless nil
      unless token == nil
        return token
      else
        return {:error => error}
      end
    else
      return {:error => "ERROR not all ENV variables found"}
    end
  end

  def self.get_auth_key(pin, token)
    if load_parameters
      response = HTTParty.post(CONFIRMPATH, :headers => HEADERS, :body => {:pin => pin, :token => token}.to_json)
      key = JSON.parse(response)["auth_key"]
    else
      return {:error => "ERROR not all ENV variables found"}
    end
  end

protected

  def self.load_parameters
    if DEVID || APPID == nil
      return false
    else<commit_msg>updated check for dev and app id<commit_after>require "jetsetmeapi/version"
require 'httparty'
require 'json'

module Jetsetmeapi

  AUTHPATH="https://api.jetsetme.com/authentication/request_token"
  CONFIRMPATH="https://api.jetsetme.com/authentication/confirm_token"
  DEVID=ENV["DEVID"]
  APPID=ENV["APPID"]
  HEADERS = {"X-DEVID" => DEVID, "X-APPID" => APPID, "Content-type" => "application/json"}

  def self.get_auth_token(msisdn)
    if load_parameters
      response = HTTParty.post(AUTHPATH, :headers => HEADERS, :body => {:msisdn => msisdn}.to_json)
      token = JSON.parse(response)["token"]
      error = JSON.parse(response)["error"] unless nil
      unless token == nil
        return token
      else
        return {:error => error}
      end
    else
      return {:error => "ERROR not all ENV variables found"}
    end
  end

  def self.get_auth_key(pin, token)
    if load_parameters
      response = HTTParty.post(CONFIRMPATH, :headers => HEADERS, :body => {:pin => pin, :token => token}.to_json)
      key = JSON.parse(response)["auth_key"]
    else
      return {:error => "ERROR not all ENV variables found"}
    end
  end

protected

  def self.load_parameters
    if DEVID && APPID
{'fraction_non_alphanumeric': 0.13097199341021418, 'fraction_numerical': 0.0, 'mean_word_length': 3.368705035971223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959650', 'n_tokens_mistral': 822, 'n_tokens_neox': 791, 'n_words': 189}