Class: Koine::RestClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/koine/rest_client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter: Adapters::HttpPartyAdapter.new, response_parser: ResponseParser.new, base_request: Request.new) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
# File 'lib/koine/rest_client/client.rb', line 8

def initialize(
  adapter: Adapters::HttpPartyAdapter.new,
  response_parser: ResponseParser.new,
  base_request: Request.new
)
  @adapter = adapter
  @response_parser = response_parser
  @request = base_request
end

Instance Method Details

#async {|builder| ... } ⇒ Object

Yields:

  • (builder)


68
69
70
71
72
# File 'lib/koine/rest_client/client.rb', line 68

def async
  builder = AsyncBuilder.new(self, @response_parser)
  yield(builder)
  builder.parsed_responses
end

#create_delete_request(path, body = {}, options = {}) ⇒ Object



64
65
66
# File 'lib/koine/rest_client/client.rb', line 64

def create_delete_request(path, body = {}, options = {})
  create_request(:delete, path, options.merge(body: body))
end

#create_get_request(path, query = {}, options = {}) ⇒ Object



24
25
26
# File 'lib/koine/rest_client/client.rb', line 24

def create_get_request(path, query = {}, options = {})
  create_request(:get, path, options.merge(query_params: query))
end

#create_patch_request(path, body = {}, options = {}) ⇒ Object



54
55
56
# File 'lib/koine/rest_client/client.rb', line 54

def create_patch_request(path, body = {}, options = {})
  create_request(:patch, path, options.merge(body: body))
end

#create_post_request(path, body = {}, options = {}) ⇒ Object



34
35
36
# File 'lib/koine/rest_client/client.rb', line 34

def create_post_request(path, body = {}, options = {})
  create_request(:post, path, options.merge(body: body))
end

#create_put_request(path, body = {}, options = {}) ⇒ Object



44
45
46
# File 'lib/koine/rest_client/client.rb', line 44

def create_put_request(path, body = {}, options = {})
  create_request(:put, path, options.merge(body: body))
end

#delete(path, body = {}, options = {}, &block) ⇒ Object



58
59
60
61
62
# File 'lib/koine/rest_client/client.rb', line 58

def delete(path, body = {}, options = {}, &block)
  request = create_delete_request(path, body, options)
  response = perform_request(request)
  parse_response(response, &block)
end

#get(path, query = {}, options = {}, &block) ⇒ Object



18
19
20
21
22
# File 'lib/koine/rest_client/client.rb', line 18

def get(path, query = {}, options = {}, &block)
  request = create_get_request(path, query, options)
  response = perform_request(request)
  parse_response(response, &block)
end

#patch(path, body = {}, options = {}, &block) ⇒ Object



48
49
50
51
52
# File 'lib/koine/rest_client/client.rb', line 48

def patch(path, body = {}, options = {}, &block)
  request = create_patch_request(path, body, options)
  response = perform_request(request)
  parse_response(response, &block)
end

#perform_request(request) ⇒ Object



74
75
76
# File 'lib/koine/rest_client/client.rb', line 74

def perform_request(request)
  @adapter.send_request(request)
end

#post(path, body = {}, options = {}, &block) ⇒ Object



28
29
30
31
32
# File 'lib/koine/rest_client/client.rb', line 28

def post(path, body = {}, options = {}, &block)
  request = create_post_request(path, body, options)
  response = perform_request(request)
  parse_response(response, &block)
end

#put(path, body = {}, options = {}, &block) ⇒ Object



38
39
40
41
42
# File 'lib/koine/rest_client/client.rb', line 38

def put(path, body = {}, options = {}, &block)
  request = create_put_request(path, body, options)
  response = perform_request(request)
  parse_response(response, &block)
end