Class: HaveAPI::ClientExample

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/client_example.rb

Overview

All client example classes should inherit this class. Depending on the client, the subclass may choose to implement either method ‘example` or `request` and `response`. `example` should be implemented if the client example shows only the request or the request and response should be coupled together.

Methods ‘example`, `request` and `response` take one argument, the example to describe.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, base_url, version, *args) ⇒ ClientExample

Returns a new instance of ClientExample.



64
65
66
67
68
69
# File 'lib/haveapi/client_example.rb', line 64

def initialize(host, base_url, version, *args)
  @host = host
  @base_url = base_url
  @version = version
  @resource_path, @resource, @action_name, @action = args
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def action
  @action
end

#action_nameObject (readonly)

Returns the value of attribute action_name.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def action_name
  @action_name
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def base_url
  @base_url
end

#hostObject (readonly)

Returns the value of attribute host.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def host
  @host
end

#resourceObject (readonly)

Returns the value of attribute resource.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def resource
  @resource
end

#resource_pathObject (readonly)

Returns the value of attribute resource_path.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def resource_path
  @resource_path
end

#versionObject (readonly)

Returns the value of attribute version.



62
63
64
# File 'lib/haveapi/client_example.rb', line 62

def version
  @version
end

Class Method Details

.auth(*args) ⇒ Object

Shortcut to #auth



47
48
49
# File 'lib/haveapi/client_example.rb', line 47

def auth(*args)
  new(*args[0..-3]).auth(*args[-2..])
end

.clientsArray<ClientExample>

Returns sorted array of classes.

Returns:



57
58
59
# File 'lib/haveapi/client_example.rb', line 57

def clients
  @clients.sort { |a, b| a.order <=> b.order }
end

.code(v = nil) ⇒ Object

Code name is passed to the syntax highligher.



25
26
27
28
# File 'lib/haveapi/client_example.rb', line 25

def code(v = nil)
  @code = v if v
  @code
end

.example(*args) ⇒ Object

Shortcut to example



52
53
54
# File 'lib/haveapi/client_example.rb', line 52

def example(*args)
  new(*args[0..-2]).example(args.last)
end

.initObject

Shortcut to #init



42
43
44
# File 'lib/haveapi/client_example.rb', line 42

def init(*)
  new(*).init
end

.label(v = nil) ⇒ Object

All subclasses have to call this method to set their label and be registered.



15
16
17
18
19
20
21
22
# File 'lib/haveapi/client_example.rb', line 15

def label(v = nil)
  if v
    @label = v
    HaveAPI::ClientExample.register(self)
  end

  @label
end

.order(v = nil) ⇒ Object

A number used for ordering client examples.



31
32
33
34
# File 'lib/haveapi/client_example.rb', line 31

def order(v = nil)
  @order = v if v
  @order
end

.register(klass) ⇒ Object



36
37
38
39
# File 'lib/haveapi/client_example.rb', line 36

def register(klass)
  @clients ||= []
  @clients << klass
end

Instance Method Details

#auth(method, desc) ⇒ Object



73
# File 'lib/haveapi/client_example.rb', line 73

def auth(method, desc); end

#initObject



71
# File 'lib/haveapi/client_example.rb', line 71

def init; end

#version_urlObject



75
76
77
# File 'lib/haveapi/client_example.rb', line 75

def version_url
  File.join(base_url, "v#{version}", '/')
end