Code Monkey home page Code Monkey logo

bskyrb's Introduction

Bskyrb

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add bskyrb

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install bskyrb

You can also install the gem by cloning this repository and running ./install-local.sh.

Usage

Create a new session:

require 'bskyrb'
username = 'your_username'
password = 'your_password'
pds_url = 'https://bsky.social'

credentials = Bskyrb::Credentials.new(username, password)
session = Bskyrb::Session.new(credentials, pds_url)
bsky = Bskyrb::RecordManager.new(session)
post_uri = bsky.create_post("Hello world from bskyrb!")["uri"]
bsky.like(post_uri)
bsky.repost(post_uri)
bsky.create_reply(post_uri, "Replying to post from bskyrb")

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, run ./deploy.sh and you will be guided through updating the version number, bundling the gem, and pushing it to RubyGems. You must be signed in with a RubyGems account that has push access to bskyrb.

And configure the type checker:

Code generation

We are working on a script to generate classes from the atproto lexicon. So far we have made non-query objects. To recreate them:

git submodule add https://github.com/bluesky-social/atproto.git
# or just clone it!
bin/codegen

This crawls the lexicon directory in your newly-cloned atproto repo, and generates formatted classes based on the json schemas embedded in the files. You can then hydrate them like so:

# make your RecordManager, then...

post_by_url = manager.get_post_by_url("https://staging.bsky.app/profile/naia.bsky.social/post/3jszsrnruws27")

my_post = Bskyrb::AppBskyFeedDefs::PostView.from_hash post_by_url["thread"]["post"]

=>
#<Bskyrb::AppBskyFeedDefs::PostView:0x000000010432a0a0
 @author=
  {"did"=>"did:plc:scx5mrfxxrqlfzkjcpbt3xfr",
   "handle"=>"naia.bsky.social",
   "displayName"=>"naia",
   "avatar"=>
    "https://cdn.bsky.social/imgproxy/0uv5pCOimHKw44PfnCt5_XpnOICHz1KeHCl8dknI_ZY/rs:fill:1000:1000:1:0/plain/bafkreibabes4xznjzdwxqj4hzirg7lofhl2detvabroibakewssfkr
      "alt"=>""}]},
 @indexedAt="2023-04-10T16:51:21.391Z",
 @labels=[],
 @likeCount=27,
 @record=
  {"text"=>"gm from the new deck chair i built yesterday\n\nthe sky is very blue",
   "$type"=>"app.bsky.feed.post",
   "embed"=>
    {"$type"=>"app.bsky.embed.images",
     "images"=>
      [{"alt"=>"",
        "image"=>{"$type"=>"blob", "ref"=>{"$link"=>"bafkreif52k6kev6xgy2ydptub5oryss3gsscajrec6zh5r2els4si2yj7i"}, "mimeType"=>"image/jpeg", "size"=>796921}}]},
   "createdAt"=>"2023-04-10T16:51:21.049Z"},
 @replyCount=4,
 @repostCount=2,
 @uri="at://did:plc:scx5mrfxxrqlfzkjcpbt3xfr/app.bsky.feed.post/3jszsrnruws27",
 @viewer={}>

Next steps:

  • Recursion--hydrate the classes embedded in the classes. Some parsing to enable this already happens in LexiconParser.
  • Generate classes for queries and other unusual object types.
  • Integrate our new classes into the API call methods.

Type checking

bskyrb uses .rbs type definitions. To check for accuracy, run bin/typecheck. Not all of the output will be useful, especially during rapid development, but it is a good idea to have types at least for the bluesky objects.

Use the rbs collection tool to manage definitions for third-party dependencies, for example HTTParty. Use bundle exec rbs collection install to download third-party definitions (you will need to do this before bin/typecheck will work).

Tests

Run the test suite with:

$ bundle exec rake test

Formatting

So nobody has to argue about formatting, bskyrb uses the standard gem. Run bin/format to format the code in this repo.

Contributing

Please do!

TODO

  • Build
  • More/better tests
  • (Eventually) Publish/release pipeline
  • Split into separate modules for XRPC, Lexicon, ATProto, etc

Contributors

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Bskyrb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

bskyrb's People

Contributors

bungoman avatar shreyanjain9 avatar thearchduke avatar tmtm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bskyrb's Issues

Links don't seem to be clickable

I've been trying to write an autoposter that just posts "#{title} - #{link}" style posts from a blog, and I absolutely cannot get clickable links to be posted.

As far as I can tell, the link_pattern in the detect_facets method isn't working. I did some tests in local code with a much simpler regex pattern and your function, and this seems to be getting the right response. Unfortunately, I can't for the life of me figure out how to get this code into a local copy of the library that my autoposter will actually work with, because I am apparently hopelessly confused by Ruby's dependency management or how to build this specific gem or something. (I used your provided install-local.sh script with my change to the gem, but no matter what I do I get a uninitialized constant Bskyrb::Credentials (NameError) unless I load from the published Gem, which works flawlessly, except that the facets aren't being processed correctly and the links aren't clickable.)

This is the simple dumb pattern I used and the test. It basically just assumes anything that starts with https:// or http:// is a URL up until the next whitespace character. The only change to the enum_for.each loop is in the URI.parse, where I removed the trailing / (if one exists it will be grabbed by the regex).

text = 'New post: "Foobar" https://mywebsite.net/foo-bar/ and also https://other.com/thing and so on'
link_pattern = /(https?):\/\/(\S+)/

facets = []

text.enum_for(:scan, link_pattern).each do |m|
  index_start = Regexp.last_match.offset(0).first
  index_end = Regexp.last_match.offset(0).last
  m.compact!
  path = "#{m[1]}#{m[2..].join("")}".strip
  facets.push(
    "$type" => "app.bsky.richtext.facet",
    "index" => {
      "byteStart" => index_start,
      "byteEnd" => index_end,
    },
    "features" => [
      {
        "uri" => URI.parse("#{m[0]}://#{path}").normalize.to_s, # this is the matched link
        "$type" => "app.bsky.richtext.facet#link",
      },
    ],
  )
end

puts facets.inspect

Mentions in posts

Just leaving this up here. I'll probably try to figure this out tomorrow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.