GithubHelp home page GithubHelp logo

mastodonkit / mastodonkit Goto Github PK

View Code? Open in Web Editor NEW
251.0 11.0 58.0 2.13 MB

MastodonKit is a Swift Framework that wraps Mastodon's API

Home Page: https://mastodonkit.github.io/MastodonKit/

License: MIT License

Swift 99.52% Ruby 0.48%
swift mastodon wrapper api mastodon-api swift-framework swift-library mastodon-app swift-package mastodon-apis

mastodonkit's Introduction

MastodonKit

Build Status Code Coverage SwiftPM Compatible SwiftPM Version CocoaPods

MastodonKit is a Swift Framework built using Swift Package Manager that wraps the Mastodon API. It covers all the endpoints and entities from Mastodon's API and is designed to be simple to use.

Visit MastodonKit's Complete Documentation for examples and descriptions of all the methods available. These are some of the examples of what you'll find there:

By the way, if you want to get in touch with me, toot me.

Contributors

License

Copyright (c) 2017 Ornithologist Coder. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mastodonkit's People

Contributors

343max avatar calvcoll avatar frankrausch avatar lickel avatar marcelvoss avatar ornithocoder avatar otaviocc avatar sbeitzel avatar tonyarnold avatar vhbit 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  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  avatar  avatar  avatar

mastodonkit's Issues

No application object is returned on client!.run(request)

import Cocoa
import MastodonKit

class ViewController: NSViewController {
    var client : Client? = nil;
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let credentials = LoadCredentials();
        if credentials == nil {
            let baseURL = getBaseURLFromUser();
            self.client = Client(baseURL: baseURL);
            let request = Clients.register(clientName: "MastoViewer", scopes: [.read]);
            
            client!.run(request) {
                application, error in
                if let application = application {
                    print("id: \(application.id)")
                    print("redirect uri: \(application.redirectURI)")
                    print("client id: \(application.clientID)")
                    print("client secret: \(application.clientSecret)")
                }
                else {
                    print("error: \(String(describing: error))");
                }
            }
        }
        else{
            self.client = Client(baseURL: credentials!.baseURL!, accessToken: credentials!.accessToken)
        }
        // Do any additional setup after loading the view.
    }
    
    func LoadCredentials() -> CredentialsModel? {
        return nil
    }
    
    func getBaseURLFromUser() -> String {
        return "https://mastodon.technology";
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }
    
    


}

returns "error: nil" in the debug console.
Which means that application and error are nil.
I am expecting at least application to be something other than nil.

MastodonKit Dead

I'm in the process of building a client, and before I get too invested in this SDK, I want to know if this SDK is dead or what? It has a good foundation, but if it's dead, it's not worth using. Can we get an update on this?

Statuses.create doesn't URL-encode properly

If I create a new status using Statuses.create(status: "something with a ; in it", ...), the semi-colon does not get encoded properly during the POST, and ends up truncating the status text.

Clarification regarding Client reuse

Hello, thanks for working in this great library!

I have a question: How am I supposed to reuse Client objects? Should I always re-register them upon every launch? Because I use a separate instance of Client after receiving my OAuth token, and I keep getting an error when trying to use it: failure = mastodonError (mastodonError = "The access token is invalid")

When inspecting the urlRequest object, it seems to be correctly setup:

p urlRequest.allHTTPHeaderFields
([String : String]?) $R18 = 1 key/value pair {
  [0] = (key = "Authorization", value = "Bearer 022cb98b7732...[redacted]")
}

Any ideas of what could be wrong? Thanks again!

The Swift 5.1 FoundationNetworking move breaks MastodonKit

Swift 5.1 moved all of Foundation's networking-related code to a separate module, which you have to include separately with import FoundationNetworking. (This may be a Linux-specific thing, I'm not sure.)

I've made a pull request for this at #61, would you mind taking a look at it?

Implement NSObject/NSCoding for Models

Unfortunately currently this does not support NSObject/NSCoding protocols, and hence saving these objects easily to disk is unavailable. (For example caching objects locally easily with NSKeyedArchiver/NSKeyedUnarchiver).

If you could add support this would be great! c:

Change URLs from String to URL

Make sure header missing image's URL is assembled using the instance baseURL (because default image for header is a relative path).

Json parsing of ClientApplication fails in registration request

I'm working with MastodonKit on macOS and ran into an issue while reading the JSONDictionary in ClientApplication. The ClientApplication constructor fails when trying to read the id property from the response, resulting in no application parameter being passed to the callback (incidentally, there's also no error, making this hard to find).

By playing around with lldb I've been able to narrow this down to the way the id is parsed into an Int. Here's my fun with lldb that highlights the problem (in Swift 4.0 and 4.1).

(lldb) po (jsonObject as! JSONDictionary)["id"] as? Int
nil

(lldb) po (jsonObject as! JSONDictionary)["id"] as? String
▿ Optional<String>
  - some : "203483"

(lldb) po Int(((jsonObject as! JSONDictionary)["id"] as? String)!)
▿ Optional<Int>
  - some : 203483

It looks like the fix is to update the ClientApplication constructor to parse the id as a string then convert it to an int. I'll look at getting the project locally to submit a PR for this in the morning.

Link to documentation in README

It would be nice for new comers to have link to full documentation in Readme, right now it's impossible to discover it, which renders it useless.

“Notification” name collides with system (NS)Notification

The name Notification, formerly known as NSNotification, is used in Foundation:
https://developer.apple.com/documentation/foundation/notification

This collides with the Mastodon Notifications.

I only noticed this when trying to access the userInfo on the built-in iOS Notification and saw that MastodonKit overrides it.

I guess it is a philosophical question what to do about this. The Swift-style prefix-less way you use is of course more elegant—until it collides with system frameworks. 😅

Merge efforts from forks?

My fork is in turn based on another fork from almost four years ago. I wonder how realistic it would be to reconcile those changes, and how much interest there is.

I also don't know the status in terms of usage. Mastonaut uses it on the Mac (hence my fork), but are there, for example, any iOS apps that do? Do they all roll their own API client?

Media Upload

Because a media file is worth a thousand words.

Request Parsing failure.

The request parsing seems to fail on certain areas, not sure if all as I haven't completely implemented my client, such as Statuses being parsed correctly through Timelines and Notifications, and Clients.register.

It seems to fail on the array.flatMap(Status.init), although this never seemed a problem before and worked correctly, I guess a recent API change from Mastodon could be to blame, hence breaking parsing?

For example here is a basic return from my debugging, showing there are 20 statuses being returned, however the flatMap produces none.

array	[JSONDictionary]	20 values	
(json as? [JSONDictionary])	[JSONDictionary]?	20 values	some
print((json as [JSONDictionary])[0] as? [String: Any])	()	
array.flatMap(Status.init)	[MastodonKit.Status]	0 values	

The print statement works correctly printing out the values as shown

Optional(["sensitive": 0, "emojis": <__NSArray0 0x60000000ecc0>(

)
, "reblog": <null>, "media_attachments": <__NSArray0 0x60000000ecc0>(

)
, "uri": https://niu.moe/users/ivesen/statuses/98818207067203544, "favourites_count": 0, "language": <null>, "muted": 0, "reblogged": 0, "tags": <__NSArray0 0x60000000ecc0>(

)
, "visibility": public, "mentions": <__NSSingleObjectArrayI 0x60400000f920>(
{
    acct = "[email protected]";
    id = 178083;
    url = "https://niu.moe/@Pasty";
    username = Pasty;
}
)
, "application": <null>, "content": <p><span class="h-card"><a href="https://niu.moe/@Pasty" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>Pasty</span></a></span> sleep tight chloe</p>, "spoiler_text": , "reblogs_count": 0, "id": 98818207199477749, "in_reply_to_account_id": 178083, "in_reply_to_id": 98818204421709969, "favourited": 0, "created_at": 2017-10-12T22:09:39.193Z, "account": {
    acct = "[email protected]";
    avatar = "https://files.mastodon.social/accounts/avatars/000/124/963/original/11c4a9fb168911ed.png";
    "avatar_static" = "https://files.mastodon.social/accounts/avatars/000/124/963/original/11c4a9fb168911ed.png";
    "created_at" = "2017-04-30T12:57:50.430Z";
    "display_name" = ivesen;
    "followers_count" = 97;
    "following_count" = 51;
    header = "https://files.mastodon.social/accounts/headers/000/124/963/original/f44ea559134c2ec6.jpg";
    "header_static" = "https://files.mastodon.social/accounts/headers/000/124/963/original/f44ea559134c2ec6.jpg";
    id = 124963;
    locked = 0;
    note = "<p>I forgot how to sleep at some point</p><p><a href=\"https://niu.moe/tags/nobot\" class=\"mention hashtag\" rel=\"nofollow noopener\" target=\"_blank\">#<span>nobot</span></a></p>";
    "statuses_count" = 3306;
    url = "https://niu.moe/@ivesen";
    username = ivesen;
}, "url": https://niu.moe/@ivesen/98818207067203544])
2017-10-12 23:22:19.402244+0100 Swiftty[67435:57645193] TIC Read Status [1:0x60000016ff00]: 1:57
2017-10-12 23:22:19.402393+0100 Swiftty[67435:57645193] TIC Read Status [1:0x60000016ff00]: 1:57
Optional(["sensitive": 0, "emojis": <__NSArray0 0x60000000ecc0>(

)
, "reblog": <null>, "media_attachments": <__NSArray0 0x60000000ecc0>(

)
, "uri": https://niu.moe/users/ivesen/statuses/98818207067203544, "favourites_count": 0, "language": <null>, "muted": 0, "reblogged": 0, "tags": <__NSArray0 0x60000000ecc0>(

)
, "visibility": public, "mentions": <__NSSingleObjectArrayI 0x60400000f920>(
{
    acct = "[email protected]";
    id = 178083;
    url = "https://niu.moe/@Pasty";
    username = Pasty;
}
)
, "application": <null>, "content": <p><span class="h-card"><a href="https://niu.moe/@Pasty" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>Pasty</span></a></span> sleep tight chloe</p>, "spoiler_text": , "reblogs_count": 0, "id": 98818207199477749, "in_reply_to_account_id": 178083, "in_reply_to_id": 98818204421709969, "favourited": 0, "created_at": 2017-10-12T22:09:39.193Z, "account": {
    acct = "[email protected]";
    avatar = "https://files.mastodon.social/accounts/avatars/000/124/963/original/11c4a9fb168911ed.png";
    "avatar_static" = "https://files.mastodon.social/accounts/avatars/000/124/963/original/11c4a9fb168911ed.png";
    "created_at" = "2017-04-30T12:57:50.430Z";
    "display_name" = ivesen;
    "followers_count" = 97;
    "following_count" = 51;
    header = "https://files.mastodon.social/accounts/headers/000/124/963/original/f44ea559134c2ec6.jpg";
    "header_static" = "https://files.mastodon.social/accounts/headers/000/124/963/original/f44ea559134c2ec6.jpg";
    id = 124963;
    locked = 0;
    note = "<p>I forgot how to sleep at some point</p><p><a href=\"https://niu.moe/tags/nobot\" class=\"mention hashtag\" rel=\"nofollow noopener\" target=\"_blank\">#<span>nobot</span></a></p>";
    "statuses_count" = 3306;
    url = "https://niu.moe/@ivesen";
    username = ivesen;
}, "url": https://niu.moe/@ivesen/98818207067203544])

screen shot 2017-10-12 at 23 23 03

MastodonKit: Command PhaseScriptExecution failed with a nonzero exit code.

The following output occurs when I try to build right after I install MastodonKit with cocoapods.

PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users//Library/Developer/Xcode/DerivedData/MastoViewer-bbrxmmfrxvitfphfpplcvznwejfo/Build/Intermediates.noindex/MastoViewer.build/Debug/MastoViewer.build/Script-1E315CD213184982319E532E.sh (in target: MastoViewer)
cd /Users//Documents/macOSAPP/MastoViewer
/bin/sh -c /Users//Library/Developer/Xcode/DerivedData/MastoViewer-bbrxmmfrxvitfphfpplcvznwejfo/Build/Intermediates.noindex/MastoViewer.build/Debug/MastoViewer.build/Script-1E315CD213184982319E532E.sh

mkdir -p /Users//Library/Developer/Xcode/DerivedData/MastoViewer-bbrxmmfrxvitfphfpplcvznwejfo/Build/Products/Debug/MastoViewer.app/Contents/Frameworks
rsync --delete -av --filter P .*.?????? --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "/Users//Library/Developer/Xcode/DerivedData/MastoViewer-bbrxmmfrxvitfphfpplcvznwejfo/Build/Products/Debug/MastodonKit/MastodonKit.framework" "/Users//Library/Developer/Xcode/DerivedData/MastoViewer-bbrxmmfrxvitfphfpplcvznwejfo/Build/Products/Debug/MastoViewer.app/Contents/Frameworks"
building file list ... done
MastodonKit.framework/
MastodonKit.framework/MastodonKit -> Versions/Current/MastodonKit
MastodonKit.framework/Resources -> Versions/Current/Resources
MastodonKit.framework/Versions/
MastodonKit.framework/Versions/Current -> A
MastodonKit.framework/Versions/A/
MastodonKit.framework/Versions/A/MastodonKit
MastodonKit.framework/Versions/A/Resources/
MastodonKit.framework/Versions/A/Resources/Info.plist

sent 629251 bytes received 106 bytes 1258714.00 bytes/sec
total size is 628754 speedup is 1.00
/Users//Documents/macOSAPP/MastoViewer/Pods/Target Support Files/Pods-MastoViewer/Pods-MastoViewer-frameworks.sh: line 104: EXPANDED_CODE_SIGN_IDENTITY: unbound variable
Command PhaseScriptExecution failed with a nonzero exit code

mastodonki

my Podfile looks like this:

# Uncomment the next line to define a global platform for your project
# platform :osx, '10.10'

target 'MastoViewer' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MastoViewer
    pod 'MastodonKit', '~> 1.0'

  target 'MastoViewerTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MastoViewerUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'TootViewer' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for TootViewer

end

Platform is osx 10.13.6
xcode version 10.0 (10A255)

What does this mean?

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.