mastodon-api 0.0.1 → 0.9.0
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/mastodon/base.rb +6 -0
- data/lib/mastodon/collection.rb +8 -0
- data/lib/mastodon/entities/media.rb +14 -0
- data/lib/mastodon/entities/mention.rb +14 -0
- data/lib/mastodon/media.rb +20 -0
- data/lib/mastodon/relationship.rb +9 -0
- data/lib/mastodon/rest/apps.rb +1 -1
- data/lib/mastodon/rest/media.rb +5 -1
- data/lib/mastodon/rest/relationships.rb +1 -1
- data/lib/mastodon/rest/utils.rb +8 -0
- data/lib/mastodon/status.rb +9 -0
- data/lib/mastodon/version.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accd7a899ecb47c6c3422e33a0b73616ce4e136b
|
4
|
+
data.tar.gz: 3391e4cfdcf7954653114bb48504fe8af5160f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80cd9c0868459f585815ea381d163d1df3f9fca050db242acbbab50982463f38a2b6be9770de59f7ad4b1adf9a393195c4665cbee657b26a9a863e942eb9f0da
|
7
|
+
data.tar.gz: 57085547060814204777c1153be45118b250a0cf3e26479046ba2d172fa291dec3a39d6027d4c56ba843ed0a968cc1e3282eebf7098590effb9217d0f7a45cea
|
data/lib/mastodon/base.rb
CHANGED
@@ -22,6 +22,12 @@ module Mastodon
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def collection_attr_reader(attribute, klass)
|
26
|
+
define_method(attribute) do
|
27
|
+
Mastodon::Collection.new(@attributes[attribute.to_s], klass)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
def predicate_attr_reader(*attributes)
|
26
32
|
attributes.each do |attribute|
|
27
33
|
define_predicate_method(attribute)
|
data/lib/mastodon/collection.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mastodon
|
2
|
+
module Entities
|
3
|
+
class Media < Mastodon::Base
|
4
|
+
# @!attribute [r] url
|
5
|
+
# @return [String]
|
6
|
+
# @!attribute [r] preview_url
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] type
|
9
|
+
# @return [String]
|
10
|
+
|
11
|
+
normal_attr_reader :url, :preview_url, :type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mastodon
|
2
|
+
module Entities
|
3
|
+
class Mention < Mastodon::Base
|
4
|
+
# @!attribute [r] id
|
5
|
+
# @return [Integer] Account ID
|
6
|
+
# @!attribute [r] acct
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] url
|
9
|
+
# @return [String]
|
10
|
+
|
11
|
+
normal_attr_reader :id, :acct, :url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Media < Mastodon::Base
|
3
|
+
# @!attribute [r] id
|
4
|
+
# @return [Integer]
|
5
|
+
# @!attribute [r] type
|
6
|
+
# @return [String] Image or video
|
7
|
+
# @!attribute [r] url
|
8
|
+
# @return [String] Full file URL
|
9
|
+
# @!attribute [r] preview_url
|
10
|
+
# @return [String] URL to preview image
|
11
|
+
# @!attribute [r] text_url
|
12
|
+
# @return [String] URL that can be put into status body and will redirect to the status/media
|
13
|
+
|
14
|
+
normal_attr_reader :id, :type, :url, :preview_url, :text_url
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
attributes.fetch('id')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,5 +1,14 @@
|
|
1
1
|
module Mastodon
|
2
2
|
class Relationship < Mastodon::Base
|
3
|
+
# @!attribute [r] id
|
4
|
+
# @return [Integer] Account ID
|
5
|
+
# @!attribute [r] following?
|
6
|
+
# @return [Boolean]
|
7
|
+
# @!attribute [r] followed_by?
|
8
|
+
# @return [Boolean]
|
9
|
+
# @!attribute [r] blocking?
|
10
|
+
# @return [Boolean]
|
11
|
+
|
3
12
|
normal_attr_reader :id
|
4
13
|
predicate_attr_reader :following, :followed_by, :blocking
|
5
14
|
|
data/lib/mastodon/rest/apps.rb
CHANGED
@@ -11,7 +11,7 @@ module Mastodon
|
|
11
11
|
# @param redirect_uri [String]
|
12
12
|
# @return [Mastodon::App]
|
13
13
|
def create_app(name, redirect_uri)
|
14
|
-
perform_request_with_object(:post, '/api/v1/apps', {
|
14
|
+
perform_request_with_object(:post, '/api/v1/apps', { client_name: name, redirect_uris: redirect_uri }, Mastodon::App)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/mastodon/rest/media.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/media'
|
2
3
|
|
3
4
|
module Mastodon
|
4
5
|
module REST
|
5
6
|
module Media
|
6
7
|
include Mastodon::REST::Utils
|
7
8
|
|
9
|
+
# Upload a media file
|
10
|
+
# @param file [HTTP::FormData::File]
|
11
|
+
# @return [Mastodon::Media]
|
8
12
|
def upload_media(file)
|
9
|
-
|
13
|
+
perform_request_with_object(:post, '/api/v1/media', { file: file }, Mastodon::Media)
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -10,7 +10,7 @@ module Mastodon
|
|
10
10
|
# @param ids [Integer]
|
11
11
|
# @return [Mastodon::Collection<Mastodon::Relationship>]
|
12
12
|
def relationships(*ids)
|
13
|
-
perform_request_with_collection(:get, '/api/v1/accounts/relationships',
|
13
|
+
perform_request_with_collection(:get, '/api/v1/accounts/relationships', array_param(:id, ids), Mastodon::Relationship)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Follow a user
|
data/lib/mastodon/rest/utils.rb
CHANGED
@@ -27,6 +27,14 @@ module Mastodon
|
|
27
27
|
response = perform_request(request_method, path, options)
|
28
28
|
Mastodon::Collection.new(response, klass)
|
29
29
|
end
|
30
|
+
|
31
|
+
# Format an array of values into a query param hash
|
32
|
+
# @param key [Symbol]
|
33
|
+
# @param values [Enumerable]
|
34
|
+
# @return [Hash]
|
35
|
+
def array_param(key, values)
|
36
|
+
values.map.with_index { |value, i| ["#{key}[#{i}]", value] }.to_h
|
37
|
+
end
|
30
38
|
end
|
31
39
|
end
|
32
40
|
end
|
data/lib/mastodon/status.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'mastodon/account'
|
2
|
+
require 'mastodon/entities/media'
|
3
|
+
require 'mastodon/entities/mention'
|
2
4
|
|
3
5
|
module Mastodon
|
4
6
|
class Status < Mastodon::Base
|
@@ -26,6 +28,10 @@ module Mastodon
|
|
26
28
|
# @return [Boolean]
|
27
29
|
# @!attribute [r] reblogged?
|
28
30
|
# @return [Boolean]
|
31
|
+
# @!attribute [r] media_attachments
|
32
|
+
# @return [Mastodon::Collection<Mastodon::Entities::Media>]
|
33
|
+
# @!attribute [r] mentions
|
34
|
+
# @return [Mastodon::Collection<Mastodon::Entities::Mention>]
|
29
35
|
|
30
36
|
normal_attr_reader :id, :content, :in_reply_to_id, :url, :uri, :created_at, :reblogs_count, :favourites_count
|
31
37
|
|
@@ -34,6 +40,9 @@ module Mastodon
|
|
34
40
|
object_attr_reader :account, Mastodon::Account
|
35
41
|
object_attr_reader :reblog, Mastodon::Status
|
36
42
|
|
43
|
+
collection_attr_reader :media_attachments, Mastodon::Entities::Media
|
44
|
+
collection_attr_reader :mentions, Mastodon::Entities::Mention
|
45
|
+
|
37
46
|
def initialize(attributes = {})
|
38
47
|
attributes.fetch('id')
|
39
48
|
super
|
data/lib/mastodon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastodon-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugen Rochko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -64,8 +64,11 @@ files:
|
|
64
64
|
- lib/mastodon/base.rb
|
65
65
|
- lib/mastodon/client.rb
|
66
66
|
- lib/mastodon/collection.rb
|
67
|
+
- lib/mastodon/entities/media.rb
|
68
|
+
- lib/mastodon/entities/mention.rb
|
67
69
|
- lib/mastodon/error.rb
|
68
70
|
- lib/mastodon/headers.rb
|
71
|
+
- lib/mastodon/media.rb
|
69
72
|
- lib/mastodon/relationship.rb
|
70
73
|
- lib/mastodon/rest/accounts.rb
|
71
74
|
- lib/mastodon/rest/api.rb
|