plivo 0.3.19 → 4.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/AUTHORS.md +4 -0
  6. data/CHANGELOG.md +158 -0
  7. data/Gemfile +10 -0
  8. data/Jenkinsfile +7 -0
  9. data/LICENSE.txt +19 -0
  10. data/README.md +155 -24
  11. data/Rakefile +9 -0
  12. data/ci/config.yml +7 -0
  13. data/examples/conference_bridge.rb +108 -0
  14. data/examples/jwt.rb +32 -0
  15. data/examples/lookup.rb +24 -0
  16. data/examples/multi_party_call.rb +295 -0
  17. data/examples/phlos.rb +55 -0
  18. data/examples/regulatory_compliance.rb +167 -0
  19. data/lib/plivo/base/resource.rb +148 -0
  20. data/lib/plivo/base/resource_interface.rb +108 -0
  21. data/lib/plivo/base/response.rb +38 -0
  22. data/lib/plivo/base.rb +17 -0
  23. data/lib/plivo/base_client.rb +393 -0
  24. data/lib/plivo/exceptions.rb +50 -0
  25. data/lib/plivo/jwt.rb +120 -0
  26. data/lib/plivo/phlo_client.rb +29 -0
  27. data/lib/plivo/resources/accounts.rb +181 -0
  28. data/lib/plivo/resources/addresses.rb +302 -0
  29. data/lib/plivo/resources/applications.rb +258 -0
  30. data/lib/plivo/resources/call_feedback.rb +55 -0
  31. data/lib/plivo/resources/calls.rb +559 -0
  32. data/lib/plivo/resources/conferences.rb +367 -0
  33. data/lib/plivo/resources/endpoints.rb +132 -0
  34. data/lib/plivo/resources/identities.rb +319 -0
  35. data/lib/plivo/resources/lookup.rb +88 -0
  36. data/lib/plivo/resources/media.rb +97 -0
  37. data/lib/plivo/resources/messages.rb +215 -0
  38. data/lib/plivo/resources/multipartycalls.rb +554 -0
  39. data/lib/plivo/resources/nodes.rb +83 -0
  40. data/lib/plivo/resources/numbers.rb +319 -0
  41. data/lib/plivo/resources/phlo_member.rb +64 -0
  42. data/lib/plivo/resources/phlos.rb +55 -0
  43. data/lib/plivo/resources/powerpacks.rb +717 -0
  44. data/lib/plivo/resources/pricings.rb +43 -0
  45. data/lib/plivo/resources/recordings.rb +116 -0
  46. data/lib/plivo/resources/regulatory_compliance.rb +610 -0
  47. data/lib/plivo/resources.rb +25 -0
  48. data/lib/plivo/rest_client.rb +63 -0
  49. data/lib/plivo/utils.rb +294 -0
  50. data/lib/plivo/version.rb +3 -0
  51. data/lib/plivo/xml/break.rb +31 -0
  52. data/lib/plivo/xml/conference.rb +20 -0
  53. data/lib/plivo/xml/cont.rb +13 -0
  54. data/lib/plivo/xml/dial.rb +16 -0
  55. data/lib/plivo/xml/dtmf.rb +13 -0
  56. data/lib/plivo/xml/element.rb +106 -0
  57. data/lib/plivo/xml/emphasis.rb +17 -0
  58. data/lib/plivo/xml/get_digits.rb +15 -0
  59. data/lib/plivo/xml/get_input.rb +16 -0
  60. data/lib/plivo/xml/hangup.rb +12 -0
  61. data/lib/plivo/xml/lang.rb +29 -0
  62. data/lib/plivo/xml/message.rb +13 -0
  63. data/lib/plivo/xml/multipartycall.rb +188 -0
  64. data/lib/plivo/xml/number.rb +13 -0
  65. data/lib/plivo/xml/p.rb +12 -0
  66. data/lib/plivo/xml/phoneme.rb +20 -0
  67. data/lib/plivo/xml/play.rb +13 -0
  68. data/lib/plivo/xml/plivo_xml.rb +19 -0
  69. data/lib/plivo/xml/pre_answer.rb +12 -0
  70. data/lib/plivo/xml/prosody.rb +28 -0
  71. data/lib/plivo/xml/record.rb +17 -0
  72. data/lib/plivo/xml/redirect.rb +13 -0
  73. data/lib/plivo/xml/response.rb +21 -0
  74. data/lib/plivo/xml/s.rb +12 -0
  75. data/lib/plivo/xml/say_as.rb +24 -0
  76. data/lib/plivo/xml/speak.rb +28 -0
  77. data/lib/plivo/xml/sub.rb +16 -0
  78. data/lib/plivo/xml/user.rb +13 -0
  79. data/lib/plivo/xml/w.rb +17 -0
  80. data/lib/plivo/xml/wait.rb +12 -0
  81. data/lib/plivo/xml.rb +39 -0
  82. data/lib/plivo.rb +12 -815
  83. data/plivo.gemspec +44 -0
  84. metadata +181 -41
  85. data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,319 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Identity < Base::Resource
5
+
6
+ def initialize(client, options = nil)
7
+ @_name = 'Verification/Identity'
8
+ @_identifier_string = 'id'
9
+ super
10
+ end
11
+
12
+ def delete
13
+ perform_delete
14
+ end
15
+
16
+ # Update an identity
17
+ # @param [String] identity_id
18
+ # @param [String] file_to_upload
19
+ # @param [Hash] options
20
+ # @option options [String] :salutation - One of Mr or Ms
21
+ # @option options [String] :first_name - First name of the user for whom the identity is created
22
+ # @option options [String] :last_name - Last name of the user for whom the identity is created
23
+ # @option options [String] :country_iso - Country ISO 2 code
24
+ # @option options [String] :birth_place - Birthplace of the user for whom the identity is created
25
+ # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created
26
+ # @option options [String] :nationality - Nationality of the user for whom the identity is created
27
+ # @option options [String] :id_nationality - Nationality mentioned in the identity proof
28
+ # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof
29
+ # @option options [String] :id_type -
30
+ # @option options [String] :id_number - The unique number on the identifier
31
+ # @option options [String] :address_line1 - Building name/number
32
+ # @option options [String] :address_line2 - The street name/number of the address
33
+ # @option options [String] :city - The city of the address for which the address proof is created
34
+ # @option options [String] :region - The region of the address for which the address proof is created
35
+ # @option options [String] :postal_code - The postal code of the address that is being created
36
+ # @option options [String] :alias - Alias name of the identity
37
+ # @option options [String] :business_name - Business name of the user for whom the identity is created.
38
+ # @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
39
+ # @option options [String] :fiscal_identification_code - The code is valid for businesses alone
40
+ # @option options [String] :street_code - Street code of the address
41
+ # @option options [String] :municipal_code - Municipal code of the address
42
+ # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
43
+ # @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
44
+ # @return [Identity] Identity
45
+ def update(file_to_upload = nil, options = nil)
46
+ params = {}
47
+
48
+ unless options.nil?
49
+ %i[salutation first_name last_name country_iso birth_place birth_date nationality id_nationality id_issue_date
50
+ id_type id_number address_line1 address_line2 city region postal_code alias business_name
51
+ fiscal_identification_code street_code municipal_code callback_url subaccount
52
+ ]
53
+ .each do |param|
54
+ if options.key?(param) &&
55
+ valid_param?(param, options[param], [String, Symbol], true)
56
+ params[param] = options[param]
57
+ end
58
+ end
59
+
60
+ %i[auto_correct_address]
61
+ .each do |param|
62
+ if options.key?(param) &&
63
+ valid_param?(param, options[param], nil, true, [true, false])
64
+ params[param] = options[param]
65
+ end
66
+ end
67
+ end
68
+
69
+ unless file_to_upload.nil?
70
+ file_extension = file_to_upload.split('.')[-1]
71
+
72
+ content_type = case file_extension
73
+ when 'jpeg' then 'image/jpeg'
74
+ when 'jpg' then 'image/jpeg'
75
+ when 'png' then 'image/png'
76
+ when 'pdf' then 'application/pdf'
77
+ else raise_invalid_request("#{file_extension} is not yet supported for upload")
78
+ end
79
+
80
+ params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
81
+ end
82
+
83
+ return perform_update(params, true)
84
+ end
85
+
86
+ def to_s
87
+ {
88
+ account: @account,
89
+ alias: @alias,
90
+ api_id: @api_id,
91
+ country_iso: @country_iso,
92
+ document_details: @document_details,
93
+ first_name: @first_name,
94
+ id: @id,
95
+ id_number: @id_number,
96
+ id_type: @id_type,
97
+ last_name: @last_name,
98
+ nationality: @nationality,
99
+ salutation: @salutation,
100
+ subaccount: @subaccount,
101
+ url: @url,
102
+ validation_status: @validation_status,
103
+ verification_status: @verification_status
104
+ }.to_s
105
+ end
106
+ end
107
+
108
+ class IdentityInterface < Base::ResourceInterface
109
+ def initialize(client, resource_list_json = nil)
110
+ @_name = 'Verification/Identity'
111
+ @_resource_type = Identity
112
+ @_identifier_string = 'id'
113
+ super
114
+ end
115
+
116
+ ##
117
+ # Get an identity
118
+ # @param [String] identity_id
119
+ # @return [Identity] Identity
120
+ def get(identity_id)
121
+ valid_param?(:identity_id, identity_id, [String, Symbol], true)
122
+ perform_get(identity_id)
123
+ end
124
+
125
+ ##
126
+ # List all identities
127
+ # @param [Hash] options
128
+ # @option options [String] :country_iso - Country ISO 2 code
129
+ # @option options [String] :customer_name - Name of the customer or business that is mentioned in the identity
130
+ # @option options [String] :alias - Friendly name of the id proof
131
+ # @option options [String] :verification_status - The status of the identity: pending. accepted, rejected, null
132
+ # @option options [Int] :offset
133
+ # @option options [Int] :limit
134
+ # @return [Hash]
135
+ def list(options=nil)
136
+ return perform_list if options.nil?
137
+
138
+ params = {}
139
+
140
+ %i[country_iso customer_name alias].each do |param|
141
+ if options.key?(param) && valid_param?(param, options[param],
142
+ [String, Symbol], true)
143
+ params[param] = options[param]
144
+ end
145
+ end
146
+
147
+ %i[verification_status].each do |param|
148
+ if options.key?(param) && valid_param?(param, options[param],
149
+ [String, Symbol], true, ['pending', 'accepted', 'rejected',
150
+ :pending, :accepted, :rejected])
151
+ params[param] = options[param]
152
+ end
153
+ end
154
+
155
+ %i[offset limit].each do |param|
156
+ if options.key?(param) && valid_param?(param, options[param],
157
+ [Integer], true)
158
+ params[param] = options[param]
159
+ end
160
+ end
161
+
162
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
163
+ raise_invalid_request('The maximum number of results that can be '\
164
+ "fetched is 20. limit can't be more than 20 or less than 1")
165
+ end
166
+
167
+ if options.key?(:offset) && options[:offset] < 0
168
+ raise_invalid_request("Offset can't be negative")
169
+ end
170
+
171
+ perform_list(params)
172
+ end
173
+
174
+ ##
175
+ # Create a new identity
176
+ # @param [String] country_iso
177
+ # @param [String] salutation
178
+ # @param [String] first_name
179
+ # @param [String] last_name
180
+ # @param [String] birth_place
181
+ # @param [String] birth_date
182
+ # @param [String] nationality
183
+ # @param [String] id_nationality
184
+ # @param [String] id_issue_date
185
+ # @param [String] id_type
186
+ # @param [String] id_number
187
+ # @param [String] address_line1
188
+ # @param [String] address_line2
189
+ # @param [String] city
190
+ # @param [String] region
191
+ # @param [String] postal_code
192
+ # @param [String] file_to_upload
193
+ # @param [Hash] options
194
+ # @option options [String] :alias - Alias name of the identity
195
+ # @option options [String] :business_name - Business name of the user for whom the identity is created.
196
+ # @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
197
+ # @option options [String] :fiscal_identification_code - The code is valid for businesses alone
198
+ # @option options [String] :street_code - Street code of the address
199
+ # @option options [String] :municipal_code - Municipal code of the address
200
+ # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
201
+ # @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
202
+ # @return [Identity] Identity
203
+ def create(country_iso, salutation, first_name, last_name, birth_place, birth_date, nationality,
204
+ id_nationality, id_issue_date, id_type, id_number, address_line1, address_line2,
205
+ city, region, postal_code, file_to_upload=nil, options=nil)
206
+ valid_param?(:country_iso, country_iso, [String, Symbol], true)
207
+ valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr])
208
+ valid_param?(:first_name, first_name, [String, Symbol], true)
209
+ valid_param?(:last_name, last_name, [String, Symbol], true)
210
+ valid_param?(:birth_place, birth_place, [String, Symbol], true)
211
+ valid_param?(:birth_date, birth_date, [String, Symbol], true)
212
+ valid_param?(:nationality, nationality, [String, Symbol], true)
213
+ valid_param?(:id_nationality, id_nationality, [String, Symbol], true)
214
+ valid_param?(:id_issue_date, id_issue_date, [String, Symbol], true)
215
+ valid_param?(:id_type, id_type, [String, Symbol], true)
216
+ valid_param?(:id_number, id_number, [String, Symbol], true)
217
+ valid_param?(:address_line1, address_line1, [String, Symbol], true)
218
+ valid_param?(:address_line2, address_line2, [String, Symbol], true)
219
+ valid_param?(:city, city, [String, Symbol], true)
220
+ valid_param?(:region, region, [String, Symbol], true)
221
+ valid_param?(:postal_code, postal_code, [String, Symbol], true)
222
+
223
+ params = {
224
+ country_iso: country_iso,
225
+ salutation: salutation,
226
+ first_name: first_name,
227
+ last_name: last_name,
228
+ birth_place: birth_place,
229
+ birth_date: birth_date,
230
+ nationality: nationality,
231
+ id_nationality: id_nationality,
232
+ id_issue_date: id_issue_date,
233
+ id_type: id_type,
234
+ id_number: id_number,
235
+ address_line1: address_line1,
236
+ address_line2: address_line2,
237
+ city: city,
238
+ region: region,
239
+ postal_code: postal_code
240
+ }
241
+
242
+ unless file_to_upload.nil?
243
+ file_extension = file_to_upload.split('.')[-1]
244
+
245
+ content_type = case file_extension
246
+ when 'jpeg' then 'image/jpeg'
247
+ when 'jpg' then 'image/jpeg'
248
+ when 'png' then 'image/png'
249
+ when 'pdf' then 'application/pdf'
250
+ else raise_invalid_request("#{file_extension} is not yet supported for upload")
251
+ end
252
+
253
+ params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
254
+ end
255
+
256
+ %i[alias business_name fiscal_identification_code street_code municipal_code callback_url subaccount]
257
+ .each do |param|
258
+ if options.key?(param) &&
259
+ valid_param?(param, options[param], [String, Symbol], true)
260
+ params[param] = options[param]
261
+ end
262
+ end
263
+
264
+ %i[auto_correct_address]
265
+ .each do |param|
266
+ if options.key?(param) &&
267
+ valid_param?(param, options[param], nil, true, [true, false])
268
+ params[param] = options[param]
269
+ end
270
+ end
271
+
272
+ perform_create(params, true)
273
+ end
274
+
275
+ # Update an identity
276
+ # @param [String] identity_id
277
+ # @param [String] file_to_upload
278
+ # @param [Hash] options
279
+ # @option options [String] :salutation - One of Mr or Ms
280
+ # @option options [String] :first_name - First name of the user for whom the identity is created
281
+ # @option options [String] :last_name - Last name of the user for whom the identity is created
282
+ # @option options [String] :country_iso - Country ISO 2 code
283
+ # @option options [String] :birth_place - Birthplace of the user for whom the identity is created
284
+ # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created
285
+ # @option options [String] :nationality - Nationality of the user for whom the identity is created
286
+ # @option options [String] :id_nationality - Nationality mentioned in the identity proof
287
+ # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof
288
+ # @option options [String] :id_type -
289
+ # @option options [String] :id_number - The unique number on the identifier
290
+ # @option options [String] :address_line1 - Building name/number
291
+ # @option options [String] :address_line2 - The street name/number of the address
292
+ # @option options [String] :city - The city of the address for which the address proof is created
293
+ # @option options [String] :region - The region of the address for which the address proof is created
294
+ # @option options [String] :postal_code - The postal code of the address that is being created
295
+ # @option options [String] :alias - Alias name of the identity
296
+ # @option options [String] :business_name - Business name of the user for whom the identity is created.
297
+ # @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
298
+ # @option options [String] :fiscal_identification_code - The code is valid for businesses alone
299
+ # @option options [String] :street_code - Street code of the address
300
+ # @option options [String] :municipal_code - Municipal code of the address
301
+ # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
302
+ # @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
303
+ # @return [Identity] Identity
304
+ def update(identity_id, file_to_upload=nil, options=nil)
305
+ Identity.new(@_client,
306
+ resource_id: identity_id).update(file_to_upload, options)
307
+ end
308
+
309
+ ##
310
+ # Delete an identity
311
+ # @param [String] identity_id
312
+ def delete(identity_id)
313
+ valid_param?(:identity_id, identity_id, [String, Symbol], true)
314
+ Identity.new(@_client,
315
+ resource_id: identity_id).delete
316
+ end
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,88 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+
5
+ class LookupBaseResource
6
+ def initialize(fields = nil)
7
+ valid_param?(:fields, fields, Hash, false)
8
+ fields.each do |k, v|
9
+ instance_variable_set("@#{k}", v)
10
+ self.class.send(:attr_reader, k)
11
+ end
12
+ end
13
+
14
+ def to_s
15
+ hash = {}
16
+ instance_variables.each { |var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
17
+ hash.to_s
18
+ end
19
+ end
20
+
21
+ class Country < LookupBaseResource
22
+ end
23
+
24
+ class NumberFormat < LookupBaseResource
25
+ end
26
+
27
+ class Carrier < LookupBaseResource
28
+ end
29
+
30
+ # Not subclassing from Base::Resource because it cannot set nested
31
+ # attributes. Named the class 'LookupResponse' because the name
32
+ # 'Number' is already taken.
33
+ class LookupResponse < LookupBaseResource
34
+ def initialize(client, options = nil)
35
+ # there is no use for client here
36
+ valid_param?(:options, options, Hash, false)
37
+ parse_and_set(options[:resource_json]) if options.key?(:resource_json)
38
+ end
39
+
40
+ def parse_and_set(resp)
41
+ return unless resp
42
+ valid_param?(:resp, resp, Hash, true)
43
+
44
+ resp.each do |k, v|
45
+ case k
46
+ when "country"
47
+ instance_variable_set("@#{k}", Country.new(v))
48
+ when "format"
49
+ instance_variable_set("@#{k}", NumberFormat.new(v))
50
+ when "carrier"
51
+ instance_variable_set("@#{k}", Carrier.new(v))
52
+ else
53
+ instance_variable_set("@#{k}", v)
54
+ end
55
+ self.class.send(:attr_reader, k)
56
+ end
57
+ end
58
+ end
59
+
60
+ class LookupInterface < Base::ResourceInterface
61
+ def initialize(client, resource_list_json = nil)
62
+ @_resource_type = LookupResponse
63
+ @_identifier_string = "phone_number"
64
+ super
65
+ # Override _resource_uri only after calling super
66
+ @_resource_uri = "/v1/Number/"
67
+ end
68
+
69
+ ##
70
+ # Lookup a number
71
+ # @param [String] number
72
+ # @return [LookupResponse] LookupResponse
73
+ def get(number, type = "carrier")
74
+ valid_param?(:number, number, [String, Symbol], true)
75
+ perform_get(number, { "type" => type })
76
+ end
77
+
78
+ private
79
+
80
+ # overridden to ensure 'Account' and extra shash isn't added to URL path
81
+ def perform_get(identifier, params = nil)
82
+ valid_param?(:identifier, identifier, [String, Symbol], true)
83
+ response_json = @_client.send_request(@_resource_uri + identifier.to_s, "GET", params, nil, false, is_voice_request: @_is_voice_request, is_lookup_request: true)
84
+ @_resource_type.new(@_client, resource_json: response_json)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,97 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Media < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'Media'
7
+ @_identifier_string = 'media_id'
8
+ super
9
+ end
10
+
11
+ def to_s
12
+ {
13
+ content_type: @content_type,
14
+ file_name: @file_name,
15
+ api_id: @api_id,
16
+ media_id: @media_id,
17
+ size: @size,
18
+ upload_time: @upload_time,
19
+ url: @url
20
+ }.to_s
21
+ end
22
+ end
23
+
24
+ class MediaInterface < Base::ResourceInterface
25
+ def initialize(client, resource_list_json = nil)
26
+ @_name = 'Media'
27
+ @_resource_type = Media
28
+ @_identifier_string = 'media_id'
29
+ super
30
+ end
31
+
32
+ ##
33
+ # Get an Media
34
+ # @param [String] media_id
35
+ # @return [Media] Media
36
+ def get(media_id)
37
+ valid_param?(:media_id, media_id, [String, Symbol], true)
38
+ perform_get(media_id)
39
+ end
40
+
41
+ ##
42
+ # List all Media
43
+ # @param [Hash] options
44
+ # @option options [Int] :offset
45
+ # @option options [Int] :limit
46
+ # @return [Hash]
47
+ def list(options=nil)
48
+ return perform_list_without_object if options.nil?
49
+
50
+ params = {}
51
+ %i[offset limit].each do |param|
52
+ if options.key?(param) && valid_param?(param, options[param],
53
+ [Integer], true)
54
+ params[param] = options[param]
55
+ end
56
+ end
57
+
58
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
59
+ raise_invalid_request('The maximum number of results that can be '\
60
+ "fetched is 20. limit can't be more than 20 or less than 1")
61
+ end
62
+
63
+ if options.key?(:offset) && options[:offset] < 0
64
+ raise_invalid_request("Offset can't be negative")
65
+ end
66
+
67
+ perform_list_without_object(params)
68
+ end
69
+
70
+ ##
71
+ # Create a new upload
72
+ def upload(filepath)
73
+ params = {}
74
+ for file_to_upload in filepath do
75
+ unless file_to_upload.nil?
76
+ file_extension = file_to_upload.split('.')[-1]
77
+
78
+ content_type = case file_extension
79
+ when 'jpeg' then 'image/jpeg'
80
+ when 'jpg' then 'image/jpeg'
81
+ when 'png' then 'image/png'
82
+ when 'pdf' then 'application/pdf'
83
+ when 'xcf' then 'image/xcf'
84
+ when 'text' then 'text/plain'
85
+ when 'mpeg' then 'video/mpeg'
86
+ when 'mp4' then 'video/mp4'
87
+ else raise_invalid_request("#{file_extension} is not yet supported for upload")
88
+ end
89
+
90
+ params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
91
+ end
92
+ end
93
+ perform_create(params, true)
94
+ end
95
+ end
96
+ end
97
+ end