Class: EasyqaApi::Item

Inherits:
Object
  • Object
show all
Extended by:
ClassMethodsSettable
Defined in:
lib/easyqa_api/item.rb

Constant Summary collapse

CONNECTION =
{
  json: {
    instance: -> { json_connection },
    content_type: 'application/json'
  },
  multipart: {
    instance: -> { multipart_connection },
    content_type: 'multipart/form-data'
  }
}.freeze
@@default_user =
nil

Constants included from ClassMethodsSettable

ClassMethodsSettable::METHODS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassMethodsSettable

install_class_methods!

Constructor Details

#initialize(*_args) ⇒ Item

Returns a new instance of Item.



51
52
# File 'lib/easyqa_api/item.rb', line 51

def initialize(*_args)
end

Class Method Details

.json_connectionObject



19
20
21
22
23
24
25
# File 'lib/easyqa_api/item.rb', line 19

def json_connection
  @json_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
    faraday.request :json
    faraday.response :json
    faraday.adapter Faraday.default_adapter
  end
end

.multipart_connectionObject



27
28
29
30
31
32
33
# File 'lib/easyqa_api/item.rb', line 27

def multipart_connection
  @multipart_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
    faraday.request :multipart
    faraday.response :json
    faraday.adapter Faraday.default_adapter
  end
end

.operation_status(response) ⇒ Object



45
46
47
48
# File 'lib/easyqa_api/item.rb', line 45

def operation_status(response)
  EasyqaApi::Exception.check_response_status!(response)
  response.body
end

.send_request(url, html_method, type = :json, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/easyqa_api/item.rb', line 35

def send_request(url, html_method, type = :json, &block)
  response = EasyqaApi::Item::CONNECTION[type][:instance].call.send(html_method) do |req|
    req.url EasyqaApi.configuration.api_path + url
    req.headers['Content-Type'] = EasyqaApi::Item::CONNECTION[type][:content_type]
    yield(req) if block
  end

  operation_status(response)
end

Instance Method Details

#install_variables!(arguments) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/easyqa_api/item.rb', line 56

def install_variables!(arguments)
  allowed_methods = retrive_allowed_methods
  arguments.each do |key, value|
    method_name = "#{key}=".to_sym
    send(method_name, value) if allowed_methods.include? method_name
  end
end