Class: HaveAPI::ClientExample
- Inherits:
-
Object
- Object
- HaveAPI::ClientExample
- 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.
Direct Known Subclasses
HaveAPI::ClientExamples::FsClient, HaveAPI::ClientExamples::Http, HaveAPI::ClientExamples::JsClient, HaveAPI::ClientExamples::PhpClient, HaveAPI::ClientExamples::RubyCli, HaveAPI::ClientExamples::RubyClient
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_path ⇒ Object
readonly
Returns the value of attribute resource_path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.auth(*args) ⇒ Object
Shortcut to #auth.
-
.clients ⇒ Array<ClientExample>
Sorted array of classes.
-
.code(v = nil) ⇒ Object
Code name is passed to the syntax highligher.
-
.example(*args) ⇒ Object
Shortcut to ClientExample.example.
-
.init(*args) ⇒ Object
Shortcut to #init.
-
.label(v = nil) ⇒ Object
All subclasses have to call this method to set their label and be registered.
-
.order(v = nil) ⇒ Object
A number used for ordering client examples.
- .register(klass) ⇒ Object
Instance Method Summary collapse
- #auth(method, desc) ⇒ Object
- #init ⇒ Object
-
#initialize(host, base_url, version, *args) ⇒ ClientExample
constructor
A new instance of ClientExample.
- #version_url ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
62 63 64 |
# File 'lib/haveapi/client_example.rb', line 62 def action @action end |
#action_name ⇒ Object (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_url ⇒ Object (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 |
#host ⇒ Object (readonly)
Returns the value of attribute host.
62 63 64 |
# File 'lib/haveapi/client_example.rb', line 62 def host @host end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
62 63 64 |
# File 'lib/haveapi/client_example.rb', line 62 def resource @resource end |
#resource_path ⇒ Object (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 |
#version ⇒ Object (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..-1]) end |
.clients ⇒ Array<ClientExample>
Returns sorted array of classes.
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 |
.init(*args) ⇒ Object
Shortcut to #init
42 43 44 |
# File 'lib/haveapi/client_example.rb', line 42 def init(*args) new(*args).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
75 76 77 |
# File 'lib/haveapi/client_example.rb', line 75 def auth(method, desc) end |
#init ⇒ Object
71 72 73 |
# File 'lib/haveapi/client_example.rb', line 71 def init end |
#version_url ⇒ Object
79 80 81 |
# File 'lib/haveapi/client_example.rb', line 79 def version_url File.join(base_url, "v#{version}", '/') end |