ruby-trello 4.0.0 → 4.1.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
  SHA256:
3
- metadata.gz: 444768a08c6a6d45235a6a35d935870d9a18dfd3486e64067ba4cdececf34701
4
- data.tar.gz: b3af839b451f934e29be6c6a5247c2945fc6d864182f70dc70be284f38c9cb55
3
+ metadata.gz: b0b194ee4ee89c070fb0114b73ce3284368c98f5053555e1a3840a23f8d478b7
4
+ data.tar.gz: 8d1f2ccee4d1e694d8d49b7428ad5e2e0d4a4cdacf713c7edbd86f7782bb07fb
5
5
  SHA512:
6
- metadata.gz: 5a719ac68ef702c5acb8e1cdccee07ff149f69c73e523f5c553823f68d3a7ac9643337b668218009f3c45138d69545dcde89946bad1b5f3fe464ea1ae6b0f020
7
- data.tar.gz: 6a3f2dd5aee11df5ab30a08098174c70119e1ceac944d4b689e0fca4076d9dac198d06b63f376c8142fd4a825ac96645e34eacca260f1909257b2b7cfaf340b6
6
+ metadata.gz: afb77d7aafa9cee6c727997864b9d009ae31d679a8e5ae1d5d4c2699b61dd27f99f21a1a13196ad3003c4222b926e4b4822dc11cedd1997bf52ae2e35e2ff474
7
+ data.tar.gz: '039ec7a24b9efa6445138ad0fb7072cb5acfdfc40edf7e9bc383959e3bdcf8ca30e80efee66be088a15008b2456e53b663cfab4666eecce79c3243356d468db4'
data/lib/trello/card.rb CHANGED
@@ -273,7 +273,7 @@ module Trello
273
273
  # Is it a file object or a string (url)?
274
274
  if attachment.respond_to?(:path) && attachment.respond_to?(:read)
275
275
  client.post("/cards/#{id}/attachments", {
276
- file: attachment,
276
+ file: Trello::TInternet.multipart_file(attachment),
277
277
  name: name
278
278
  })
279
279
  else
@@ -4,6 +4,8 @@ module Trello
4
4
  class << self
5
5
  begin
6
6
  require 'faraday'
7
+ require 'faraday/multipart'
8
+ require 'mime/types'
7
9
  rescue LoadError
8
10
  end
9
11
 
@@ -11,6 +13,14 @@ module Trello
11
13
  try_execute request
12
14
  end
13
15
 
16
+ def multipart_file(file)
17
+ Faraday::Multipart::FilePart.new(
18
+ file,
19
+ content_type(file),
20
+ filename(file)
21
+ )
22
+ end
23
+
14
24
  private
15
25
 
16
26
  def try_execute(request)
@@ -33,6 +43,7 @@ module Trello
33
43
  request: { timeout: 10 }
34
44
  ) do |faraday|
35
45
  faraday.response :raise_error
46
+ faraday.request :multipart
36
47
  faraday.request :json
37
48
  end
38
49
 
@@ -40,6 +51,26 @@ module Trello
40
51
  req.body = request.body
41
52
  end
42
53
  end
54
+
55
+ def content_type(file)
56
+ return file.content_type if file.respond_to?(:content_type)
57
+
58
+ mime = MIME::Types.type_for file.path
59
+ if mime.empty?
60
+ 'text/plain'
61
+ else
62
+ mime[0].content_type
63
+ end
64
+ end
65
+
66
+ def filename(file)
67
+ if file.respond_to?(:original_filename)
68
+ file.original_filename
69
+ else
70
+ File.basename(file.path)
71
+ end
72
+ end
73
+
43
74
  end
44
75
  end
45
76
  end
@@ -11,6 +11,10 @@ module Trello
11
11
  try_execute request
12
12
  end
13
13
 
14
+ def multipart_file(file)
15
+ file
16
+ end
17
+
14
18
  private
15
19
 
16
20
  def try_execute(request)
data/lib/trello/net.rb CHANGED
@@ -7,6 +7,10 @@ module Trello
7
7
  def execute(request)
8
8
  Trello.http_client.execute(request)
9
9
  end
10
+
11
+ def multipart_file(file)
12
+ Trello.http_client.multipart_file(file)
13
+ end
10
14
  end
11
15
  end
12
16
  end
data/spec/card_spec.rb CHANGED
@@ -734,7 +734,7 @@ module Trello
734
734
 
735
735
  allow(client)
736
736
  .to receive(:post)
737
- .with("/cards/abcdef123456789123456789/attachments", { file: f, name: '' })
737
+ .with("/cards/abcdef123456789123456789/attachments", { file: instance_of(Multipart::Post::UploadIO), name: '' })
738
738
  .and_return "not important"
739
739
 
740
740
  card.add_attachment(f)
@@ -0,0 +1,244 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.trello.com/1/cards/5e95d1b4f43f9a06497f17f7?key=DEVELOPER_PUBLIC_KEY&token=MEMBER_TOKEN
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v2.3.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Sat, 11 Nov 2023 18:18:11 GMT
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - '1053'
27
+ X-Dns-Prefetch-Control:
28
+ - 'off'
29
+ Expect-Ct:
30
+ - max-age=0
31
+ X-Frame-Options:
32
+ - DENY
33
+ X-Download-Options:
34
+ - noopen
35
+ X-Permitted-Cross-Domain-Policies:
36
+ - none
37
+ Referrer-Policy:
38
+ - strict-origin-when-cross-origin
39
+ Surrogate-Control:
40
+ - no-store
41
+ Cache-Control:
42
+ - max-age=0, must-revalidate, no-cache, no-store
43
+ Pragma:
44
+ - no-cache
45
+ Expires:
46
+ - Thu, 01 Jan 1970 00:00:00
47
+ X-Trello-Version:
48
+ - 1.242759.0
49
+ X-Trello-Environment:
50
+ - Production
51
+ Set-Cookie:
52
+ - dsc=set_cookie_dsc; Path=/; Expires=Sat, 25 Nov 2023 18:18:11 GMT; Secure;
53
+ SameSite=None
54
+ - preAuthProps=s%3A5e679b808e6e8828784b30e1%3AisEnterpriseAdmin%3Dfalse.Pfv1AFghhSOM0MLjFpWB8CaOPcNRIjt%2FmCZysEK4KNY;
55
+ Path=/; HttpOnly
56
+ Access-Control-Allow-Origin:
57
+ - "*"
58
+ Access-Control-Allow-Methods:
59
+ - GET, PUT, POST, DELETE
60
+ Access-Control-Allow-Headers:
61
+ - Authorization, Accept, Content-Type
62
+ Access-Control-Expose-Headers:
63
+ - x-rate-limit-api-key-interval-ms, x-rate-limit-api-key-max, x-rate-limit-api-key-remaining,
64
+ x-rate-limit-api-token-interval-ms, x-rate-limit-api-token-max, x-rate-limit-api-token-remaining
65
+ X-Rate-Limit-Api-Token-Interval-Ms:
66
+ - '10000'
67
+ X-Rate-Limit-Api-Token-Max:
68
+ - '100'
69
+ X-Rate-Limit-Api-Token-Remaining:
70
+ - '99'
71
+ X-Rate-Limit-Db-Query-Time-Interval-Ms:
72
+ - '600000'
73
+ X-Rate-Limit-Db-Query-Time-Max:
74
+ - '7200000'
75
+ X-Rate-Limit-Db-Query-Time-Remaining:
76
+ - '7199990'
77
+ X-Rate-Limit-Api-Key-Interval-Ms:
78
+ - '10000'
79
+ X-Rate-Limit-Api-Key-Max:
80
+ - '300'
81
+ X-Rate-Limit-Api-Key-Remaining:
82
+ - '299'
83
+ X-Rate-Limit-Member-Interval-Ms:
84
+ - '10000'
85
+ X-Rate-Limit-Member-Max:
86
+ - '375'
87
+ X-Rate-Limit-Member-Remaining:
88
+ - '374'
89
+ X-Server-Time:
90
+ - '1699726691750'
91
+ Server:
92
+ - AtlassianEdge
93
+ X-Content-Type-Options:
94
+ - nosniff
95
+ X-Xss-Protection:
96
+ - 1; mode=block
97
+ Atl-Traceid:
98
+ - 5442e51c04ce42f5aa01bfb53445cc31
99
+ Report-To:
100
+ - '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group":
101
+ "endpoint-1", "include_subdomains": true, "max_age": 600}'
102
+ Nel:
103
+ - '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to":
104
+ "endpoint-1"}'
105
+ Strict-Transport-Security:
106
+ - max-age=63072000; preload
107
+ body:
108
+ encoding: UTF-8
109
+ string: '{"id":"5e95d1b4f43f9a06497f17f7","badges":{"attachmentsByType":{"trello":{"board":0,"card":0}},"location":false,"votes":0,"viewingMemberVoted":false,"subscribed":false,"start":null,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"checkItemsEarliestDue":null,"comments":0,"attachments":3,"description":false,"due":null,"dueComplete":false},"checkItemStates":[],"closed":false,"dueComplete":false,"dateLastActivity":"2023-11-11T18:14:08.574Z","desc":"","descData":null,"due":null,"dueReminder":null,"email":null,"idBoard":"5e94f5ded016b22c2437c13c","idChecklists":[],"idList":"5e95d1b07f2ff83927319128","idMembers":[],"idMembersVoted":[],"idShort":2,"idAttachmentCover":"","labels":[],"idLabels":[],"manualCoverAttachment":false,"name":"C2","pos":16384,"shortLink":"DeJYDbq0","shortUrl":"https://trello.com/c/DeJYDbq0","start":null,"subscribed":false,"url":"https://trello.com/c/DeJYDbq0/2-c2","cover":{"idAttachment":null,"color":null,"idUploadedBackground":null,"size":"normal","brightness":"light","idPlugin":null},"isTemplate":false,"cardRole":null}'
110
+ recorded_at: Sat, 11 Nov 2023 18:18:11 GMT
111
+ - request:
112
+ method: post
113
+ uri: https://api.trello.com/1/cards/5e95d1b4f43f9a06497f17f7/attachments?key=DEVELOPER_PUBLIC_KEY&token=MEMBER_TOKEN
114
+ body:
115
+ encoding: UTF-8
116
+ string: "-------------RubyMultipartPost-045b3ab4e226f744d8d7119fa63ad0fb\r\nContent-Disposition:
117
+ form-data; name=\"file\"; filename=\"add_and_remove_attachment_spec.rb\"\r\nContent-Length:
118
+ 1672\r\nContent-Type: application/x-ruby\r\nContent-Transfer-Encoding: binary\r\n\r\nrequire
119
+ 'spec_helper'\n\nRSpec.describe 'Trell::Card add and remove attachment' do\n
120
+ \ include IntegrationHelpers\n\n before { setup_trello }\n\n describe '#add_attachment'
121
+ do\n it 'can success add an attachment(file) on a card', focus: true do\n
122
+ \ cassette_name = Trello.http_client == \"rest-client\" ? \"can_add_a_file_on_a_card\"
123
+ : \"can_add_a_file_on_a_card_with_farady\"\n VCR.use_cassette(cassette_name)
124
+ do\n card = Trello::Card.find('5e95d1b4f43f9a06497f17f7')\n file
125
+ = File.new('spec/integration/card/add_and_remove_attachment_spec.rb', 'r')\n\n
126
+ \ response = card.add_attachment(file)\n expect(response.code).to
127
+ eq(200)\n body = JSON.parse(response.body)\n expect(body['name']).to
128
+ eq('add_and_remove_attachment_spec.rb')\n end\n end\n\n it 'can
129
+ success add and attachment(url) on a card' do\n VCR.use_cassette('can_add_a_file_from_url_on_a_card')
130
+ do\n card = Trello::Card.find('5e95d1b4f43f9a06497f17f7')\n file_url
131
+ = 'https://upload.wikimedia.org/wikipedia/en/6/6b/Hello_Web_Series_%28Wordmark%29_Logo.png'\n\n
132
+ \ response = card.add_attachment(file_url, 'hello.png')\n expect(response.code).to
133
+ eq(200)\n body = JSON.parse(response.body)\n expect(body['name']).to
134
+ eq('hello.png')\n end\n end\n end\n\n describe '#remove_attachment'
135
+ do\n it 'can success remove and attachment on a card' do\n VCR.use_cassette('can_remove_an_attachment_on_a_card')
136
+ do\n card = Trello::Card.find('5e95d1b4f43f9a06497f17f7')\n attachments
137
+ = card.attachments\n\n response = card.remove_attachment(attachments.last)\n
138
+ \ expect(response.code).to eq(200)\n end\n end\n end\nend\n\r\n-------------RubyMultipartPost-045b3ab4e226f744d8d7119fa63ad0fb\r\nContent-Disposition:
139
+ form-data; name=\"name\"\r\n\r\n\r\n-------------RubyMultipartPost-045b3ab4e226f744d8d7119fa63ad0fb--\r\n"
140
+ headers:
141
+ User-Agent:
142
+ - Faraday v2.3.0
143
+ Content-Type:
144
+ - multipart/form-data; boundary=-----------RubyMultipartPost-045b3ab4e226f744d8d7119fa63ad0fb
145
+ Content-Length:
146
+ - '2104'
147
+ Accept-Encoding:
148
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
149
+ Accept:
150
+ - "*/*"
151
+ response:
152
+ status:
153
+ code: 200
154
+ message: OK
155
+ headers:
156
+ Date:
157
+ - Sat, 11 Nov 2023 18:18:14 GMT
158
+ Content-Type:
159
+ - application/json; charset=utf-8
160
+ Content-Length:
161
+ - '451'
162
+ X-Dns-Prefetch-Control:
163
+ - 'off'
164
+ Expect-Ct:
165
+ - max-age=0
166
+ X-Frame-Options:
167
+ - DENY
168
+ X-Download-Options:
169
+ - noopen
170
+ X-Permitted-Cross-Domain-Policies:
171
+ - none
172
+ Referrer-Policy:
173
+ - strict-origin-when-cross-origin
174
+ Surrogate-Control:
175
+ - no-store
176
+ Cache-Control:
177
+ - max-age=0, must-revalidate, no-cache, no-store
178
+ Pragma:
179
+ - no-cache
180
+ Expires:
181
+ - Thu, 01 Jan 1970 00:00:00
182
+ X-Trello-Version:
183
+ - 1.242759.0
184
+ X-Trello-Environment:
185
+ - Production
186
+ Access-Control-Allow-Origin:
187
+ - "*"
188
+ Access-Control-Allow-Methods:
189
+ - GET, PUT, POST, DELETE
190
+ Access-Control-Allow-Headers:
191
+ - Authorization, Accept, Content-Type
192
+ Access-Control-Expose-Headers:
193
+ - x-rate-limit-api-key-interval-ms, x-rate-limit-api-key-max, x-rate-limit-api-key-remaining,
194
+ x-rate-limit-api-token-interval-ms, x-rate-limit-api-token-max, x-rate-limit-api-token-remaining
195
+ X-Rate-Limit-Api-Token-Interval-Ms:
196
+ - '10000'
197
+ X-Rate-Limit-Api-Token-Max:
198
+ - '100'
199
+ X-Rate-Limit-Api-Token-Remaining:
200
+ - '98'
201
+ X-Rate-Limit-Db-Query-Time-Interval-Ms:
202
+ - '600000'
203
+ X-Rate-Limit-Db-Query-Time-Max:
204
+ - '7200000'
205
+ X-Rate-Limit-Db-Query-Time-Remaining:
206
+ - '7199990'
207
+ X-Rate-Limit-Api-Key-Interval-Ms:
208
+ - '10000'
209
+ X-Rate-Limit-Api-Key-Max:
210
+ - '300'
211
+ X-Rate-Limit-Api-Key-Remaining:
212
+ - '298'
213
+ X-Rate-Limit-Member-Interval-Ms:
214
+ - '10000'
215
+ X-Rate-Limit-Member-Max:
216
+ - '375'
217
+ X-Rate-Limit-Member-Remaining:
218
+ - '373'
219
+ Set-Cookie:
220
+ - preAuthProps=s%3A5e679b808e6e8828784b30e1%3AisEnterpriseAdmin%3Dfalse.Pfv1AFghhSOM0MLjFpWB8CaOPcNRIjt%2FmCZysEK4KNY;
221
+ Path=/; HttpOnly
222
+ X-Server-Time:
223
+ - '1699726694377'
224
+ Server:
225
+ - AtlassianEdge
226
+ X-Content-Type-Options:
227
+ - nosniff
228
+ X-Xss-Protection:
229
+ - 1; mode=block
230
+ Atl-Traceid:
231
+ - c52c43e2b82d4915bb527fc58f3153bc
232
+ Report-To:
233
+ - '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group":
234
+ "endpoint-1", "include_subdomains": true, "max_age": 600}'
235
+ Nel:
236
+ - '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to":
237
+ "endpoint-1"}'
238
+ Strict-Transport-Security:
239
+ - max-age=63072000; preload
240
+ body:
241
+ encoding: UTF-8
242
+ string: '{"id":"654fc566366a6de141e759d8","bytes":1672,"date":"2023-11-11T18:18:14.070Z","edgeColor":null,"idMember":"5e679b808e6e8828784b30e1","isUpload":true,"mimeType":"application/x-ruby","name":"add_and_remove_attachment_spec.rb","previews":[],"url":"https://trello.com/1/cards/5e95d1b4f43f9a06497f17f7/attachments/654fc566366a6de141e759d8/download/add_and_remove_attachment_spec.rb","pos":81920,"fileName":"add_and_remove_attachment_spec.rb","limits":{}}'
243
+ recorded_at: Sat, 11 Nov 2023 18:18:14 GMT
244
+ recorded_with: VCR 6.1.0
@@ -7,7 +7,8 @@ RSpec.describe 'Trell::Card add and remove attachment' do
7
7
 
8
8
  describe '#add_attachment' do
9
9
  it 'can success add an attachment(file) on a card' do
10
- VCR.use_cassette('can_add_a_file_on_a_card') do
10
+ cassette_name = Trello.http_client == "rest-client" ? "can_add_a_file_on_a_card" : "can_add_a_file_on_a_card_with_farady"
11
+ VCR.use_cassette(cassette_name) do
11
12
  card = Trello::Card.find('5e95d1b4f43f9a06497f17f7')
12
13
  file = File.new('spec/integration/card/add_and_remove_attachment_spec.rb', 'r')
13
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Tregunna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -80,6 +80,40 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday-multipart
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mime-types
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '4.0'
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '3.0'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '4.0'
83
117
  description: A wrapper around the trello.com API.
84
118
  email: jeremy@tregunna.ca
85
119
  executables: []
@@ -158,6 +192,7 @@ files:
158
192
  - spec/cassettes/board_find_with_id_and_get_specific_fields.yml
159
193
  - spec/cassettes/can_add_a_file_from_url_on_a_card.yml
160
194
  - spec/cassettes/can_add_a_file_on_a_card.yml
195
+ - spec/cassettes/can_add_a_file_on_a_card_with_farady.yml
161
196
  - spec/cassettes/can_add_a_member_to_a_board.yml
162
197
  - spec/cassettes/can_add_a_member_to_a_card.yml
163
198
  - spec/cassettes/can_add_label_on_a_card.yml
@@ -465,6 +500,7 @@ test_files:
465
500
  - spec/cassettes/board_find_with_id_and_get_specific_fields.yml
466
501
  - spec/cassettes/can_add_a_file_from_url_on_a_card.yml
467
502
  - spec/cassettes/can_add_a_file_on_a_card.yml
503
+ - spec/cassettes/can_add_a_file_on_a_card_with_farady.yml
468
504
  - spec/cassettes/can_add_a_member_to_a_board.yml
469
505
  - spec/cassettes/can_add_a_member_to_a_card.yml
470
506
  - spec/cassettes/can_add_label_on_a_card.yml