dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

ourhome.rb (1520B)


      1 #!/usr/bin/env ruby
      2 require 'net/http'
      3 require 'uri'
      4 require 'json'
      5 
      6 %w[OURHOME_CLIENT_ID OURHOME_USER OURHOME_PASS].each do |env_var|
      7   abort "#{env_var} not set in environment" unless ENV.key? env_var
      8 end
      9 
     10 client_header = "ClientID: #{ENV['OURHOME_CLIENT_ID']}"
     11 user = ENV['OURHOME_USER']
     12 pass = ENV['OURHOME_PASS']
     13 headers = {
     14   'AUTHORIZATION' => client_header,
     15   'Content-Type' => 'application/json',
     16   'Origin' => 'https://app.ourhomeapp.com',
     17   'Referer' => 'https://app.ourhomeapp.com/',
     18   'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
     19   'X-AUTHORIZATION' => client_header,
     20   'X-CSRFToken' => '{{csrf_token}}'
     21 }
     22 
     23 uri = URI 'https://api.ourhomeapp.com'
     24 https = Net::HTTP.new(uri.host, uri.port)
     25 https.use_ssl = true
     26 
     27 data = { email: user, password: pass }
     28 resp = https.post('/api/v1/users/login/', data.to_json, headers)
     29 
     30 abort 'Request error' if resp.code_type != Net::HTTPOK
     31 
     32 cookie = resp['set-cookie']
     33 body = JSON.parse resp.body
     34 me = body['id']
     35 headers['Cookie'] = cookie
     36 
     37 uri.path = '/api/v1/tasks/'
     38 query = { is_active: true, sorting: true, user_id: body['id'], is_event: false, list: 'T' }
     39 uri.query = URI.encode_www_form(query)
     40 resp2 = https.get(uri, headers)
     41 body = JSON.parse resp2.body
     42 my_tasks = (body['objects']
     43   .select { _1['currently_assigned_user'] =~ %r{/#{me}/} && _1['list'] == 'T' }
     44   .map { _1.select { |k, _v| %w[description scheduled_due_date point_value].include? k } })
     45 
     46 print my_tasks.to_json