Class: BooticClient::Relation
- Inherits:
-
Object
- Object
- BooticClient::Relation
- Defined in:
- lib/bootic_client/relation.rb
Constant Summary collapse
- GET =
'get'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #docs ⇒ Object
- #href ⇒ Object
-
#initialize(attrs, client, wrapper_class = Entity) ⇒ Relation
constructor
A new instance of Relation.
- #inspect ⇒ Object
- #name ⇒ Object
- #parameters ⇒ Object
- #run(opts = {}) ⇒ Object
- #templated? ⇒ Boolean
- #title ⇒ Object
- #transport_method ⇒ Object
- #type ⇒ Object
Constructor Details
Class Method Details
.expand(href, opts = {}) ⇒ Object
62 63 64 |
# File 'lib/bootic_client/relation.rb', line 62 def self.(href, opts = {}) URITemplate.new(href).(opts) end |
Instance Method Details
#docs ⇒ Object
42 43 44 |
# File 'lib/bootic_client/relation.rb', line 42 def docs attrs['docs'] end |
#href ⇒ Object
18 19 20 |
# File 'lib/bootic_client/relation.rb', line 18 def href attrs['href'] end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/bootic_client/relation.rb', line 14 def inspect %(#<#{self.class.name} #{attrs.inspect}>) end |
#name ⇒ Object
30 31 32 |
# File 'lib/bootic_client/relation.rb', line 30 def name attrs['name'] end |
#parameters ⇒ Object
26 27 28 |
# File 'lib/bootic_client/relation.rb', line 26 def parameters @parameters ||= templated? ? uri.variables : [] end |
#run(opts = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bootic_client/relation.rb', line 50 def run(opts = {}) if templated? uri_vars = uri.variables payload = opts.each_with_object({}) do |(k,v),memo| memo[k] = v unless uri_vars.include?(k.to_s) end client.request_and_wrap transport_method.to_sym, uri.(opts), wrapper_class, payload else client.request_and_wrap transport_method.to_sym, href, wrapper_class, opts end end |
#templated? ⇒ Boolean
22 23 24 |
# File 'lib/bootic_client/relation.rb', line 22 def templated? !!attrs['templated'] end |
#title ⇒ Object
34 35 36 |
# File 'lib/bootic_client/relation.rb', line 34 def title attrs['title'] end |
#transport_method ⇒ Object
46 47 48 |
# File 'lib/bootic_client/relation.rb', line 46 def transport_method @transport_method ||= attrs['method'] || GET end |
#type ⇒ Object
38 39 40 |
# File 'lib/bootic_client/relation.rb', line 38 def type attrs['type'] end |