bskyrb 0.1.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/bskyrb.rb +64 -0
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c0758819808494d3dc4d546aad2318cc5b0f1b2c7b628cfb0e7dd583a8fc525b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d0747be2257ec6e78471c4ea5ed024461b177e9fa6a9ad0ae8a7f6ac5a2a08d7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3f5a8addc8279164556ced9de8b49b28527a0d5c6b956f10b0bd78fe5c1b864dcbfae0e3bdb4c41568e655a4289e3e2a56dc591021e86406e1481e73546929e5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4283bdb365aa3012f866066d8602c25a459e371586e87347d2f8188db7ad43c0b803d0d3d2e9c3034dd279db5831c1600796856767681cde1b715994210177e3
         
     | 
    
        data/lib/bskyrb.rb
    ADDED
    
    | 
         @@ -0,0 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # require_relative "bskyrb/version"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'net/http'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'date'
         
     | 
| 
      
 7 
     | 
    
         
            +
            module ATProto
         
     | 
| 
      
 8 
     | 
    
         
            +
              class Session
         
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize(username, password)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @atp_host = "https://bsky.social"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @atp_auth_token = ""
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @did = ""
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @username = username
         
     | 
| 
      
 14 
     | 
    
         
            +
              
         
     | 
| 
      
 15 
     | 
    
         
            +
                  data = { "identifier" => username, "password" => password }.to_json
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
                  uri = URI("#{@atp_host}/xrpc/com.atproto.server.createSession")
         
     | 
| 
      
 18 
     | 
    
         
            +
                  response = Net::HTTP.post(uri, data, 'Content-Type' => 'application/json')
         
     | 
| 
      
 19 
     | 
    
         
            +
              
         
     | 
| 
      
 20 
     | 
    
         
            +
                  parsed_response = JSON.parse(response.body)
         
     | 
| 
      
 21 
     | 
    
         
            +
              
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @atp_auth_token = parsed_response['accessJwt']
         
     | 
| 
      
 23 
     | 
    
         
            +
              
         
     | 
| 
      
 24 
     | 
    
         
            +
                  if @atp_auth_token.nil?
         
     | 
| 
      
 25 
     | 
    
         
            +
                    raise ValueError.new("No access token, is your password wrong?")
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
              
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @did = parsed_response['did']
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                def getdid()
         
     | 
| 
      
 31 
     | 
    
         
            +
                  puts @did
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
                
         
     | 
| 
      
 34 
     | 
    
         
            +
              def resolveHandle(username) # aka getDid
         
     | 
| 
      
 35 
     | 
    
         
            +
                headers = { "Authorization" => "Bearer #{@atp_auth_token}" }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                uri = URI("#{@atp_host}/xrpc/com.atproto.identity.resolveHandle?handle=#{username}")
         
     | 
| 
      
 38 
     | 
    
         
            +
                response = Net::HTTP.get(uri, headers)
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                return response
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
              def get_skoot_by_url(url)
         
     | 
| 
      
 43 
     | 
    
         
            +
                headers = { "Authorization" => "Bearer #{@atp_auth_token}" }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                username_of_person_in_link = url.split('/')[-3]
         
     | 
| 
      
 46 
     | 
    
         
            +
                did_of_person_in_link = JSON.parse(resolveHandle(username_of_person_in_link))['did']
         
     | 
| 
      
 47 
     | 
    
         
            +
                url_identifier = url.split('/')[-1]
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                uri = "at://#{did_of_person_in_link}/app.bsky.feed.post/#{url_identifier}"
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                response = Net::HTTP.get(URI("#{@atp_host}/xrpc/app.bsky.feed.getPostThread?uri=#{uri}"), headers)
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                return response
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              
         
     | 
| 
      
 57 
     | 
    
         
            +
            def method_missing(method_name, *args)
         
     | 
| 
      
 58 
     | 
    
         
            +
              message = "You called #{method_name} with #{args}. This method doesn't exist."
         
     | 
| 
      
 59 
     | 
    
         
            +
              
         
     | 
| 
      
 60 
     | 
    
         
            +
                  raise NoMethodError, message
         
     | 
| 
      
 61 
     | 
    
         
            +
              
         
     | 
| 
      
 62 
     | 
    
         
            +
            end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end 
         
     | 
| 
      
 64 
     | 
    
         
            +
            end 
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bskyrb
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Shreyan Jain
         
     | 
| 
         @@ -58,7 +58,8 @@ email: 
     | 
|
| 
       58 
58 
     | 
    
         
             
            executables: []
         
     | 
| 
       59 
59 
     | 
    
         
             
            extensions: []
         
     | 
| 
       60 
60 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       61 
     | 
    
         
            -
            files: 
     | 
| 
      
 61 
     | 
    
         
            +
            files:
         
     | 
| 
      
 62 
     | 
    
         
            +
            - lib/bskyrb.rb
         
     | 
| 
       62 
63 
     | 
    
         
             
            homepage: https://github.com/ShreyanJain9/bskyrb
         
     | 
| 
       63 
64 
     | 
    
         
             
            licenses:
         
     | 
| 
       64 
65 
     | 
    
         
             
            - MIT
         
     |