Giter VIP home page Giter VIP logo

mammut's Introduction

Mammut. A API Wrapper for the Mastodon API.

This project is no longer maintained. For a more updated version see elefren.

crates.io Docs MIT/APACHE-2.0

mammut's People

Contributors

aaronepower avatar autumnontape avatar bvtsang avatar carlschwan avatar carols10cents avatar gagath avatar hueftl avatar inux39 avatar jhaye avatar klausi avatar qryxip avatar thebestjohn avatar xampprocky 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  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  avatar  avatar  avatar  avatar  avatar

mammut's Issues

Crates.io version fails to build

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?

Serde error when calling get_home_timeline()

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?

Example is broken: `std::ops::Try` is not implemented for `mammut::Registration`

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`

Posting a status yields a Http/Serialize error

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"))))

Add Attachment::Meta

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.

Update the dependency on reqwest

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

Cannot Authenticate With Pleroma Instances

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://

Example in README does not compile

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

media call results in Http(Error { kind: UrlEncoded(Custom("unsupported value")), url: None })

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?

Questions Regarding Account Struct

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?

Add lists support

It looks like there's a list entity, but no implementation.
Is this being worked on?

Uploading image attachments is broken

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?

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.