Class: Ubiquity::Envoi::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ubiquity/envoi/api/client.rb,
lib/ubiquity/envoi/api/client/http_client.rb,
lib/ubiquity/envoi/api/client/requests/base_request.rb

Direct Known Subclasses

Utilities

Defined Under Namespace

Modules: Requests Classes: HTTPClient, Paginator

Instance Attribute Summary collapse

API Endpoints collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = { }) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/ubiquity/envoi/api/client.rb', line 14

def initialize(args = { })
  @http_client = HTTPClient.new(args)
  @logger = http_client.logger
end

Instance Attribute Details

#http_clientObject

Returns the value of attribute http_client.



12
13
14
# File 'lib/ubiquity/envoi/api/client.rb', line 12

def http_client
  @http_client
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/ubiquity/envoi/api/client.rb', line 12

def logger
  @logger
end

#requestObject

Returns the value of attribute request.



12
13
14
# File 'lib/ubiquity/envoi/api/client.rb', line 12

def request
  @request
end

#responseObject

Returns the value of attribute response.



12
13
14
# File 'lib/ubiquity/envoi/api/client.rb', line 12

def response
  @response
end

Instance Method Details

#content(args = { }, options = { }) ⇒ Object

############################################################################################################## #



73
74
75
# File 'lib/ubiquity/envoi/api/client.rb', line 73

def content(args = { }, options = { })
  http :get, 'content'
end

#content_create(args = { }, options = { }) ⇒ Object



77
78
79
# File 'lib/ubiquity/envoi/api/client.rb', line 77

def content_create(args = { }, options = { })

end

#content_details(args = { }, options = { }) ⇒ Object



81
82
83
# File 'lib/ubiquity/envoi/api/client.rb', line 81

def content_details(args = { }, options = { })
  http :get, "content/#{args[:id]}"
end

#content_field_details(args = { }, options = { }) ⇒ Object



85
86
87
# File 'lib/ubiquity/envoi/api/client.rb', line 85

def content_field_details(args = { }, options = { })
  http :get, "content-field/#{args[:id]}"
end

#content_fieldset_details(args = { }, options = { }) ⇒ Object



89
90
91
# File 'lib/ubiquity/envoi/api/client.rb', line 89

def content_fieldset_details(args = { }, options = { })
  http :get, "content-fieldset/#{args[:id]}"
end

#content_fieldsets(args = { }, options = { }) ⇒ Object



97
98
99
# File 'lib/ubiquity/envoi/api/client.rb', line 97

def content_fieldsets(args = { }, options = { })
  http :get, 'content-fieldset'
end

#content_type_details(args = { }, options = { }) ⇒ Object



93
94
95
# File 'lib/ubiquity/envoi/api/client.rb', line 93

def content_type_details(args = { }, options = { })
  http :get, "content-type/#{args[:id]}"
end

#content_types(args = { }, options = { }) ⇒ Object Also known as: content_types_get



101
102
103
# File 'lib/ubiquity/envoi/api/client.rb', line 101

def content_types(args = { }, options = { })
  http :get, 'content-type'
end

#file_get(args = { }, options = { }) ⇒ Object



106
107
108
109
110
# File 'lib/ubiquity/envoi/api/client.rb', line 106

def file_get(args = { }, options = { })
  id = args[:id]

  http(:get, "file/#{id}")
end

#http(method, *args) ⇒ Object

Exposes HTTP Methods

Examples:

http(:get, ‘/’)



63
64
65
66
67
68
# File 'lib/ubiquity/envoi/api/client.rb', line 63

def http(method, *args)
  @request = nil
  @response = http_client.send(method, *args)
  @request = http_client.request
  @response
end

#media_file_add_file(args = { }, options = { }) ⇒ Object Also known as: media_file_file_add



134
135
136
# File 'lib/ubiquity/envoi/api/client.rb', line 134

def media_file_add_file(args = { }, options = { })
  process_request_using_class(Requests::MediaFileAddFile, args, options)
end

#media_file_create(args = { }, options = { }) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ubiquity/envoi/api/client.rb', line 112

def media_file_create(args = { }, options = { })
  # _request = Requests::BaseRequest.new(
  #   args,
  #   {
  #       :http_path => 'media-files/media-file',
  #       :http_method => :post,
  #       :parameters => [
  #         { :name => :name, :required => true },
  #         { :name => :description },
  #         { :name => :file },
  #         { :name => :metadata },
  #         # { :name => 'file[path]', :aliases => [ :path ], :required => true },
  #         # { :name => 'file[mime]', :aliases => [ :mime, :mime_type ], :required => true },
  #         # { :name => 'file[size]', :aliases => [ :size ], :required => true },
  #         # { :name => 'file[width]', :aliases => [ :width ] }
  #       ]
  #   }.merge(options)
  # )
  # process_request(_request, options)
  process_request_using_class(Requests::MediaFileCreate, args, options)
end

#media_file_delete(args = { }, options = { }) ⇒ Object



139
140
141
142
143
# File 'lib/ubiquity/envoi/api/client.rb', line 139

def media_file_delete(args = { }, options = { })
  id = args[:id]

  http(:delete, "media-files/media-file/#{id}")
end

#media_file_files_get(args = { }, options = { }) ⇒ Object



151
152
153
154
155
# File 'lib/ubiquity/envoi/api/client.rb', line 151

def media_file_files_get(args = { }, options = { })
  id = args[:id] || args[:media_file_id]

  http(:get, "media-files/media-file/#{id}/files")
end

#media_file_get(args = { }, options = { }) ⇒ Object



145
146
147
148
149
# File 'lib/ubiquity/envoi/api/client.rb', line 145

def media_file_get(args = { }, options = { })
  id = args[:id] || args[:media_file_id]

  http(:get, "media-files/media-file/#{id}")
end

#media_file_secured_get(args = { }, options = { }) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ubiquity/envoi/api/client.rb', line 157

def media_file_secured_get(args = { }, options = { })
  _request = Requests::BaseRequest.new(
      args,
      {
          :http_path => 'media-files/media-file/#{path_arguments[:media_file_id]}/secure',
          :http_method => :post,
          # :body => args,
          :parameters => [
              { :name => :media_file_id, :aliases => [ :id ], :send_in => :path },
              { :name => :email, :send_in => :body },
          ]
      }
  )
  process_request(_request, options)
end

#media_file_transcode(args = { }, options = { }) ⇒ Object

Transcode a Media File

Parameters:

  • args (Hash) (defaults to: { })

Options Hash (args):

  • :media_file_id (String)
  • :transcoder_id (String)
  • :transcoder_args (Hash)

See Also:



181
182
183
184
185
186
187
# File 'lib/ubiquity/envoi/api/client.rb', line 181

def media_file_transcode(args = { }, options = { })
  media_file_id = args[:media_file_id]
  transcoder_id = args[:transcoder_id]
  transcoder_args = args[:transcoder_args] || {}

  http(:post, "media-files/media-file/#{media_file_id}/action/transcode/#{transcoder_id}", transcoder_args)
end

#media_file_transcode_parameters_get(args = { }, options = { }) ⇒ Object



189
190
191
192
193
194
# File 'lib/ubiquity/envoi/api/client.rb', line 189

def media_file_transcode_parameters_get(args = { }, options = { })
  media_file_id = args[:media_file_id]
  transcoder_id = args[:transcoder_id]

  http(:get, "media-files/media-file/#{media_file_id}/action/transcode/#{transcoder_id}")
end

#media_file_transcoders_get(args = { }, options = { }) ⇒ Object



196
197
198
199
200
# File 'lib/ubiquity/envoi/api/client.rb', line 196

def media_file_transcoders_get(args = { }, options = { })
  media_file_id = args[:media_file_id] || args[:id]

  http(:get, "media-files/media-file/#{media_file_id}/action/transcode")
end

#media_file_update(args = { }, options = { }) ⇒ Object



202
203
204
# File 'lib/ubiquity/envoi/api/client.rb', line 202

def media_file_update(args = { }, options = { })
  process_request_using_class(Requests::MediaFileUpdate, args, options)
end

#media_files_detailed_get(args = { }, options = { }) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/ubiquity/envoi/api/client.rb', line 222

def media_files_detailed_get(args = { }, options = { })
  # http(:get, 'media-files/media-file-detailed?_perPage=200')

  _request = Requests::BaseRequest.new(
      args,
      {
          :http_path => 'media-files/media-file-detailed',
          :parameters => [
              { :name => :_perPage, :aliases => [ :perPage ], :default_value => '200' },
              { :name => :_page, :alises => [ :page ], :default_value => '1' }
          ]
      }
  )
  process_request(_request, options)
end

#media_files_get(args = { }, options = { }) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ubiquity/envoi/api/client.rb', line 206

def media_files_get(args = { }, options = { })
  # http(:get, 'media-files/media-file?_perPage=200')

  _request = Requests::BaseRequest.new(
      args,
      {
          :http_path => 'media-files/media-file',
          :parameters => [
              { :name => :_perPage, :default_value => '200' },
              { :name => :_page, :default_value => '1' }
          ]
      }
  )
  process_request(_request, options)
end

#paginatorObject



51
52
53
# File 'lib/ubiquity/envoi/api/client.rb', line 51

def paginator
  @paginator ||= Paginator.new(self, { :logger => logger }) if @response
end

#process_request(request, options = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ubiquity/envoi/api/client.rb', line 19

def process_request(request, options = nil)
  @paginator = nil
  @response = nil
  @request = request
  logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty?

  if ([:all, 'all'].include?(request.arguments[:_page]))
    request.arguments[:_page] = 1
    include_remaining_pages = true
  else
    include_remaining_pages = false
  end

  request.client = self unless request.client
  options ||= request.options

  return (options.fetch(:return_request, true) ? request : nil) unless options.fetch(:execute_request, true)

  #@response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
  @response = request.execute

  if request.respond_to?(:success?) && !request.success?
    raise "Request failed. #{request.response.code} #{response.body}"
  end

  if include_remaining_pages
    return paginator.include_remaining_pages
  end

  @response
end

#process_request_using_class(request_class, args, options = { }) ⇒ Object



55
56
57
58
59
# File 'lib/ubiquity/envoi/api/client.rb', line 55

def process_request_using_class(request_class, args, options = { })
  @response = nil
  @request = request_class.new(args, options.merge(:client => self))
  process_request(@request, options)
end

#project_get(args = { }, options = { }) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/ubiquity/envoi/api/client.rb', line 238

def project_get(args = { }, options = { })
  _request = Requests::BaseRequest.new(
    args,
    {
      :http_path => 'production/project/#{path_arguments[:project_id]}',
      :parameters => [
        { :name => :project_id, :aliases => [ :id ], :send_in => :path }
      ]
    }
  )

  process_request(_request, options)
end

#projects_get(args = { }, options = { }) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/ubiquity/envoi/api/client.rb', line 252

def projects_get(args = { }, options = { })
  _request = Requests::BaseRequest.new(
    args,
    {
      :http_path => 'production/project',
      :parameters => [

      ]
    }
  )

  process_request(_request, options)
end

#storages_get(args = { }, options = { }) ⇒ Object



266
267
268
# File 'lib/ubiquity/envoi/api/client.rb', line 266

def storages_get(args = { }, options = { })
  http(:get, 'media-files/storage')
end

#user_create(args = { }, options = { }) ⇒ Object



270
271
272
# File 'lib/ubiquity/envoi/api/client.rb', line 270

def user_create(args = { }, options = { })

end

#whoObject



274
275
276
# File 'lib/ubiquity/envoi/api/client.rb', line 274

def who
  http :get, 'who'
end