Class: Webspicy::HttpClient

Inherits:
Client
  • Object
show all
Defined in:
lib/webspicy/client/http_client.rb

Defined Under Namespace

Classes: Api

Instance Attribute Summary collapse

Attributes inherited from Client

#scope

Instance Method Summary collapse

Methods inherited from Client

#before, #config

Constructor Details

#initialize(scope) ⇒ HttpClient

Returns a new instance of HttpClient.



4
5
6
7
# File 'lib/webspicy/client/http_client.rb', line 4

def initialize(scope)
  super(scope)
  @api = Api.new
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/webspicy/client/http_client.rb', line 8

def api
  @api
end

Instance Method Details

#call(test_case) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/webspicy/client/http_client.rb', line 10

def call(test_case)
  service, resource = test_case.service, test_case.resource

  # Instantiate the parameters
  headers = test_case.headers
  params = test_case.dress_params? ? service.dress_params(test_case.params) : test_case.params

  # Instantiate the url and strip parameters
  url, params = resource.instantiate_url(params)

  # Globalize the URL if required
  url = scope.to_real_url(url, to_real_url)

  # Invoke the service now
  api.public_send(service.method.to_s.downcase.to_sym, url, params, headers, test_case.body)

  # Return the result
  Resource::Service::Invocation.new(service, test_case, api.last_response, self)
end