mastodon-api 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc0c9787cd86d495ceab2625291f4aceb8cdc6d6
4
- data.tar.gz: 4f93ab9cd2a539f1db0b5d894be11673784a1322
3
+ metadata.gz: accd7a899ecb47c6c3422e33a0b73616ce4e136b
4
+ data.tar.gz: 3391e4cfdcf7954653114bb48504fe8af5160f2d
5
5
  SHA512:
6
- metadata.gz: 8f10d250823c02c2ad8292dcbc524bb22907509e94b3c8586ae98a5027278aa02329aab1644fc0634ad12c850c9759ab31e3412ad193cd96fdd19030df45b6f8
7
- data.tar.gz: e9f4fcd13cc8cd60152d174e8cad4a8716c97514c89dfb62081b53477708973ece9f7273830311ca6d5930d2af72d7b91a6d73b4a2a44fcbf9364c9f7f318c47
6
+ metadata.gz: 80cd9c0868459f585815ea381d163d1df3f9fca050db242acbbab50982463f38a2b6be9770de59f7ad4b1adf9a393195c4665cbee657b26a9a863e942eb9f0da
7
+ data.tar.gz: 57085547060814204777c1153be45118b250a0cf3e26479046ba2d172fa291dec3a39d6027d4c56ba843ed0a968cc1e3282eebf7098590effb9217d0f7a45cea
@@ -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)
@@ -15,5 +15,13 @@ module Mastodon
15
15
 
16
16
  self
17
17
  end
18
+
19
+ def size
20
+ @collection.size
21
+ end
22
+
23
+ def last
24
+ @collection.last
25
+ end
18
26
  end
19
27
  end
@@ -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
 
@@ -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', { name: name, redirect_uris: redirect_uri }, Mastodon::App)
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
@@ -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
- raise NotImplementedError
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', { id: ids }, Mastodon::Relationship)
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
@@ -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
@@ -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
@@ -7,11 +7,11 @@ module Mastodon
7
7
  end
8
8
 
9
9
  def minor
10
- 0
10
+ 9
11
11
  end
12
12
 
13
13
  def patch
14
- 1
14
+ 0
15
15
  end
16
16
 
17
17
  def pre
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.1
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-20 00:00:00.000000000 Z
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