Class: Nokotime::Connection

Inherits:
Object
  • Object
show all
Includes:
Authentication
Defined in:
lib/nokotime/connection.rb

Constant Summary

Constants included from Authentication

Authentication::AUTHENTICATION_TYPE

Instance Method Summary collapse

Methods included from Authentication

#authorize_request, #valid_auth?

Instance Method Details

#get(path, params: {}, request_options: {}) ⇒ Object

rubocop:disable Metrics/MethodLength



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nokotime/connection.rb', line 6

def get(path, params: {}, request_options: {})
  response = connection.get do |request|
    authorize_request(request)
    set_request_options(request, request_options)
    request.url path, params
  end

  response
rescue Faraday::ConnectionFailed => e
  raise Errors::ConnectionFailed.new(e), e.message
rescue Faraday::ResourceNotFound => e
  raise Errors::ResourceNotFound.new(e), e.message
rescue Faraday::ClientError => e
  raise Errors::ClientError.new(e), e.message
end

#get_in_parallel(path, from_page_number, to_page_number, params: {}, request_options: {}) ⇒ Object

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



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
50
51
# File 'lib/nokotime/connection.rb', line 25

def get_in_parallel(
  path,
  from_page_number,
  to_page_number,
  params: {},
  request_options: {}
)
  responses = []

  connection.in_parallel(manager) do
    (from_page_number..to_page_number).each do |page|
      merged_params = {page: page}.merge(params)

      responses << get(
        path, params: merged_params, request_options: request_options
      )
    end
  end

  responses
rescue Faraday::ConnectionFailed => e
  raise Errors::ConnectionFailed.new(e), e.message
rescue Faraday::ResourceNotFound => e
  raise Errors::ResourceNotFound.new(e), e.message
rescue Faraday::ClientError => e
  raise Errors::ClientError.new(e), e.message
end