Class: BookingSync::API::Relation
- Inherits:
-
Object
- Object
- BookingSync::API::Relation
- Defined in:
- lib/bookingsync/api/relation.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#href_template ⇒ Object
readonly
Returns the value of attribute href_template.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.from_link(client, name, options) ⇒ BookingSync::API::Relation
Build a single Relation from the given options.
-
.from_links(client, links) ⇒ Hash
Build a hash of Relations from the ‘links` key in JSON API response.
Instance Method Summary collapse
-
#call(data = nil, options = nil) ⇒ BookingSync::API::Response
Make an API request with the curent Relation.
-
#get(options = nil) ⇒ BookingSync::API::Response
Make an API request with the curent Relation using GET.
- #href(options = nil) ⇒ Object
-
#initialize(client, name, href, method = nil) ⇒ Relation
constructor
A Relation represents an available next action for a resource.
Constructor Details
#initialize(client, name, href, method = nil) ⇒ Relation
A Relation represents an available next action for a resource.
47 48 49 50 51 52 53 54 |
# File 'lib/bookingsync/api/relation.rb', line 47 def initialize(client, name, href, method = nil) @client = client @name = name.to_sym @href = href @href_template = ::Addressable::Template.new(href.to_s) @method = (method || :get).to_sym @available_methods = Set.new methods || [@method] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/bookingsync/api/relation.rb', line 5 def client @client end |
#href_template ⇒ Object (readonly)
Returns the value of attribute href_template.
5 6 7 |
# File 'lib/bookingsync/api/relation.rb', line 5 def href_template @href_template end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/bookingsync/api/relation.rb', line 5 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bookingsync/api/relation.rb', line 5 def name @name end |
Class Method Details
.from_link(client, name, options) ⇒ BookingSync::API::Relation
Build a single Relation from the given options.
31 32 33 34 35 36 37 38 |
# File 'lib/bookingsync/api/relation.rb', line 31 def self.from_link(client, name, ) case when Hash new client, name, [:href], [:method] when String new client, name, end end |
.from_links(client, links) ⇒ Hash
Build a hash of Relations from the ‘links` key in JSON API response.
13 14 15 16 17 18 19 |
# File 'lib/bookingsync/api/relation.rb', line 13 def self.from_links(client, links) relations = {} links.each do |name, | relations[name] = from_link(client, name, ) end if links relations end |
Instance Method Details
#call(data = nil, options = nil) ⇒ BookingSync::API::Response
Make an API request with the curent Relation.
84 85 86 87 |
# File 'lib/bookingsync/api/relation.rb', line 84 def call(data = nil, = nil) m = && [:method] @client.call m || @method, @href_template, data, || {} end |
#get(options = nil) ⇒ BookingSync::API::Response
Make an API request with the curent Relation using GET.
63 64 65 66 67 |
# File 'lib/bookingsync/api/relation.rb', line 63 def get( = nil) ||= {} [:method] = :get call end |
#href(options = nil) ⇒ Object
69 70 71 72 |
# File 'lib/bookingsync/api/relation.rb', line 69 def href( = nil) return @href if @href_template.nil? @href_template.( || {}).to_s end |