mastodon-api 0.0.1
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 +7 -0
- data/lib/mastodon.rb +4 -0
- data/lib/mastodon/account.rb +31 -0
- data/lib/mastodon/app.rb +10 -0
- data/lib/mastodon/base.rb +44 -0
- data/lib/mastodon/client.rb +21 -0
- data/lib/mastodon/collection.rb +19 -0
- data/lib/mastodon/error.rb +18 -0
- data/lib/mastodon/headers.rb +17 -0
- data/lib/mastodon/relationship.rb +11 -0
- data/lib/mastodon/rest/accounts.rb +44 -0
- data/lib/mastodon/rest/api.rb +21 -0
- data/lib/mastodon/rest/apps.rb +18 -0
- data/lib/mastodon/rest/client.rb +10 -0
- data/lib/mastodon/rest/media.rb +13 -0
- data/lib/mastodon/rest/relationships.rb +45 -0
- data/lib/mastodon/rest/request.rb +37 -0
- data/lib/mastodon/rest/statuses.rb +72 -0
- data/lib/mastodon/rest/suggestions.rb +16 -0
- data/lib/mastodon/rest/timelines.rb +40 -0
- data/lib/mastodon/rest/utils.rb +32 -0
- data/lib/mastodon/status.rb +42 -0
- data/lib/mastodon/version.rb +29 -0
- data/mastodon.gemspec +21 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc0c9787cd86d495ceab2625291f4aceb8cdc6d6
|
4
|
+
data.tar.gz: 4f93ab9cd2a539f1db0b5d894be11673784a1322
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f10d250823c02c2ad8292dcbc524bb22907509e94b3c8586ae98a5027278aa02329aab1644fc0634ad12c850c9759ab31e3412ad193cd96fdd19030df45b6f8
|
7
|
+
data.tar.gz: e9f4fcd13cc8cd60152d174e8cad4a8716c97514c89dfb62081b53477708973ece9f7273830311ca6d5930d2af72d7b91a6d73b4a2a44fcbf9364c9f7f318c47
|
data/lib/mastodon.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Account < Mastodon::Base
|
3
|
+
# @!attribute [r] id
|
4
|
+
# @return [Integer]
|
5
|
+
# @!attribute [r] username
|
6
|
+
# @return [String]
|
7
|
+
# @!attribute [r] acct
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] url
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] avatar
|
12
|
+
# @return [String]
|
13
|
+
# @!attribute [r] header
|
14
|
+
# @return [String]
|
15
|
+
# @!attribute [r] note
|
16
|
+
# @return [String]
|
17
|
+
# @!attribute [r] followers_count
|
18
|
+
# @return [Integer]
|
19
|
+
# @!attribute [r] following_count
|
20
|
+
# @return [Integer]
|
21
|
+
# @!attribute [r] statuses_count
|
22
|
+
# @return [Integer]
|
23
|
+
|
24
|
+
normal_attr_reader :id, :username, :acct, :url, :avatar, :header, :note, :followers_count, :following_count, :statuses_count
|
25
|
+
|
26
|
+
def initialize(attributes = {})
|
27
|
+
attributes.fetch('id')
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/mastodon/app.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Base
|
3
|
+
attr_reader :attributes
|
4
|
+
|
5
|
+
alias to_h attributes
|
6
|
+
alias to_hash attributes
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def normal_attr_reader(*attributes)
|
14
|
+
attributes.each do |attribute|
|
15
|
+
define_attribute_method(attribute)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def object_attr_reader(attribute, klass)
|
20
|
+
define_method(attribute) do
|
21
|
+
klass.new(@attributes[attribute.to_s])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def predicate_attr_reader(*attributes)
|
26
|
+
attributes.each do |attribute|
|
27
|
+
define_predicate_method(attribute)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def define_predicate_method(key)
|
32
|
+
define_method("#{key}?") do
|
33
|
+
@attributes[key.to_s]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def define_attribute_method(key)
|
38
|
+
define_method(key) do
|
39
|
+
@attributes[key.to_s]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mastodon/version'
|
2
|
+
|
3
|
+
module Mastodon
|
4
|
+
class Client
|
5
|
+
attr_reader :base_url, :bearer_token
|
6
|
+
|
7
|
+
# @param options [Hash]
|
8
|
+
# @option options :base_url [String] URL of the instance you want to connect to
|
9
|
+
# @option options :bearer_token [String] OAuth access token for your authenticated user
|
10
|
+
def initialize(options = {})
|
11
|
+
@base_url = options[:base_url]
|
12
|
+
@bearer_token = options[:bearer_token]
|
13
|
+
end
|
14
|
+
|
15
|
+
# User agent of the client
|
16
|
+
# @return [String]
|
17
|
+
def user_agent
|
18
|
+
@user_agent ||= "MastodonRubyGem/#{Mastodon::Version}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Collection
|
3
|
+
include ::Enumerable
|
4
|
+
|
5
|
+
def initialize(items, klass)
|
6
|
+
@collection = items.map { |attributes| klass.new(attributes) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def each(start = 0)
|
10
|
+
return to_enum(:each, start) unless block_given?
|
11
|
+
|
12
|
+
Array(@collection[start..-1]).each do |element|
|
13
|
+
yield(element)
|
14
|
+
end
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Error < StandardError
|
3
|
+
ClientError = Class.new(self)
|
4
|
+
BadRequest = Class.new(ClientError)
|
5
|
+
Unauthorized = Class.new(ClientError)
|
6
|
+
Forbidden = Class.new(ClientError)
|
7
|
+
UnprocessableEntity = Class.new(ClientError)
|
8
|
+
TooManyRequests = Class.new(ClientError)
|
9
|
+
|
10
|
+
ERRORS = {
|
11
|
+
400 => Mastodon::Error::BadRequest,
|
12
|
+
401 => Mastodon::Error::Unauthorized,
|
13
|
+
403 => Mastodon::Error::Forbidden,
|
14
|
+
422 => Mastodon::Error::UnprocessableEntity,
|
15
|
+
429 => Mastodon::Error::TooManyRequests
|
16
|
+
}.freeze
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mastodon
|
2
|
+
class Headers
|
3
|
+
# @param client [Mastodon::Client]
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [Hash]
|
9
|
+
def request_headers
|
10
|
+
{
|
11
|
+
user_agent: @client.user_agent,
|
12
|
+
accept: '*/*',
|
13
|
+
authorization: "Bearer #{@client.bearer_token}"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/account'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Accounts
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Retrieve account of authenticated user
|
10
|
+
# @return [Mastodon::Account]
|
11
|
+
def verify_credentials
|
12
|
+
perform_request_with_object(:get, '/api/v1/accounts/verify_credentials', {}, Mastodon::Account)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Retrieve account
|
16
|
+
# @param id [Integer]
|
17
|
+
# @return [Mastodon::Account]
|
18
|
+
def account(id)
|
19
|
+
perform_request_with_object(:get, "/api/v1/accounts/#{id}", {}, Mastodon::Account)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get a list of followers
|
23
|
+
# @param id [Integer]
|
24
|
+
# @return [Mastodon::Collection<Mastodon::Account>]
|
25
|
+
def followers(id)
|
26
|
+
perform_request_with_collection(:get, "/api/v1/accounts/#{id}/followers", {}, Mastodon::Account)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Get a list of followed accounts
|
30
|
+
# @param id [Integer]
|
31
|
+
# @return [Mastodon::Collection<Mastodon::Account>]
|
32
|
+
def following(id)
|
33
|
+
perform_request_with_collection(:get, "/api/v1/accounts/#{id}/following", {}, Mastodon::Account)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Follow a remote user
|
37
|
+
# @param uri [String] The URI of the remote user, in the format of username@domain
|
38
|
+
# @return [Mastodon::Account]
|
39
|
+
def follow_by_uri(uri)
|
40
|
+
perform_request_with_object(:post, "/api/v1/follows", { uri: uri }, Mastodon::Account)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mastodon/rest/statuses'
|
2
|
+
require 'mastodon/rest/accounts'
|
3
|
+
require 'mastodon/rest/timelines'
|
4
|
+
require 'mastodon/rest/relationships'
|
5
|
+
require 'mastodon/rest/media'
|
6
|
+
require 'mastodon/rest/suggestions'
|
7
|
+
require 'mastodon/rest/apps'
|
8
|
+
|
9
|
+
module Mastodon
|
10
|
+
module REST
|
11
|
+
module API
|
12
|
+
include Mastodon::REST::Statuses
|
13
|
+
include Mastodon::REST::Accounts
|
14
|
+
include Mastodon::REST::Timelines
|
15
|
+
include Mastodon::REST::Relationships
|
16
|
+
include Mastodon::REST::Media
|
17
|
+
include Mastodon::REST::Suggestions
|
18
|
+
include Mastodon::REST::Apps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/app'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Apps
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Register a new OAuth client app on the target instance
|
10
|
+
# @param name [String]
|
11
|
+
# @param redirect_uri [String]
|
12
|
+
# @return [Mastodon::App]
|
13
|
+
def create_app(name, redirect_uri)
|
14
|
+
perform_request_with_object(:post, '/api/v1/apps', { name: name, redirect_uris: redirect_uri }, Mastodon::App)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/relationship'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Relationships
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Get the relationships of authenticated user towards given other users
|
10
|
+
# @param ids [Integer]
|
11
|
+
# @return [Mastodon::Collection<Mastodon::Relationship>]
|
12
|
+
def relationships(*ids)
|
13
|
+
perform_request_with_collection(:get, '/api/v1/accounts/relationships', { id: ids }, Mastodon::Relationship)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Follow a user
|
17
|
+
# @param id [Integer]
|
18
|
+
# @return [Mastodon::Relationship]
|
19
|
+
def follow(id)
|
20
|
+
perform_request_with_object(:post, "/api/v1/accounts/#{id}/follow", {}, Mastodon::Relationship)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Unfollow a user
|
24
|
+
# @param id [Integer]
|
25
|
+
# @return [Mastodon::Relationship]
|
26
|
+
def unfollow(id)
|
27
|
+
perform_request_with_object(:post, "/api/v1/accounts/#{id}/unfollow", {}, Mastodon::Relationship)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Block a user
|
31
|
+
# @param id [Integer]
|
32
|
+
# @return [Mastodon::Relationship]
|
33
|
+
def block(id)
|
34
|
+
perform_request_with_object(:post, "/api/v1/accounts/#{id}/block", {}, Mastodon::Relationship)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Unblock a user
|
38
|
+
# @param id [Integer]
|
39
|
+
# @return [Mastodon::Relationship]
|
40
|
+
def unblock(id)
|
41
|
+
perform_request_with_object(:post, "/api/v1/accounts/#{id}/unblock", {}, Mastodon::Relationship)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'http'
|
3
|
+
require 'json'
|
4
|
+
require 'mastodon/error'
|
5
|
+
require 'mastodon/headers'
|
6
|
+
|
7
|
+
module Mastodon
|
8
|
+
module REST
|
9
|
+
class Request
|
10
|
+
def initialize(client, request_method, path, options = {})
|
11
|
+
@client = client
|
12
|
+
@request_method = request_method
|
13
|
+
@uri = Addressable::URI.parse(@client.base_url + path)
|
14
|
+
@headers = Mastodon::Headers.new(@client).request_headers
|
15
|
+
@path = @uri.path
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
options_key = @request_method == :get ? :params : :form
|
21
|
+
response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, options_key => @options)
|
22
|
+
fail_or_return(response.code, response.body.empty? ? '' : response.parse)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fail_or_return(code, body)
|
28
|
+
raise Mastodon::Error::ERRORS[code] if Mastodon::Error::ERRORS.include?(code)
|
29
|
+
body
|
30
|
+
end
|
31
|
+
|
32
|
+
def http_client
|
33
|
+
HTTP
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/status'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Statuses
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Create new status
|
10
|
+
# @param text [String]
|
11
|
+
# @param in_reply_to_id [Integer]
|
12
|
+
# @param media_ids [Array<Integer>]
|
13
|
+
# @return [Mastodon::Status]
|
14
|
+
def create_status(text, in_reply_to_id = nil, media_ids = [])
|
15
|
+
perform_request_with_object(:post, "/api/v1/statuses", { status: text, in_reply_to_id: in_reply_to_id, media_ids: media_ids }, Mastodon::Status)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Retrieve status
|
19
|
+
# @param id [Integer]
|
20
|
+
# @return [Mastodon::Status]
|
21
|
+
def status(id)
|
22
|
+
perform_request_with_object(:get, "/api/v1/statuses/#{id}", {}, Mastodon::Status)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Destroy status
|
26
|
+
# @param id [Integer]
|
27
|
+
# @return [Boolean]
|
28
|
+
def destroy_status(id)
|
29
|
+
!perform_request(:delete, "/api/v1/statuses/#{id}").nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
# Reblog a status
|
33
|
+
# @param id [Integer]
|
34
|
+
# @return [Mastodon::Status]
|
35
|
+
def reblog(id)
|
36
|
+
perform_request_with_object(:post, "/api/v1/statuses/#{id}/reblog", {}, Mastodon::Status)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Undo a reblog of a status
|
40
|
+
# @param id [Integer]
|
41
|
+
# @return [Mastodon::Status]
|
42
|
+
def unreblog(id)
|
43
|
+
perform_request_with_object(:post, "/api/v1/statuses/#{id}/unreblog", {}, Mastodon::Status)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Favourite a status
|
47
|
+
# @param id [Integer]
|
48
|
+
# @return [Mastodon::Status]
|
49
|
+
def favourite(id)
|
50
|
+
perform_request_with_object(:post, "/api/v1/statuses/#{id}/favourite", {}, Mastodon::Status)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Undo a favourite of a status
|
54
|
+
# @param id [Integer]
|
55
|
+
# @return [Mastodon::Status]
|
56
|
+
def unfavourite(id)
|
57
|
+
perform_request_with_object(:post, "/api/v1/statuses/#{id}/unfavourite", {}, Mastodon::Status)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get a list of statuses by a user
|
61
|
+
# @param account_id [Integer]
|
62
|
+
# @param options [Hash]
|
63
|
+
# @option options :max_id [Integer]
|
64
|
+
# @option options :since_id [Integer]
|
65
|
+
# @option options :limit [Integer]
|
66
|
+
# @return [Mastodon::Collection<Mastodon::Status>]
|
67
|
+
def statuses(account_id, options = {})
|
68
|
+
perform_request_with_collection(:get, "/api/v1/accounts/#{account_id}/statuses", options, Mastodon::Status)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/account'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Suggestions
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Get "who to follow" suggestions for authenticated user
|
10
|
+
# @return [Mastodon::Collection<Mastodon::Account>]
|
11
|
+
def suggestions
|
12
|
+
perform_request_with_collection(:get, '/api/v1/accounts/suggestions', {}, Mastodon::Account)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'mastodon/rest/utils'
|
2
|
+
require 'mastodon/status'
|
3
|
+
|
4
|
+
module Mastodon
|
5
|
+
module REST
|
6
|
+
module Timelines
|
7
|
+
include Mastodon::REST::Utils
|
8
|
+
|
9
|
+
# Retrieve statuses from the home timeline
|
10
|
+
# @param options [Hash]
|
11
|
+
# @option options :max_id [Integer]
|
12
|
+
# @option options :since_id [Integer]
|
13
|
+
# @option options :limit [Integer]
|
14
|
+
# @return [Mastodon::Collection<Mastodon::Status>]
|
15
|
+
def home_timeline(options = {})
|
16
|
+
perform_request_with_collection(:get, '/api/v1/statuses/home', options, Mastodon::Status)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retrieve statuses from the mentions timeline
|
20
|
+
# @param options [Hash]
|
21
|
+
# @option options :max_id [Integer]
|
22
|
+
# @option options :since_id [Integer]
|
23
|
+
# @option options :limit [Integer]
|
24
|
+
# @return [Mastodon::Collection<Mastodon::Status>]
|
25
|
+
def mentions_timeline(options = {})
|
26
|
+
perform_request_with_collection(:get, '/api/v1/statuses/mentions', options, Mastodon::Status)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieve statuses from the public timeline
|
30
|
+
# @param options [Hash]
|
31
|
+
# @option options :max_id [Integer]
|
32
|
+
# @option options :since_id [Integer]
|
33
|
+
# @option options :limit [Integer]
|
34
|
+
# @return [Mastodon::Collection<Mastodon::Status>]
|
35
|
+
def public_timeline(options = {})
|
36
|
+
perform_request_with_collection(:get, '/api/v1/statuses/public', options, Mastodon::Status)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'mastodon/rest/request'
|
2
|
+
|
3
|
+
module Mastodon
|
4
|
+
module REST
|
5
|
+
module Utils
|
6
|
+
# @param request_method [Symbol]
|
7
|
+
# @param path [String]
|
8
|
+
# @param options [Hash]
|
9
|
+
def perform_request(request_method, path, options = {})
|
10
|
+
Mastodon::REST::Request.new(self, request_method, path, options).perform
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param request_method [Symbol]
|
14
|
+
# @param path [String]
|
15
|
+
# @param options [Hash]
|
16
|
+
# @param klass [Class]
|
17
|
+
def perform_request_with_object(request_method, path, options, klass)
|
18
|
+
response = perform_request(request_method, path, options)
|
19
|
+
klass.new(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param request_method [Symbol]
|
23
|
+
# @param path [String]
|
24
|
+
# @param options [Hash]
|
25
|
+
# @param klass [Class]
|
26
|
+
def perform_request_with_collection(request_method, path, options, klass)
|
27
|
+
response = perform_request(request_method, path, options)
|
28
|
+
Mastodon::Collection.new(response, klass)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'mastodon/account'
|
2
|
+
|
3
|
+
module Mastodon
|
4
|
+
class Status < Mastodon::Base
|
5
|
+
# @!attribute [r] id
|
6
|
+
# @return [Integer]
|
7
|
+
# @!attribute [r] in_reply_to_id
|
8
|
+
# @return [Integer]
|
9
|
+
# @!attribute [r] content
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] url
|
12
|
+
# @return [String]
|
13
|
+
# @!attribute [r] uri
|
14
|
+
# @return [String]
|
15
|
+
# @!attribute [r] created_at
|
16
|
+
# @return [String]
|
17
|
+
# @!attribute [r] reblogs_count
|
18
|
+
# @return [Integer]
|
19
|
+
# @!attribute [r] favourites_count
|
20
|
+
# @return [Integer]
|
21
|
+
# @!attribute [r] account
|
22
|
+
# @return [Mastodon::Account]
|
23
|
+
# @!attribute [r] reblog
|
24
|
+
# @return [Mastodon::Status]
|
25
|
+
# @!attribute [r] favourited?
|
26
|
+
# @return [Boolean]
|
27
|
+
# @!attribute [r] reblogged?
|
28
|
+
# @return [Boolean]
|
29
|
+
|
30
|
+
normal_attr_reader :id, :content, :in_reply_to_id, :url, :uri, :created_at, :reblogs_count, :favourites_count
|
31
|
+
|
32
|
+
predicate_attr_reader :favourited, :reblogged
|
33
|
+
|
34
|
+
object_attr_reader :account, Mastodon::Account
|
35
|
+
object_attr_reader :reblog, Mastodon::Status
|
36
|
+
|
37
|
+
def initialize(attributes = {})
|
38
|
+
attributes.fetch('id')
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Mastodon
|
2
|
+
module Version
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def major
|
6
|
+
0
|
7
|
+
end
|
8
|
+
|
9
|
+
def minor
|
10
|
+
0
|
11
|
+
end
|
12
|
+
|
13
|
+
def patch
|
14
|
+
1
|
15
|
+
end
|
16
|
+
|
17
|
+
def pre
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_a
|
22
|
+
[major, minor, patch, pre].compact
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
to_a.join('.')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/mastodon.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mastodon/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mastodon-api'
|
7
|
+
spec.description = 'A ruby interface to the Mastodon API'
|
8
|
+
spec.homepage = 'https://github.com/Gargron/mastodon-api'
|
9
|
+
spec.email = 'eugen@zeonfederated.com'
|
10
|
+
spec.authors = ['Eugen Rochko']
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.licenses = %w(MIT)
|
13
|
+
spec.files = %w(mastodon.gemspec) + Dir['lib/**/*.rb']
|
14
|
+
spec.require_paths = %w(lib)
|
15
|
+
spec.version = Mastodon::Version
|
16
|
+
|
17
|
+
spec.add_dependency 'http', '~> 2.0'
|
18
|
+
spec.add_dependency 'addressable', '~> 2.4'
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mastodon-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugen Rochko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: A ruby interface to the Mastodon API
|
56
|
+
email: eugen@zeonfederated.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/mastodon.rb
|
62
|
+
- lib/mastodon/account.rb
|
63
|
+
- lib/mastodon/app.rb
|
64
|
+
- lib/mastodon/base.rb
|
65
|
+
- lib/mastodon/client.rb
|
66
|
+
- lib/mastodon/collection.rb
|
67
|
+
- lib/mastodon/error.rb
|
68
|
+
- lib/mastodon/headers.rb
|
69
|
+
- lib/mastodon/relationship.rb
|
70
|
+
- lib/mastodon/rest/accounts.rb
|
71
|
+
- lib/mastodon/rest/api.rb
|
72
|
+
- lib/mastodon/rest/apps.rb
|
73
|
+
- lib/mastodon/rest/client.rb
|
74
|
+
- lib/mastodon/rest/media.rb
|
75
|
+
- lib/mastodon/rest/relationships.rb
|
76
|
+
- lib/mastodon/rest/request.rb
|
77
|
+
- lib/mastodon/rest/statuses.rb
|
78
|
+
- lib/mastodon/rest/suggestions.rb
|
79
|
+
- lib/mastodon/rest/timelines.rb
|
80
|
+
- lib/mastodon/rest/utils.rb
|
81
|
+
- lib/mastodon/status.rb
|
82
|
+
- lib/mastodon/version.rb
|
83
|
+
- mastodon.gemspec
|
84
|
+
homepage: https://github.com/Gargron/mastodon-api
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: A ruby interface to the Mastodon API
|
108
|
+
test_files: []
|