<commit_before>require "xively_api_client/version"

module XivelyApiClient
  # Your code goes here...
end<commit_msg>first draft of api client with main methods<commit_after>require "xively_api_client/version.rb"

module XivelyApiClient
  class Client
    attr_accessor :domain, :instance, :user, :pass

    def initialize args = {}
      @instance = args[:instance] || ENV['XIVELY_INSTANCE']
      @domain = args[:domain] || ENV['XIVELY_DOMAIN']
      @user = args[:user] || ENV['XIVELY_USER']
      @pass = args[:pass] || ENV['XIVELY_PASS']
    end

    def create_device serial_id, options = {}
      if serial_id
        response = post(create_device_json serial_id, options)
        JSON.parse(response.body)["devices"].first
      end
    end

    def devices
      begin
        response = HTTParty.get device_url, basic_auth: credentials
        JSON.parse(response.body)["devices"]
      rescue
        nil
      end
    end

    def delete serial
      HTTParty.delete device_url(serial),
                      :basic_auth => credentials
    end

    private

    def post body
      HTTParty.post device_url,
                    :body => body,
                    :basic_auth => credentials,
                    :headers => {'Content-Type' => 'application/json'}
    end

    def device_url serial = nil
      url = "https://v3api.xively.com/v3/service_instances/#{ instance }/domains/#{ domain }/devices"
      url += "/#{ serial }" if serial
      url
    end

    def credentials
      { username: @user, password: <PASSWORD> }
    end

    def create_device_json serial_id, options = {}
      queues = options[:queues] || []
      batch_id = options[:batch_id] || "2ndnozefwvbsi"
      { devices:
        [{ batch_id: batch_id,
          queues: queues.map { |q| { name: q, type: "message" } },
          serial: serial_id
        }]
      }.to_json
    end

  end
end
{'fraction_non_alphanumeric': 0.11258629845990441, 'fraction_numerical': 0.0015932023366967605, 'mean_word_length': 2.305263157894737, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '6505598', 'n_tokens_mistral': 590, 'n_tokens_neox': 571, 'n_words': 138}