pinata 1.0.3 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba75b73272ea6aa069b6e0611646d16bd912007d3c1301cf642261b32171788d
4
- data.tar.gz: c97be242f95c38e6c8981ed07bc7b5ef87a34d11498bc0a25ca585ef9d2c17ee
3
+ metadata.gz: 341660ad2f2ed148c9e3a9d7a79344253888aa027a35722c435be98b3b4e905d
4
+ data.tar.gz: e931d31a5b993c2816a5fde7f6df89f04d0a6cc661abb8664403bffdfa111924
5
5
  SHA512:
6
- metadata.gz: 7f3d95309e9f692bf1b027d9936f0c8ce5243570ab7f3e2c92c0c1eacf9acc593405733037cf138125a32b52979eaff1c362cf622b78a83f7f86c4eae394ca82
7
- data.tar.gz: d3c0da1b275300a2d40f6c54bc0c67f7b4e6b864506c3ea576605e28a73c29295466e7299bf562fde06302c16fd21e6917163bcbaabbc04fa7544da3a890f8c6
6
+ metadata.gz: 40a983ad8e8f10c626448ac3cc8b9d33f68f6884b17144b69029aef2bacd4b1c8d3410648c9d7965cc922902386172c81d8dfd53cf93b874b6dc7a22d8e7d9db
7
+ data.tar.gz: f519fbfc5365c9ed40aaf6f5cc12cacc3f3698732be980a0775e7236e5d91cab92479344e6f727f4347e2c0d6b1d2d3e454e40e9b836518ac3dc0eaf4c188c0f
data/README.md CHANGED
@@ -89,6 +89,18 @@ client.files.update(file_id: "thefilesid", "name": "thenameoffile")
89
89
  client.files.delete(file_id: "1234567890")
90
90
  ```
91
91
 
92
+ ### Groups
93
+
94
+ ```ruby
95
+ client.groups.create({})
96
+ client.groups.get(group_id: "id")
97
+ client.groups.list
98
+ client.groups.add_file(group_id: "id", file_id: "id")
99
+ client.groups.remove_file(group_id: "id", file_id: "id")
100
+ client.groups.update(group_id: "id", {})
101
+ client.groups.delete(group_id: "id")
102
+ ```
103
+
92
104
  ## Development
93
105
 
94
106
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/pinata/client.rb CHANGED
@@ -26,6 +26,10 @@ module Pinata
26
26
  FilesResource.new(self)
27
27
  end
28
28
 
29
+ def groups
30
+ GroupsResource.new(self)
31
+ end
32
+
29
33
  def test_connection
30
34
  @test_connection ||= Faraday.new(url: API_BASE_URL) do |conn|
31
35
  conn.request :authorization, :Bearer, pinata_jwt
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pinata
4
+ class Group < Object
5
+ end
6
+ end
@@ -30,7 +30,7 @@ module Pinata
30
30
  handle_response client.api_connection.patch(url, body, headers)
31
31
  end
32
32
 
33
- def api_put_request(url, body:, headers: {})
33
+ def api_put_request(url, body: {}, headers: {})
34
34
  handle_response client.api_connection.put(url, body, headers)
35
35
  end
36
36
 
@@ -2,10 +2,12 @@
2
2
 
3
3
  module Pinata
4
4
  class FilesResource < Resource
5
- def upload(file:, name: nil, mime_type: nil, metadata: nil)
5
+ def upload(file:, group_id: nil, name: nil, mime_type: nil, metadata: nil)
6
+ validate(file: file)
6
7
  mime_type ||= Marcel::MimeType.for(file)
7
8
  payload = {file: Faraday::UploadIO.new(file, mime_type)}
8
9
  payload[:name] = name unless name.nil?
10
+ payload[:group_id] = group_id unless group_id.nil?
9
11
  payload[:keyvalues] = metadata unless metadata.nil?
10
12
  File.new upload_post_request("files", body: payload,
11
13
  headers: {"Content-Type" => "multipart/form-data"}).body["data"]
@@ -38,5 +40,9 @@ module Pinata
38
40
  def delete(file_id:)
39
41
  File.new api_delete_request("files/#{file_id}").body.dig("data")
40
42
  end
43
+
44
+ def validate(file:)
45
+ raise ArgumentError, "`file` is required" if file.nil?
46
+ end
41
47
  end
42
48
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pinata
4
+ class GroupsResource < Resource
5
+ def create(name:, is_public: false)
6
+ payload = {
7
+ name: name,
8
+ is_public: is_public
9
+ }
10
+ Group.new api_post_request("files/groups", body: payload).body["data"]
11
+ end
12
+
13
+ def get(group_id:)
14
+ Group.new api_get_request("files/groups/#{group_id}").body.dig("data")
15
+ end
16
+
17
+ def list(**params)
18
+ response = api_get_request("files/groups", params: params)
19
+ Collection.from_response(response, key: "groups", type: Group)
20
+ end
21
+
22
+ def add_file(group_id:, file_id:)
23
+ Group.new api_put_request("files/groups/#{group_id}/ids/#{file_id}").body["data"]
24
+ end
25
+
26
+ def remove_file(group_id:, file_id:)
27
+ Group.new api_delete_request("files/groups/#{group_id}/ids/#{file_id}").body["data"]
28
+ end
29
+
30
+ def update(group_id:, **attributes)
31
+ Group.new api_put_request("files/groups/#{group_id}", body: attributes).body["data"]
32
+ end
33
+
34
+ def delete(group_id:)
35
+ Group.new api_delete_request("files/groups/#{group_id}").body.dig("data")
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pinata
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.5"
5
5
  end
data/lib/pinata.rb CHANGED
@@ -16,6 +16,8 @@ module Pinata
16
16
 
17
17
  autoload :AuthenticationResource, "pinata/resources/authentication"
18
18
  autoload :FilesResource, "pinata/resources/files"
19
+ autoload :GroupsResource, "pinata/resources/groups"
19
20
 
20
21
  autoload :File, "pinata/objects/file"
22
+ autoload :Group, "pinata/objects/group"
21
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Onyx Mueller
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-20 00:00:00.000000000 Z
11
+ date: 2025-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -72,9 +72,11 @@ files:
72
72
  - lib/pinata/error.rb
73
73
  - lib/pinata/object.rb
74
74
  - lib/pinata/objects/file.rb
75
+ - lib/pinata/objects/group.rb
75
76
  - lib/pinata/resource.rb
76
77
  - lib/pinata/resources/authentication.rb
77
78
  - lib/pinata/resources/files.rb
79
+ - lib/pinata/resources/groups.rb
78
80
  - lib/pinata/version.rb
79
81
  - pinata.gemspec
80
82
  - sig/pinata.rbs
@@ -85,7 +87,7 @@ metadata:
85
87
  homepage_uri: https://github.com/onyxmueller/pinata-ruby
86
88
  source_code_uri: https://github.com/onyxmueller/pinata-ruby
87
89
  changelog_uri: https://github.com/onyxmueller/pinata-ruby/changelog.md
88
- post_install_message:
90
+ post_install_message:
89
91
  rdoc_options: []
90
92
  require_paths:
91
93
  - lib
@@ -101,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  version: '0'
102
104
  requirements: []
103
105
  rubygems_version: 3.4.19
104
- signing_key:
106
+ signing_key:
105
107
  specification_version: 4
106
108
  summary: Ruby bindings for the Pinata API
107
109
  test_files: []