xampprocky / mammut Goto Github PK
View Code? Open in Web Editor NEWA wrapper for the Mastodon API in Rust.
License: Other
A wrapper for the Mastodon API in Rust.
License: Other
Problem: I need to depend on the dev version of this crate through github which is ugly. See https://github.com/klausi/mastodon-twitter-sync/blob/master/Cargo.toml
There have been some useful commits since 0.12, please release them.
Thanks!
So, I am going through and trying to fix Trumpet, and I was wondering about a few decisions made when you were updating trumpet. Mainly, the Page
struct. With the page struct, everything is now wrapped in multiple layers of structure. For example, Trumpet gets a list of accounts, the user chooses an account, and then we check if the user is already following them, then follow the user if not, printing a message otherwise. When now getting accounts, you have to navigate through a Page struct of accounts, check the options and results, and then get another page of accounts to check through. Why not return a Vec and let your users handle pagination? Is this an API change?
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> src/main.rs:17:28
|
17 | let mut registration = Registration::new("https://botsin.space")?;
| ------------------------------------------
| |
| the `?` operator cannot be applied to type `mammut::Registration`
| in this macro invocation
|
= help: the trait `std::ops::Try` is not implemented for `mammut::Registration`
= note: required by `std::ops::Try::into_result`
Error:
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> src/main.rs:17:28
|
17 | let mut registration = Registration::new("https://mastodon.social")?;
| ---------------------------------------------
| |
| the `?` operator cannot be applied to type `mammut::Registration`
| in this macro invocation
|
= help: the trait `std::ops::Try` is not implemented for `mammut::Registration`
= note: required by `std::ops::Try::into_result`
error: aborting due to previous error
Several days ago the description of "meta"
attribute was added to the documentation by TootSuite.
But in spite of the description, the API returns a JSON like this:
...
"meta": {
"original": {
"aspect": 0.75,
"height": 700,
"size": "525x700",
"width": 525
},
"small": {
"aspect": 0.75,
"height": 400,
"size": "300x400",
"width": 300
}
},
...
I counld't immidiately figure out the entities because I'm not familer with Ruby.
https://github.com/tootsuite/mastodon/blob/master/app/models/media_attachment.rb
For now, deserialization of Attachment
doesn't fail by lack of Attachment.meta
.
Using a &Path
or PathBuf
would allow me to refactor this code into much nicer:
https://github.com/klausi/mastodon-twitter-sync/blob/246284cf98561d4358d326d0f417a0556c36827c/src/post.rs#L24-L34
Serde(ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 })
is the full error.
Mastodon::get_home_timeline()
only returns one single Status
rather than Vec<Status>
. This seems to be the result of this part of the API being auto-generated.
Here is get_home_timeline in the docs: https://docs.rs/mammut/0.10.0/mammut/struct.Mastodon.html#method.get_home_timeline
Pleroma seems to be expecting different JSON than what Mammut sends. Here's the error sent:
Instance URL: https://pleroma.site
Could not autheticate with the Mastodon instance.
Check that you entered the url of an existing instance.
Http(
Error {
kind: Json(
Error("missing field `redirect_uri`", line: 1, column: 132)
),
url: None
}
)
Instance URL: https://
As reported in klausi/mastodon-twitter-sync#4 it is hard for users of Mammut to properly handle the error condition of a Mastodon instance being unreachable.
Filing this issue per suggestion by https://github.com/klausi.
Starting from the README I'm trying the following:
extern crate mammut;
extern crate toml;
use mammut::{Data, Mastodon, Registration};
use mammut::apps::{AppBuilder, Scope};
use std::io;
use std::fs::File;
use std::io::prelude::*;
fn main() {
let mastodon = match File::open("mastodon-twitter-sync.toml") {
Ok(f) => load_from_config(f),
Err(_) => register(),
};
let timeline = mastodon.get_home_timeline().unwrap();
println!("{:?}", timeline);
}
fn register() -> Mastodon {
let app = AppBuilder {
client_name: "mastodon-twitter-sync",
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
scopes: Scope::Read,
website: None,
};
let mut registration = Registration::new("https://mastodon.social");
registration.register(app).unwrap();;
let url = registration.authorise().unwrap();
println!("Click this link to authorize on Mastodon: {}", url);
println!("Paste the returned authorization code: ");
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let code = input.trim();
let mastodon = registration.create_access_token(code.to_string()).unwrap();
// Save app data for using on the next run.
let toml = toml::to_string(&*mastodon).unwrap();
let mut file = File::create("mastodon-twitter-sync.toml").unwrap();
file.write_all(toml.as_bytes()).unwrap();
mastodon
}
fn load_from_config(mut file: File) -> Mastodon {
let mut config = String::new();
file.read_to_string(&mut config).unwrap();
let data: Data = toml::from_str(&config).unwrap();
Mastodon::from_data(data)
}
Errors with:
Serde(ErrorImpl { code: Message("invalid type: map, expected a string"), line: 1, column: 2 })
So some types seem to be wrong, but which ones?
I get a bunch of serde errors with 0.8.0
like
|
2 | #[derive(Debug, Clone, Deserialize)]
| ^^^^^^^^^^^ the trait `serde::Deserialize<'_>` is not implemented for `chrono::DateTime<chrono::UTC>`
|
= note: required by `serde::de::SeqAccess::next_element
but the current version works fine. Do you think you could publish it?
Tootsuite has released version 2.4.0 which comes with new additions to the API.
I'm not sure if this is the best place to ask this question. If it's not, please redirect me to the appropriate place.
I'm trying to see if I can get an image attached to a post. Here is the relevant portion of my code:
let data: mammut::Data = serde_json::from_reader(deserialized)?;
let mastodon = Mastodon::from_data(data)?;
let mut image = File::open("hello-world.png")?;
let mut contents: Vec<u8> = Vec::new();
println!("read_to_end");
let read_bytes = image.read_to_end(&mut contents)?;
println!("{:?}", read_bytes);
println!("{:?}", mastodon);
println!("mastodon.media");
let attachment = mastodon.media(contents)?
Running this gives the following output:
read_to_end
2416
Mastodon { client: Client { redirect_policy: Mutex { data: RedirectPolicy { inner: Limit(10) } }, referer: AtomicBool(true), auto_ungzip: AtomicBool(true) }, headers: Headers { Authorization: Bearer redacted
, }, data: Data { base: "https://ephemeral.glitch.social", client_id: "redacted", client_secret: "redacted", redirect: "urn:ietf:wg:oauth:2.0:oob", token: "redacted" } }
mastodon.media
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Http(Error { kind: UrlEncoded(Custom("unsupported value")), url: None })', /checkout/src/libcore/result.rs:859
stack backtrace:
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::_print
at /checkout/src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at /checkout/src/libstd/sys_common/backtrace.rs:60
at /checkout/src/libstd/panicking.rs:355
3: std::panicking::default_hook
at /checkout/src/libstd/panicking.rs:371
4: std::panicking::rust_panic_with_hook
at /checkout/src/libstd/panicking.rs:549
5: std::panicking::begin_panic
at /checkout/src/libstd/panicking.rs:511
6: std::panicking::begin_panic_fmt
at /checkout/src/libstd/panicking.rs:495
7: rust_begin_unwind
at /checkout/src/libstd/panicking.rs:471
8: core::panicking::panic_fmt
at /checkout/src/libcore/panicking.rs:69
9: core::result::unwrap_failed
at /checkout/src/libcore/macros.rs:29
10: <core::result::Result<T, E>>::unwrap
at /checkout/src/libcore/result.rs:737
11: xumbot::main
at ./src/main.rs:19
12: __rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:98
13: std::rt::lang_start
at /checkout/src/libstd/panicking.rs:433
at /checkout/src/libstd/panic.rs:361
at /checkout/src/libstd/rt.rs:57
14: main
15: __libc_start_main
16: _start
I think this error has something to do with the macros mammut
uses to handle REST calls, but I'm not quite sure how to figure out what specifically is wrong.
I was able to use the API to post a status with only text, and according to the output I am able to load the contents of my image into a Vec<u8>
. But my code fails when let attachment = mastodon.media(contents)?
is executed.
Am I using the API incorrectly? Is there something else I'm missing?
Hi,
Debian Unstable ships with OpenSSL 1.1.1 and the reqwest
dependency in Mammut relies on the version 0.9.24 of the openssl crate which does not support OpenSSL 1.1.1.
in particular compilation fails with this message:
error: failed to run custom build command for `openssl v0.9.24`
process didn't exit successfully: `/home/ao2/WIP/mastodon/mastodon-twitter-sync/Mammut/target/debug/build/openssl-3a8db21765a1c7e0/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Unable to detect OpenSSL version', /home/ao2/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/build.rs:16:14
note: Run with `RUST_BACKTRACE=1` for a backtrace.
warning: build failed, waiting for other jobs to finish...
error: build failed
Updating to reqwest = "0.9"
would fix the openssl issue but it looks like the API has changed and the code needs some updates too:
Compiling mammut v0.11.0 (file:///home/ao2/WIP/mastodon/mastodon-twitter-sync/Mammut)
error[E0432]: unresolved imports `reqwest::header::Link`, `reqwest::header::RelationType`
--> src/page.rs:3:23
|
3 | use reqwest::header::{Link, RelationType};
| ^^^^ ^^^^^^^^^^^^ no `RelationType` in `header`
| |
| no `Link` in `header`
error[E0432]: unresolved imports `reqwest::header::Authorization`, `reqwest::header::Bearer`, `reqwest::header::Headers`
--> src/lib.rs:66:23
|
66 | use reqwest::header::{Authorization, Bearer, Headers};
| ^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^ no `Headers` in `header`
| | |
| | no `Bearer` in `header`
| no `Authorization` in `header`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0432`.
error: Could not compile `mammut`.
To learn more, run the command again with --verbose.
I'll try looking into it, but feel free to anticipate me ๐.
Thanks,
Antonio
BTW the issue arose when compiling https://github.com/klausi/mastodon-twitter-sync
The upload photo example does not work with the mastodon.social server:
$ cargo run --example upload_photo
Compiling mammut v0.12.0 (/home/klausi/workspace/Mammut)
Finished dev [unoptimized + debuginfo] target(s) in 3.53s
Running `target/debug/examples/upload_photo`
Enter the path to the photo you'd like to post:
test.jpg
Error: Api(ApiError { error: None, error_description: None })
The response from the Mastodon server is:
{
"id": "14765098",
"type": "unknown",
"url": "https://mastodon.social/files/original/missing.png",
"preview_url": "https://mastodon.social/files/small/missing.png",
"remote_url": null,
"text_url": "https://mastodon.social/media/_X2BWQQcaR_gAi5SfYU",
"meta": null,
"description": null,
"blurhash": null
}
Why does the server return an unknown type?
How do we tell the server that this is just a JPG image it should accept?
Attempting to post a simple status that looks like this:
StatusBuilder {
status: "look carefully ahead",
in_reply_to_id: None,
media_ids: None,
sensitive: None,
spoiler_text: None,
visibility: None
}
using
post = mastodon.new_status(status);
yields an
Err(Http(Serialize(Custom("unsupported value"))))
(gonna delete this afterwards, didn't know how to contact you otherwise)
It looks like there's a list entity, but no implementation.
Is this being worked on?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.