Class: Hoodoo::Client::Endpoint::HTTP

Inherits:
HTTPBased show all
Defined in:
lib/hoodoo/client/endpoint/endpoints/http.rb

Overview

Talk to a resource that is contacted over HTTP or HTTPS.

Configured with a Hoodoo::Services::Discovery::ForHTTP discovery result instance.

Instance Attribute Summary

Attributes inherited from Hoodoo::Client::Endpoint

#interaction, #locale, #resource, #session_id, #version

Instance Method Summary collapse

Methods inherited from Hoodoo::Client::Endpoint

endpoint_for, #initialize

Constructor Details

This class inherits a constructor from Hoodoo::Client::Endpoint

Instance Method Details

#create(body_hash, query_hash = nil) ⇒ Object

See Hoodoo::Client::Endpoint#create.



85
86
87
88
89
90
91
92
# File 'lib/hoodoo/client/endpoint/endpoints/http.rb', line 85

def create( body_hash, query_hash = nil )
  d            = @description.dup
  d.action     = :create
  d.body_hash  = body_hash
  d.query_hash = query_hash

  return do_http( d )
end

#delete(ident, query_hash = nil) ⇒ Object

See Hoodoo::Client::Endpoint#delete.



108
109
110
111
112
113
114
115
# File 'lib/hoodoo/client/endpoint/endpoints/http.rb', line 108

def delete( ident, query_hash = nil )
  d            = @description.dup
  d.action     = :delete
  d.ident      = ident
  d.query_hash = query_hash

  return do_http( d )
end

#list(query_hash = nil) ⇒ Object

See Hoodoo::Client::Endpoint#list.



49
50
51
52
53
54
55
# File 'lib/hoodoo/client/endpoint/endpoints/http.rb', line 49

def list( query_hash = nil )
  d            = @description.dup # This does NOT dup the objects to which @description points
  d.action     = :list
  d.query_hash = query_hash

  return inject_enumeration_state( do_http( d ), query_hash )
end

#show(ident, query_hash = nil) ⇒ Object

See Hoodoo::Client::Endpoint#show.

In RESTful HTTP, ‘GET /resources/#= nil` gets evaluated as `GET /resources/`, which is of course interpreted as a #list request. Since this is undesirable behaviour, the ident must be populated, and this will return `404 Not Found` if it is not.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hoodoo/client/endpoint/endpoints/http.rb', line 64

def show( ident, query_hash = nil )
  if ident.nil?
    data = response_class_for( :show ).new
    data.platform_errors.add_error(
      'platform.not_found',
      'reference' => {entity_name: 'nil identifier given on :show action'}
    )

    return data
  end

  d            = @description.dup
  d.action     = :show
  d.ident      = ident
  d.query_hash = query_hash

  return do_http( d )
end

#update(ident, body_hash, query_hash = nil) ⇒ Object

See Hoodoo::Client::Endpoint#update.



96
97
98
99
100
101
102
103
104
# File 'lib/hoodoo/client/endpoint/endpoints/http.rb', line 96

def update( ident, body_hash, query_hash = nil )
  d            = @description.dup
  d.action     = :update
  d.ident      = ident
  d.body_hash  = body_hash
  d.query_hash = query_hash

  return do_http( d )
end